intellij-rust
intellij-rust copied to clipboard
Undefined variables are not detected/reported
Environment
- Intellij-Rust plugin version: v0.2.0.2112-183
- stable-x86_64-apple-darwin (default)
- rustc 1.31.0 (abe02cefd 2018-12-04)
- IDE name and version: CLion 2018.3.1
- Operating system: OSX Mojave
Problem description: undefined variables are not highlighted/reported. See screenshot. My expectation is to see secret_number
on line 9 to be highlighted with red.

Workarounds
Release 125
- Turn on cargo check as an external linter. Enable
Preferences | Languages & Frameworks | Rust | Cargo | Run external linter to analyze code on the fly
option. Note, it's CPU consuming especially on large projects - Turn off
Ignore unresolved references without quick fix
option ofRust | Unresolved reference
inspection inPreferences | Editor | Inspections
settings. Note, it may lead to false-positive error annotations.
Do you have the Use cargo check to analyze code
setting turned on?
@chinedufn It works with "use cargo to analyze code" option on. Is this feature supported only through cargo?
I have absolutely no idea (:
I've had this issue for a while but didn't think to check GitHub; will this ever be implemented without having to enable external linters?
I'm also on macOS (CLion on Catalina specifically). It's relatively hard to fix without another source like this issue.
@Undin is this another case of disabled unresolved reference inspection to avoid false positives? Do we want to fix it now?
is this another case of disabled unresolved reference inspection to avoid false positives?
Yep.
Do we want to fix it now?
The proper fix is to show error annotation of unresolved reference inspection by default. But currently, it will lead to false-positive errors in some cases. We've discussed it some time ago this case. Probably, we can add some heuristic to check that current element is local variable. For example, a single identifier in function body, not part of dot or call expression, snake case. Not sure it's the best idea and it will work properly but we can try
I just looked at Intellij as a Rust IDE today and have to say that I am bewildered how this issue has only two upvotes, let alone still exists .. This seems to me to be the most fundamental inspection there can be. Or am I missing some underlying Rust complexity that makes this much harder to implement for Rust when compared to Go or Java?
Well, kind of. It is disabled because of false positives and even though it's possible that nowadays the plugin has a reasonably small amount of them so that it would be usable, there would still be some. You can play with the settings in Settings -> Inspections -> Rust -> Unresolved reference
and check off Ignore unresolved references without a quick fix
.
It is in fact much harder to do this for Rust when compared to Go/Java, because the Rust compiler is much more complex and this plugin has to basically reimplement it from scratch. That's pretty much all there is to it, if I'm not mistaken.
Is there a chance at least some very basic checks could be reported? For instance, I declare a variable of type int
which is not a valid type but I see no errors which is disappointing.