intellij-rust: false positives when detecting errors in editor
Environment
- IntelliJ Rust plugin version: 0.4.179.4903-222
- Rust toolchain version: 1.64.0 (a55dd71d5 2022-09-19) x86_64-pc-windows-msvc
- IDE name and version: IntelliJ IDEA 2022.2.2 Ultimate Edition (IU-222.4167.29)
- Operating system: Windows 10 10.0
- Macro expansion: enabled
Problem description
I get a lot of underwaved errors when editing Rust code, for
- formatted strings, e.g.
println!
and similar macros, with the following explanation: "‘(type)’ doesn’t implement ‘Display’, for types like String, usize, … - arguments of generic functions with types that should normally be accepted, but are marked as wrong.
The program compiles without any error or warning, and runs without any problem.
A few examples:
-
‘usize’ doesn’t implement ‘Display’:
-
‘String’ doesn’t implement ‘Display’: (the tooltip only shows the function signature, not the error)
-
here, a function that takes any type from which f64 can be taken:
-
(function signature)
This makes IntelliJ’s error detection unusable and is very annoying.
Misc info
Some of the errors disappear if I invalidate the cache and restart the IDE (File, Invalidate Caches…), but not all of them. Then they come back after a while.
I never saw that in 2022.2.1. I think I briefly used it with 1.64 and never saw those problems either. I have just updated to 2022.2.2 and now I’m seeing them all the time.
EDIT: work-around by reverting to previous version, see post below.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 2
- Comments: 27 (8 by maintainers)
Commits related to this issue
- Fix issue #9432 random false-positives caused by GC activity Actually, the bug is a wrong (missing) implementation of CargoBasedCrate.equals/hashCode — committed to intellij-rust/intellij-rust by vlad20012 2 years ago
- Merge #9461 9461: Fix issue #9432 random false-positives caused by GC activity r=dima74 a=vlad20012 Fixes #9432. See technical explanation [here](https://github.com/intellij-rust/intellij-rust/issue... — committed to intellij-rust/intellij-rust by bors[bot] 2 years ago
- Fix issue #9432 random false-positives caused by GC activity Actually, the bug is a wrong (missing) implementation of CargoBasedCrate.equals/hashCode (cherry picked from commit f640f7bbef250af5f171a... — committed to intellij-rust/intellij-rust by vlad20012 2 years ago
- Fix issue #9432 random false-positives caused by GC activity Actually, the bug is a wrong (missing) implementation of CargoBasedCrate.equals/hashCode — committed to Kobzol/intellij-rust by vlad20012 2 years ago
It was difficult, but I solved this riddle! The bug was introduced in #9229 (included into 0.4.179 release). I’m fixing it in #9461 that will likely be included into 0.4.180 (will be released next Monday).
Technical explanation:
CargoBasedCrate
had identity-basedequals
/hashCode
(looking ahead, this led to the bug).CrateGraphServiceImpl.crateGraph
is stored under aCachedValue
that stores a cached value indirectly underSoftReference
(“indirectly” meansSoftReference
->SomeWrapper
->CrateGraph
), so Java GC can collectSomeWrapper
anytime, that means invalidation of the thecrateGraph
cached value (and its re-calculation during a next access). Hence it’s possible that at some point we have multipleCargoBasedCrate
instances referring to the “same” crate.Crate.hasTransitiveDependencyOrSelf(Crate)
(introduced in #9229) usesCargoBasedCrate.equals/hashCode
in order to check if a crate is a dependency of another crate. The combination of these nuances has led to the fact that in some circumstancesCrate.hasTransitiveDependencyOrSelf(Crate)
could wrongly returnfalse
, that turns the #9229 filtering mechanism against valid impls (like impl Copy for primitives), that in turn leads to observable false-positivesThe issue is fixed in the nightly plugin. You can try it now (see instructions)
Thank everyone for participating!
So far I haven’t seen the problem since I reverted to Rust 0.4.178.4873-222, so I would say it’s a good work around.
I think those type-related optimizations above may have broken something in the trait system in version 0.4.179. It seems unable to see what traits are supported by a type.
Procedure:
Install Plugin from disk
.No need to uninstall it first. Maybe a
Restart & Invalidate Caches
may be safer, though I didn’t need to do it.Remarkable! Great work!
@blueglyph you can do it via https://uploads.jetbrains.com not to make them publicly available