-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Modify error message of importing inherent associated items when #[feature(import_trait_associated_functions)] is enabled
#152611
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
Open
CoCo-Japan-pan
wants to merge
3
commits into
rust-lang:main
Choose a base branch
from
CoCo-Japan-pan:fix-148009
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+178
−21
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
58374d7
Modify the error message shown when a user tries to import inherent a…
CoCo-Japan-pan 4d5ce5d
Add note for enum import errors when `import_trait_associated_functio…
CoCo-Japan-pan fae6a31
Add UI tests for inherent associated item import attempts
CoCo-Japan-pan 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| //! Check that when the feature `import_trait_associated_functions` is enabled, | ||
| //! and one trys to import inherent associated items, the error message is | ||
| //! updated to reflect that only trait associated items can be imported. | ||
| //! | ||
| //! Regression test for <https://github.com/rust-lang/rust/issues/148009>. | ||
|
|
||
| //@ check-fail | ||
|
|
||
| #![feature(import_trait_associated_functions, extern_types)] | ||
|
|
||
| pub struct TestStruct; | ||
|
|
||
| impl TestStruct { | ||
| pub fn m1() {} | ||
| pub const C1: usize = 0; | ||
| } | ||
|
|
||
| pub use self::TestStruct::{C1, m1}; | ||
| //~^ ERROR unresolved import `self::TestStruct` [E0432] | ||
| //~| NOTE `TestStruct` is a struct, not a module or a trait | ||
| //~| NOTE cannot import inherent associated items, only trait associated items | ||
|
|
||
| pub union TestUnion { | ||
| pub f: f32, | ||
| pub i: i32, | ||
| } | ||
|
|
||
| impl TestUnion { | ||
| pub fn m2() {} | ||
| pub const C2: usize = 0; | ||
| } | ||
|
|
||
| pub use self::TestUnion::{C2, m2}; | ||
| //~^ ERROR unresolved import `self::TestUnion` [E0432] | ||
| //~| NOTE `TestUnion` is a union, not a module or a trait | ||
| //~| NOTE cannot import inherent associated items, only trait associated items | ||
|
|
||
| pub enum TestEnum { | ||
| V1, | ||
| V2, | ||
| } | ||
|
|
||
| impl TestEnum { | ||
| pub fn m3() {} | ||
| pub const C3: usize = 0; | ||
| } | ||
|
|
||
| pub use self::TestEnum::{C3, m3}; | ||
| //~^ ERROR unresolved imports `self::TestEnum::C3`, `self::TestEnum::m3` [E0432] | ||
| //~| NOTE no `m3` in `TestEnum` | ||
| //~| NOTE no `C3` in `TestEnum` | ||
| //~| NOTE cannot import inherent associated items, only trait associated items | ||
|
|
||
| extern "C" { | ||
| pub type TestForeignTy; | ||
| } | ||
|
|
||
| impl TestForeignTy { | ||
| pub fn m4() {} | ||
| pub const C4: usize = 0; | ||
| } | ||
|
|
||
| pub use self::TestForeignTy::{C4, m4}; | ||
| //~^ ERROR unresolved import `self::TestForeignTy` [E0432] | ||
| //~| NOTE `TestForeignTy` is a foreign type, not a module or a trait | ||
| //~| NOTE cannot import inherent associated items, only trait associated items | ||
|
|
||
| fn main() {} | ||
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,37 @@ | ||
| error[E0432]: unresolved import `self::TestStruct` | ||
| --> $DIR/import-inherent-148009.rs:18:15 | ||
| | | ||
| LL | pub use self::TestStruct::{C1, m1}; | ||
| | ^^^^^^^^^^ `TestStruct` is a struct, not a module or a trait | ||
| | | ||
| = note: cannot import inherent associated items, only trait associated items | ||
|
|
||
| error[E0432]: unresolved import `self::TestUnion` | ||
| --> $DIR/import-inherent-148009.rs:33:15 | ||
| | | ||
| LL | pub use self::TestUnion::{C2, m2}; | ||
| | ^^^^^^^^^ `TestUnion` is a union, not a module or a trait | ||
| | | ||
| = note: cannot import inherent associated items, only trait associated items | ||
|
|
||
| error[E0432]: unresolved imports `self::TestEnum::C3`, `self::TestEnum::m3` | ||
| --> $DIR/import-inherent-148009.rs:48:26 | ||
| | | ||
| LL | pub use self::TestEnum::{C3, m3}; | ||
| | ^^ ^^ no `m3` in `TestEnum` | ||
| | | | ||
| | no `C3` in `TestEnum` | ||
| | | ||
| = note: cannot import inherent associated items, only trait associated items | ||
|
|
||
| error[E0432]: unresolved import `self::TestForeignTy` | ||
| --> $DIR/import-inherent-148009.rs:63:15 | ||
| | | ||
| LL | pub use self::TestForeignTy::{C4, m4}; | ||
| | ^^^^^^^^^^^^^ `TestForeignTy` is a foreign type, not a module or a trait | ||
| | | ||
| = note: cannot import inherent associated items, only trait associated items | ||
|
|
||
| error: aborting due to 4 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0432`. |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you have to add further annotations to actually test the label? Something like
//~| NOTE cannot import inherent associated items, only trait associated itemsIIRC?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a note
NOTE cannot import inherent associated items, only trait associated itemsin fae6a31