-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
diagnostics: add note when param-env shadows global impl #150424
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
xonx4l
wants to merge
9
commits into
rust-lang:main
Choose a base branch
from
xonx4l:suggest_param_env_shadowing
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.
+216
−4
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5b1070b
Add note for param-env shadowing
xonx4l a873a3f
add suggested changes
xonx4l c576dc5
delete middle check.
xonx4l 071d0cd
rewording note and refer issue
xonx4l 6b3c425
update tests
xonx4l 1eddc17
fix GATs logic
xonx4l 7a2f2fe
fix tidy
xonx4l 7a7d48e
add tests
xonx4l 34981bf
add comments to tests
xonx4l 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
Some comments aren't visible on the classic Files Changed page.
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
17 changes: 17 additions & 0 deletions
17
tests/ui/associated-types/param-env-shadowing-false-positive.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,17 @@ | ||
| // Regression test for issue #149910. | ||
| // The compiler previously incorrectly claimed that the local param-env bound | ||
| // shadowed the global impl, but they are actually the same. | ||
|
|
||
| trait Trait { | ||
| type Assoc; | ||
| } | ||
|
|
||
| impl<T> Trait for T { | ||
| type Assoc = T; | ||
| } | ||
|
|
||
| fn foo<T: Trait>(x: T::Assoc) -> u32 { | ||
| x //~ ERROR mismatched types | ||
| } | ||
|
|
||
| fn main() {} |
18 changes: 18 additions & 0 deletions
18
tests/ui/associated-types/param-env-shadowing-false-positive.stderr
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,18 @@ | ||
| error[E0308]: mismatched types | ||
| --> $DIR/param-env-shadowing-false-positive.rs:14:5 | ||
| | | ||
| LL | fn foo<T: Trait>(x: T::Assoc) -> u32 { | ||
| | --- expected `u32` because of return type | ||
| LL | x | ||
| | ^ expected `u32`, found associated type | ||
| | | ||
| = note: expected type `u32` | ||
| found associated type `<T as Trait>::Assoc` | ||
| help: consider constraining the associated type `<T as Trait>::Assoc` to `u32` | ||
| | | ||
| LL | fn foo<T: Trait<Assoc = u32>>(x: T::Assoc) -> u32 { | ||
| | +++++++++++++ | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0308`. |
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,17 @@ | ||
| // Regression test for issue #149910. | ||
| // This ensures that the diagnostics logic handles Generic Associated Types (GATs) | ||
| // correctly without crashing (ICE). | ||
|
|
||
| trait Trait { | ||
| type Assoc<T>; | ||
| } | ||
|
|
||
| impl<T> Trait for T { | ||
| type Assoc<U> = U; | ||
| } | ||
|
|
||
| fn foo<T: Trait>(x: T::Assoc<T>) -> u32 { | ||
| x //~ ERROR mismatched types | ||
| } | ||
|
|
||
| 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,18 @@ | ||
| error[E0308]: mismatched types | ||
| --> $DIR/param-env-shadowing-gat.rs:14:5 | ||
| | | ||
| LL | fn foo<T: Trait>(x: T::Assoc<T>) -> u32 { | ||
| | --- expected `u32` because of return type | ||
| LL | x | ||
| | ^ expected `u32`, found associated type | ||
| | | ||
| = note: expected type `u32` | ||
| found associated type `<T as Trait>::Assoc<T>` | ||
| help: consider constraining the associated type `<T as Trait>::Assoc<T>` to `u32` | ||
| | | ||
| LL | fn foo<T: Trait<Assoc<T> = u32>>(x: T::Assoc<T>) -> u32 { | ||
| | ++++++++++++++++ | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0308`. |
14 changes: 14 additions & 0 deletions
14
tests/ui/associated-types/param-env-shadowing-issue-149910.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,14 @@ | ||
| trait Trait { | ||
| type Assoc; | ||
| } | ||
|
|
||
| impl<T> Trait for T { | ||
| type Assoc = T; | ||
| } | ||
|
|
||
| fn foo<T: Trait>(x: T) -> T::Assoc { | ||
| x | ||
| //~^ ERROR mismatched types | ||
| } | ||
|
|
||
| fn main() {} |
22 changes: 22 additions & 0 deletions
22
tests/ui/associated-types/param-env-shadowing-issue-149910.stderr
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,22 @@ | ||
| error[E0308]: mismatched types | ||
| --> $DIR/param-env-shadowing-issue-149910.rs:10:5 | ||
| | | ||
| LL | fn foo<T: Trait>(x: T) -> T::Assoc { | ||
| | - -------- expected `<T as Trait>::Assoc` because of return type | ||
| | | | ||
| | found this type parameter | ||
| LL | x | ||
| | ^ expected associated type, found type parameter `T` | ||
| | | ||
| = note: expected associated type `<T as Trait>::Assoc` | ||
| found type parameter `T` | ||
| = note: the associated type `<T as Trait>::Assoc` is defined as `T` in the implementation, but the where-bound `T` shadows this definition | ||
| see issue #152409 <https://github.com/rust-lang/rust/issues/152409> for more information | ||
| help: consider further restricting this bound | ||
| | | ||
| LL | fn foo<T: Trait<Assoc = T>>(x: T) -> T::Assoc { | ||
| | +++++++++++ | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0308`. |
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
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.
can you add a comment to each test explaining what it is testing?
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 all the comments for the tests.