intellij-rust icon indicating copy to clipboard operation
intellij-rust copied to clipboard

Undefined variables are not detected/reported

Open ngortheone opened this issue 6 years ago • 9 comments

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.

screen shot 2018-12-12 at 8 43 59 pm

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 of Rust | Unresolved reference inspection in Preferences | Editor | Inspections settings. Note, it may lead to false-positive error annotations.

ngortheone avatar Dec 13 '18 14:12 ngortheone

Do you have the Use cargo check to analyze code setting turned on?

image

chinedufn avatar Dec 14 '18 00:12 chinedufn

@chinedufn It works with "use cargo to analyze code" option on. Is this feature supported only through cargo?

ngortheone avatar Dec 14 '18 02:12 ngortheone

I have absolutely no idea (:

chinedufn avatar Dec 14 '18 18:12 chinedufn

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.

alecks avatar Jun 03 '20 19:06 alecks

@Undin is this another case of disabled unresolved reference inspection to avoid false positives? Do we want to fix it now?

Kobzol avatar Jun 04 '20 07:06 Kobzol

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

Undin avatar Jun 08 '20 19:06 Undin

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?

soenkeliebau avatar Aug 27 '20 14:08 soenkeliebau

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.

Kobzol avatar Aug 27 '20 14:08 Kobzol

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. image

Shpota avatar Sep 16 '22 07:09 Shpota