Rollup merge of #72623 - da-x:use-suggest-public-path, r=petrochenkov

Prefer accessible paths in 'use' suggestions

This PR addresses issue https://github.com/rust-lang/rust/issues/26454, where `use` suggestions are made for paths that don't work. For example:

```rust
mod foo {
    mod bar {
        struct X;
    }
}

fn main() { X; } // suggests `use foo::bar::X;`
```
This commit is contained in:
Dylan DPC 2020-06-22 14:53:48 +02:00 committed by GitHub
commit fdd241f5b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 99 additions and 82 deletions

View file

@ -23,14 +23,10 @@ LL | | }
| |_____- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing one of these items
help: consider importing this function
|
LL | use bar::g;
|
LL | use foo::test2::test::g;
|
LL | use foo::test::g;
|
error[E0425]: cannot find function `f` in this scope
--> $DIR/globs.rs:61:12

View file

@ -0,0 +1,12 @@
mod foo {
pub struct B(pub ());
}
mod baz {
fn foo() {
B(());
//~^ ERROR cannot find function, tuple struct or tuple variant `B` in this scope [E0425]
}
}
fn main() {}

View file

@ -0,0 +1,14 @@
error[E0425]: cannot find function, tuple struct or tuple variant `B` in this scope
--> $DIR/issue-26545.rs:7:9
|
LL | B(());
| ^ not found in this scope
|
help: consider importing this tuple struct
|
LL | use foo::B;
|
error: aborting due to previous error
For more information about this error, try `rustc --explain E0425`.

View file

@ -33,7 +33,7 @@ fn qux() -> Some {
fn main() {}
mod x {
enum Enum {
pub enum Enum {
Variant1,
Variant2(),
Variant3(usize),

View file

@ -1,20 +1,20 @@
mod foo {
pub struct B(());
pub struct Bx(());
}
mod bar {
use foo::B;
use foo::Bx;
fn foo() {
B(());
//~^ ERROR expected function, tuple struct or tuple variant, found struct `B` [E0423]
Bx(());
//~^ ERROR expected function, tuple struct or tuple variant, found struct `Bx` [E0423]
}
}
mod baz {
fn foo() {
B(());
//~^ ERROR cannot find function, tuple struct or tuple variant `B` in this scope [E0425]
Bx(());
//~^ ERROR cannot find function, tuple struct or tuple variant `Bx` in this scope [E0425]
}
}

View file

@ -1,18 +1,18 @@
error[E0423]: expected function, tuple struct or tuple variant, found struct `B`
error[E0423]: expected function, tuple struct or tuple variant, found struct `Bx`
--> $DIR/issue-42944.rs:9:9
|
LL | B(());
| ^ constructor is not visible here due to private fields
LL | Bx(());
| ^^ constructor is not visible here due to private fields
error[E0425]: cannot find function, tuple struct or tuple variant `B` in this scope
error[E0425]: cannot find function, tuple struct or tuple variant `Bx` in this scope
--> $DIR/issue-42944.rs:16:9
|
LL | B(());
| ^ not found in this scope
LL | Bx(());
| ^^ not found in this scope
|
help: consider importing this tuple struct
|
LL | use foo::B;
LL | use foo::Bx;
|
error: aborting due to 2 previous errors

View file

@ -15,12 +15,10 @@ error[E0423]: expected function, found module `foo`
LL | foo();
| ^^^ not a function
|
help: consider importing one of these items instead
help: consider importing this function instead
|
LL | use foo::foo;
|
LL | use m1::foo;
|
error: aborting due to 2 previous errors

View file

@ -4,12 +4,10 @@ error[E0425]: cannot find function `foo` in this scope
LL | fn sub() -> isize { foo(); 1 }
| ^^^ not found in this scope
|
help: consider importing one of these items
help: consider importing this function
|
LL | use foo::foo;
|
LL | use m1::foo;
|
error: aborting due to previous error

View file

@ -11,14 +11,10 @@ help: a unit struct with a similar name exists
|
LL | Baz();
| ^^^
help: consider importing one of these items instead
|
LL | use foo1::Bar;
help: consider importing this function instead
|
LL | use foo2::Bar;
|
LL | use foo3::Bar;
|
error[E0425]: cannot find function, tuple struct or tuple variant `Bar` in this scope
--> $DIR/privacy-ns1.rs:51:5
@ -33,14 +29,10 @@ help: a unit struct with a similar name exists
|
LL | Baz();
| ^^^
help: consider importing one of these items
|
LL | use foo1::Bar;
help: consider importing this function
|
LL | use foo2::Bar;
|
LL | use foo3::Bar;
|
error[E0412]: cannot find type `Bar` in this scope
--> $DIR/privacy-ns1.rs:52:17
@ -55,14 +47,10 @@ help: a struct with a similar name exists
|
LL | let _x: Box<Baz>;
| ^^^
help: consider importing one of these items
help: consider importing this trait
|
LL | use foo1::Bar;
|
LL | use foo2::Bar;
|
LL | use foo3::Bar;
|
error[E0107]: wrong number of const arguments: expected 0, found 1
--> $DIR/privacy-ns1.rs:35:17

View file

@ -4,14 +4,10 @@ error[E0423]: expected function, tuple struct or tuple variant, found trait `Bar
LL | Bar();
| ^^^ not a function, tuple struct or tuple variant
|
help: consider importing one of these items instead
|
LL | use foo1::Bar;
help: consider importing this function instead
|
LL | use foo2::Bar;
|
LL | use foo3::Bar;
|
error[E0423]: expected function, tuple struct or tuple variant, found trait `Bar`
--> $DIR/privacy-ns2.rs:26:5
@ -26,14 +22,10 @@ help: a unit struct with a similar name exists
|
LL | Baz();
| ^^^
help: consider importing one of these items instead
|
LL | use foo1::Bar;
help: consider importing this function instead
|
LL | use foo2::Bar;
|
LL | use foo3::Bar;
|
error[E0573]: expected type, found function `Bar`
--> $DIR/privacy-ns2.rs:43:14
@ -45,14 +37,10 @@ help: use `=` if you meant to assign
|
LL | let _x = Bar();
| ^
help: consider importing one of these items instead
help: consider importing this trait instead
|
LL | use foo1::Bar;
|
LL | use foo2::Bar;
|
LL | use foo3::Bar;
|
error[E0603]: trait `Bar` is private
--> $DIR/privacy-ns2.rs:63:15

View file

@ -25,11 +25,8 @@ LL | use mul1::Mul;
|
LL | use mul2::Mul;
|
LL | use mul3::Mul;
LL | use std::ops::Mul;
|
LL | use mul4::Mul;
|
and 2 other candidates
error[E0405]: cannot find trait `ThisTraitReallyDoesntExistInAnyModuleReally` in this scope
--> $DIR/issue-21221-1.rs:63:6