-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Improve suggestions for importing out-of-scope traits reexported as _
#91412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
48dab5c
Test for issue-86035
compiler-errors 1f2cf1e
Prefer visibility paths where items are not named `_`
compiler-errors c327627
Bail if printing item named `_` in `try_print_visible_def_path`
compiler-errors f835085
Suggest glob-import if we need to import a trait, but it has no visib…
compiler-errors 682a342
Fixup tests for issue-86035
compiler-errors File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
13 changes: 13 additions & 0 deletions
13
src/test/ui/imports/auxiliary/overlapping_pub_trait_source.rs
This file contains hidden or 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,13 @@ | ||
/* This crate declares an item as both `prelude::*` and `m::Tr`. | ||
* The compiler should always suggest `m::Tr`. */ | ||
|
||
pub struct S; | ||
|
||
pub mod prelude { | ||
pub use crate::m::Tr as _; | ||
} | ||
|
||
pub mod m { | ||
pub trait Tr { fn method(&self); } | ||
impl Tr for crate::S { fn method(&self) {} } | ||
} |
This file contains hidden or 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,13 @@ | ||
/* This crate declares an item that is unnamed. | ||
* Its only public path is through `prelude::*`. */ | ||
|
||
pub struct S; | ||
compiler-errors marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
mod m { | ||
pub trait Tr { fn method(&self); } | ||
impl Tr for crate::S { fn method(&self) {} } | ||
} | ||
|
||
pub mod prelude { | ||
pub use crate::m::Tr as _; | ||
} |
This file contains hidden or 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,15 @@ | ||
// aux-build:overlapping_pub_trait_source.rs | ||
|
||
/* | ||
* This crate declares two public paths, `m::Tr` and `prelude::_`. Make sure we prefer the former. | ||
*/ | ||
extern crate overlapping_pub_trait_source; | ||
|
||
fn main() { | ||
//~^ HELP the following trait is implemented but not in scope; perhaps add a `use` for it: | ||
//~| SUGGESTION overlapping_pub_trait_source::m::Tr | ||
use overlapping_pub_trait_source::S; | ||
S.method(); | ||
//~^ ERROR no method named `method` found for struct `S` in the current scope [E0599] | ||
//~| HELP items from traits can only be used if the trait is in scope | ||
} |
This file contains hidden or 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,20 @@ | ||
error[E0599]: no method named `method` found for struct `S` in the current scope | ||
--> $DIR/overlapping_pub_trait.rs:12:7 | ||
| | ||
LL | S.method(); | ||
| ^^^^^^ method not found in `S` | ||
| | ||
::: $DIR/auxiliary/overlapping_pub_trait_source.rs:11:23 | ||
| | ||
LL | pub trait Tr { fn method(&self); } | ||
| ------ the method is available for `S` here | ||
| | ||
= help: items from traits can only be used if the trait is in scope | ||
help: the following trait is implemented but not in scope; perhaps add a `use` for it: | ||
| | ||
LL | use overlapping_pub_trait_source::m::Tr; | ||
| | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0599`. |
This file contains hidden or 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 @@ | ||
// aux-build:unnamed_pub_trait_source.rs | ||
|
||
/* | ||
* This crate declares an unnameable public path for our item. Make sure we don't suggest | ||
* importing it by name, and instead we suggest importing it by glob. | ||
*/ | ||
extern crate unnamed_pub_trait_source; | ||
|
||
fn main() { | ||
//~^ HELP the following trait is implemented but not in scope; perhaps add a `use` for it: | ||
//~| SUGGESTION unnamed_pub_trait_source::prelude::*; // trait Tr | ||
use unnamed_pub_trait_source::S; | ||
S.method(); | ||
//~^ ERROR no method named `method` found for struct `S` in the current scope [E0599] | ||
//~| HELP items from traits can only be used if the trait is in scope | ||
} |
This file contains hidden or 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,20 @@ | ||
error[E0599]: no method named `method` found for struct `S` in the current scope | ||
--> $DIR/unnamed_pub_trait.rs:13:7 | ||
| | ||
LL | S.method(); | ||
| ^^^^^^ method not found in `S` | ||
| | ||
::: $DIR/auxiliary/unnamed_pub_trait_source.rs:7:23 | ||
| | ||
LL | pub trait Tr { fn method(&self); } | ||
| ------ the method is available for `S` here | ||
| | ||
= help: items from traits can only be used if the trait is in scope | ||
help: the following trait is implemented but not in scope; perhaps add a `use` for it: | ||
| | ||
LL | use unnamed_pub_trait_source::prelude::*; // trait Tr | ||
compiler-errors marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0599`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.