forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#96353 - estebank:issue-95413, r=compiler-errors
When suggesting to import an item, also suggest changing the path if appropriate When we don't find an item we search all of them for an appropriate import and suggest `use`ing it. This is sometimes done for expressions that have paths with more than one segment. We now also suggest changing that path to work with the `use`. Fix rust-lang#95413
- Loading branch information
Showing
14 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/test/ui/trait-bounds/shadowed-path-in-trait-bound-suggestion.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// run-rustfix | ||
#![allow(non_snake_case)] | ||
mod A { | ||
pub trait Trait {} | ||
impl Trait for i32 {} | ||
} | ||
|
||
mod B { | ||
use A::Trait; | ||
|
||
pub struct A<H: Trait>(pub H); //~ ERROR cannot find trait | ||
} | ||
|
||
fn main() { | ||
let _ = B::A(42); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/test/ui/trait-bounds/shadowed-path-in-trait-bound-suggestion.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// run-rustfix | ||
#![allow(non_snake_case)] | ||
mod A { | ||
pub trait Trait {} | ||
impl Trait for i32 {} | ||
} | ||
|
||
mod B { | ||
pub struct A<H: A::Trait>(pub H); //~ ERROR cannot find trait | ||
} | ||
|
||
fn main() { | ||
let _ = B::A(42); | ||
} |
19 changes: 19 additions & 0 deletions
19
src/test/ui/trait-bounds/shadowed-path-in-trait-bound-suggestion.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
error[E0405]: cannot find trait `Trait` in `A` | ||
--> $DIR/shadowed-path-in-trait-bound-suggestion.rs:9:24 | ||
| | ||
LL | pub struct A<H: A::Trait>(pub H); | ||
| ^^^^^ not found in `A` | ||
| | ||
help: consider importing this trait | ||
| | ||
LL | use A::Trait; | ||
| | ||
help: if you import `Trait`, refer to it directly | ||
| | ||
LL - pub struct A<H: A::Trait>(pub H); | ||
LL + pub struct A<H: Trait>(pub H); | ||
| | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0405`. |