reeslabree
reeslabree

Reputation: 176

Rust Analyzer doesn't create warning for undefined variables

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?

Upvotes: 1

Views: 1577

Answers (3)

CompileYourCake
CompileYourCake

Reputation: 414

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.

Upvotes: 5

reeslabree
reeslabree

Reputation: 176

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.

Upvotes: 1

Colonel Thirty Two
Colonel Thirty Two

Reputation: 26569

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.

Upvotes: 0

Related Questions