title: What does the rust-analyzer error "could not resolve macro `$crate::format_args`" mean and how do I fix it?
body: <p>I'm using rust-analyzer version 0.2.408 on Visual Studio Code.</p>
  <p>I'm writing a command line application that involves centering text in the terminal. This is the function I wrote to do this:</p>
  <pre class="lang-rs prettyprint-override"><code>use console::{Alignment, pad_str};
  
  fn get_padded_row(row: &amp;str, width: u16, symbol: Option&lt;char&gt;) -&gt; String {
      let symbol = symbol.unwrap_or(' ');
      return pad_str(row, width as usize, Alignment::Center, None)
          .to_string()
          .replace(' ', &amp;symbol.to_string());
  }
  </code></pre>
  <p>This function works perfectly fine, and there were no errors with it. Then I wrote a test:</p>
  <pre class="lang-rs prettyprint-override"><code>#[cfg(test)]
  mod tests {
      use crate::get_padded_row;
  
      #[test]
      fn row_padding_dashes() {
          let padded_row = get_padded_row(&quot;hello&quot;, 15, Some('-'));
          assert_eq!(
              padded_row, &quot;-----hello-----&quot;.to_string(),
              &quot;`get_padded_row` was not correct, got `{}`&quot;, padded_row
          );
      }
  }
  </code></pre>
  <p>The code still works perfectly fine. Both <code>cargo run</code> and <code>cargo test</code> work, the function passes the test, and <code>cargo check</code> returns no issues. But rust-analyzer gives an error, highlighting everything from the <code>tr};</code> in the <code>use</code> statement to the <code>p</code> right after <code>return</code>: &quot;could not resolve macro <code>$crate::format_args</code> rust-analyzer(macro-error)&quot;. Searching for this error returns nothing. VSCode links me to <a href="https://rust-analyzer.github.io/manual.html#macro-error" rel="noreferrer">rust-analyzer user manual</a>, which says only &quot;This diagnostic is shown for macro expansion errors&quot;. Restarting VSCode and reinstalling rust-analyzer have done nothing. The error always comes back, and highlighting the same oddly specific region. The only way I've found to get rid of it while keeping rust-analyzer installed is to remove the test.</p>
  <p>Judging from how the error is about macro expansion, and how removing the test fixes the issue, I'd imagine it's caused by the <code>#[test]</code> macro, but it's strange that rustc finds no issues at all with my code while rust-analyzer is freaking out about this error. So far, I've had better experiences with rust-analyzer than with the official Rust VSCode extension, but I'm on the verge of switching back to fix this issue.</p>