Auto merge of #54391 - davidtwco:issue-54230, r=petrochenkov

suggest `crate::...` for "local" paths in 2018

Fixes #54230.

This commit adds suggestions for unresolved imports in the cases where
there could be a missing `crate::`, `super::`, `self::` or a missing
external crate name before an import.

r? @nikomatsakis
This commit is contained in:
bors 2018-10-03 21:46:21 +00:00
commit 4bf883b5e7
11 changed files with 296 additions and 19 deletions

View file

@ -19,15 +19,15 @@ mod a {
mod b {
use alloc::HashMap;
//~^ ERROR unresolved import `alloc` [E0432]
//~| Did you mean `a::alloc`?
//~| Did you mean `super::alloc`?
mod c {
use alloc::HashMap;
//~^ ERROR unresolved import `alloc` [E0432]
//~| Did you mean `a::alloc`?
//~| Did you mean `std::alloc`?
mod d {
use alloc::HashMap;
//~^ ERROR unresolved import `alloc` [E0432]
//~| Did you mean `a::alloc`?
//~| Did you mean `std::alloc`?
}
}
}

View file

@ -8,19 +8,19 @@ error[E0432]: unresolved import `alloc`
--> $DIR/resolve_self_super_hint.rs:20:13
|
LL | use alloc::HashMap;
| ^^^^^ Did you mean `a::alloc`?
| ^^^^^ Did you mean `super::alloc`?
error[E0432]: unresolved import `alloc`
--> $DIR/resolve_self_super_hint.rs:24:17
|
LL | use alloc::HashMap;
| ^^^^^ Did you mean `a::alloc`?
| ^^^^^ Did you mean `std::alloc`?
error[E0432]: unresolved import `alloc`
--> $DIR/resolve_self_super_hint.rs:28:21
|
LL | use alloc::HashMap;
| ^^^^^ Did you mean `a::alloc`?
| ^^^^^ Did you mean `std::alloc`?
error: aborting due to 4 previous errors

View file

@ -0,0 +1,15 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// This file is used as part of the local-path-suggestions.rs test.
pub mod foobar {
pub struct Baz;
}

View file

@ -2,7 +2,7 @@ error[E0432]: unresolved import `alloc`
--> $DIR/issue-54006.rs:16:5
|
LL | use alloc::vec;
| ^^^^^ Could not find `alloc` in `{{root}}`
| ^^^^^ Did you mean `std::alloc`?
error: cannot determine resolution for the macro `vec`
--> $DIR/issue-54006.rs:20:18

View file

@ -0,0 +1,36 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:baz.rs
// compile-flags:--extern baz
// edition:2015
// This test exists to demonstrate the behaviour of the import suggestions
// from the `local-path-suggestions-2018.rs` test when not using the 2018 edition.
extern crate baz as aux_baz;
mod foo {
pub type Bar = u32;
}
mod baz {
use foo::Bar;
fn baz() {
let x: Bar = 22;
}
}
use foo::Bar;
use foobar::Baz;
fn main() { }

View file

@ -0,0 +1,9 @@
error[E0432]: unresolved import `foobar`
--> $DIR/local-path-suggestions-2015.rs:34:5
|
LL | use foobar::Baz;
| ^^^^^^ Did you mean `aux_baz::foobar`?
error: aborting due to previous error
For more information about this error, try `rustc --explain E0432`.

View file

@ -0,0 +1,31 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:baz.rs
// compile-flags:--extern baz
// edition:2018
mod foo {
pub type Bar = u32;
}
mod baz {
use foo::Bar;
fn baz() {
let x: Bar = 22;
}
}
use foo::Bar;
use foobar::Baz;
fn main() { }

View file

@ -0,0 +1,21 @@
error[E0432]: unresolved import `foo`
--> $DIR/local-path-suggestions-2018.rs:20:9
|
LL | use foo::Bar;
| ^^^ Did you mean `crate::foo`?
error[E0432]: unresolved import `foo`
--> $DIR/local-path-suggestions-2018.rs:27:5
|
LL | use foo::Bar;
| ^^^ Did you mean `self::foo`?
error[E0432]: unresolved import `foobar`
--> $DIR/local-path-suggestions-2018.rs:29:5
|
LL | use foobar::Baz;
| ^^^^^^ Did you mean `baz::foobar`?
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0432`.