0

For some reason Rust Analyzer isn't generating a warning for undefined variables. Do I need to tweak some settings somewhere?

enter image description here

I'm also not getting warnings for unused variables, unimported crates, etc.

Edit: Tested this out with a new workspace. Both cargo check and Rust Analyzer work. It reports a single intentional error. When I run cargo check in the first workspace, it reports a lot of errors in the ~/.cargo directory, and none in the current workspace. Perhaps a crate I am using has errors and is locking up cargo check before it can get around to checking the files in my directory?

reeslabree
  • 127
  • 13

3 Answers3

1

The log when running cargo check showed some issues with ~/.cargo/registry/src/github.com-xx..xx/rppal-0.12.0. This came from a the crate rust_gpiozero that I had listed as a dependency. As best as I can figure, cargo check was failing on this and then ceasing to analyze my files. After removing this dependency, both cargo check and Rust Analyzer run as expected.

Cheers to all who replied to this thread for their guidance.

reeslabree
  • 127
  • 13
1

For another possible cause: try cargo clean.

This problem happened to me after upgrading my toolchain version. As mentioned in other answers, running cargo check yielded many errors. The topmost error mentioned a crate "compiled by an incompatible version of rustc." Running cargo clean followed by cargo check fixed all errors.

CompileYourCake
  • 324
  • 2
  • 12
0

Rust-analyzer itself doesn't produce errors or warnings for this.

If you want warnings and errors, enable the "Check on Enable" option in the rust-analyzer extension. This will run cargo check every time you save a Rust file and display the emitted warnings and errors in the files.

Colonel Thirty Two
  • 23,953
  • 8
  • 45
  • 85
  • Enable "check on save" perhaps? This has already been enabled, and I get a handful of warnings for things like incomplete statements (ex. `let x = ` throws an error.), however I don't get any errors for the more complex things. Between your and @PitaJ's responses, it seems like this is perhaps a cargo error rather than a Rust Analyzer error. – reeslabree Dec 01 '22 at 15:05