Only suggest imports if not imported.
This commit modifies name resolution error reporting so that if a name is in scope and has been imported then we do not suggest importing it. This can occur when we add a label about constructors not being visible due to private fields. In these cases, we know that the struct/variant has been imported and we should silence any suggestions to import the struct/variant.
This commit is contained in:
parent
de111e6367
commit
48b0c9da69
5 changed files with 63 additions and 17 deletions
19
src/test/ui/issue-42944.rs
Normal file
19
src/test/ui/issue-42944.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
mod foo {
|
||||
pub struct B(());
|
||||
}
|
||||
|
||||
mod bar {
|
||||
use foo::B;
|
||||
|
||||
fn foo() {
|
||||
B(()); //~ ERROR expected function, found struct `B` [E0423]
|
||||
}
|
||||
}
|
||||
|
||||
mod baz {
|
||||
fn foo() {
|
||||
B(()); //~ ERROR cannot find function `B` in this scope [E0425]
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
20
src/test/ui/issue-42944.stderr
Normal file
20
src/test/ui/issue-42944.stderr
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
error[E0423]: expected function, found struct `B`
|
||||
--> $DIR/issue-42944.rs:9:9
|
||||
|
|
||||
LL | B(()); //~ ERROR expected function, found struct `B` [E0423]
|
||||
| ^ constructor is not visible here due to private fields
|
||||
|
||||
error[E0425]: cannot find function `B` in this scope
|
||||
--> $DIR/issue-42944.rs:15:9
|
||||
|
|
||||
LL | B(()); //~ ERROR cannot find function `B` in this scope [E0425]
|
||||
| ^ not found in this scope
|
||||
help: possible candidate is found in another module, you can import it into scope
|
||||
|
|
||||
LL | use foo::B;
|
||||
|
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors occurred: E0423, E0425.
|
||||
For more information about an error, try `rustc --explain E0423`.
|
||||
|
|
@ -2,25 +2,16 @@ error[E0423]: expected value, found struct `Z`
|
|||
--> $DIR/privacy-struct-ctor.rs:20:9
|
||||
|
|
||||
LL | Z;
|
||||
| ^ constructor is not visible here due to private fields
|
||||
help: a tuple struct with a similar name exists
|
||||
|
|
||||
LL | S;
|
||||
| ^
|
||||
help: possible better candidate is found in another module, you can import it into scope
|
||||
|
|
||||
LL | use m::n::Z;
|
||||
|
|
||||
| |
|
||||
| constructor is not visible here due to private fields
|
||||
| help: a tuple struct with a similar name exists: `S`
|
||||
|
||||
error[E0423]: expected value, found struct `S`
|
||||
--> $DIR/privacy-struct-ctor.rs:33:5
|
||||
|
|
||||
LL | S;
|
||||
| ^ constructor is not visible here due to private fields
|
||||
help: possible better candidate is found in another module, you can import it into scope
|
||||
|
|
||||
LL | use m::S;
|
||||
|
|
||||
|
||||
error[E0423]: expected value, found struct `S2`
|
||||
--> $DIR/privacy-struct-ctor.rs:38:5
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue