Open
Description
Occurs in nightly-2022-01-26
Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=2eec42713e64ef9243a12589aece967c
pub type Foos = i32;
pub enum Foo {
A,
B,
C,
}
mod module0 {
pub struct Foo {
a: i32,
}
}
mod module1 {
pub struct Foo {}
}
mod module2 {
pub enum Foo {} // This one actually gets correctly filtered out
}
fn main() {
let foo = Foo { b: 0 };
}
The output is a mess of false suggestions, I managed to hit an error that looked very similar to this while refactoring:
error[E0574]: expected struct, variant or union type, found enum `Foo`
--> src/main.rs:22:15
|
1 | pub type Foos = i32;
| -------------------- similarly named type alias `Foos` defined here
...
22 | let foo = Foo { b: 0 };
| ^^^
|
help: a type alias with a similar name exists
|
22 | let foo = Foos { b: 0 };
| ~~~~
help: consider importing one of these items instead
|
1 | use crate::module0::Foo;
|
1 | use crate::module1::Foo;
At a minimum we should detect that these suggestions are invalid and not suggest them:
error[E0574]: expected struct, variant or union type, found enum `Foo`
--> src/main.rs:22:15
|
22 | let foo = Foo { b: 0 };
| ^^^
|
However maybe we should instead suggest that the user try to properly use Foo as an enum?