-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Do not suggest 'Trait<Assoc=arg>' when in trait impl #116553
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
bors
merged 1 commit into
rust-lang:master
from
gurry:116464-assoc-type-invalid-suggestion
Oct 26, 2023
Merged
Changes from all commits
Commits
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
43 changes: 43 additions & 0 deletions
43
tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.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,43 @@ | ||
// Regression test for #116464 | ||
// Checks that we do not suggest Trait<..., Assoc=arg> when the trait | ||
// is referred to from one of its impls but do so at all other places | ||
|
||
pub trait Trait<T> { | ||
type Assoc; | ||
} | ||
|
||
impl<T, S> Trait<T> for i32 { | ||
type Assoc = String; | ||
} | ||
|
||
// Should not not trigger suggestion here... | ||
impl<T, S> Trait<T, S> for () {} | ||
//~^ ERROR trait takes 1 generic argument but 2 generic arguments were supplied | ||
|
||
//... but should do so in all of the below cases except the last one | ||
fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), i32> { | ||
//~^ ERROR trait takes 1 generic argument but 2 generic arguments were supplied | ||
//~| ERROR trait takes 1 generic argument but 2 generic arguments were supplied | ||
3 | ||
} | ||
|
||
struct Struct<T: Trait<u32, String>> { | ||
//~^ ERROR trait takes 1 generic argument but 2 generic arguments were supplied | ||
a: T | ||
} | ||
|
||
trait AnotherTrait<T: Trait<T, i32>> {} | ||
//~^ ERROR trait takes 1 generic argument but 2 generic arguments were supplied | ||
|
||
impl<T: Trait<u32, String>> Struct<T> {} | ||
//~^ ERROR trait takes 1 generic argument but 2 generic arguments were supplied | ||
|
||
// Test for self type. Should not trigger suggestion as it doesn't have an | ||
// associated type | ||
trait YetAnotherTrait {} | ||
impl<T: Trait<u32, Assoc=String>, U> YetAnotherTrait for Struct<T, U> {} | ||
//~^ ERROR struct takes 1 generic argument but 2 generic arguments were supplied | ||
|
||
|
||
fn main() { | ||
} |
109 changes: 109 additions & 0 deletions
109
...ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.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,109 @@ | ||
error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied | ||
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:14:12 | ||
| | ||
LL | impl<T, S> Trait<T, S> for () {} | ||
| ^^^^^ expected 1 generic argument | ||
| | ||
note: trait defined here, with 1 generic parameter: `T` | ||
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:5:11 | ||
| | ||
LL | pub trait Trait<T> { | ||
| ^^^^^ - | ||
|
||
error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied | ||
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:18:12 | ||
| | ||
LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), i32> { | ||
| ^^^^^ expected 1 generic argument | ||
| | ||
note: trait defined here, with 1 generic parameter: `T` | ||
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:5:11 | ||
| | ||
LL | pub trait Trait<T> { | ||
| ^^^^^ - | ||
help: replace the generic bound with the associated type | ||
| | ||
LL | fn func<T: Trait<u32, Assoc = String>>(t: T) -> impl Trait<(), i32> { | ||
| +++++++ | ||
|
||
error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied | ||
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:18:46 | ||
| | ||
LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), i32> { | ||
| ^^^^^ expected 1 generic argument | ||
| | ||
note: trait defined here, with 1 generic parameter: `T` | ||
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:5:11 | ||
| | ||
LL | pub trait Trait<T> { | ||
| ^^^^^ - | ||
help: replace the generic bound with the associated type | ||
| | ||
LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), Assoc = i32> { | ||
| +++++++ | ||
|
||
error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied | ||
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:24:18 | ||
| | ||
LL | struct Struct<T: Trait<u32, String>> { | ||
| ^^^^^ expected 1 generic argument | ||
| | ||
note: trait defined here, with 1 generic parameter: `T` | ||
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:5:11 | ||
| | ||
LL | pub trait Trait<T> { | ||
| ^^^^^ - | ||
help: replace the generic bound with the associated type | ||
| | ||
LL | struct Struct<T: Trait<u32, Assoc = String>> { | ||
| +++++++ | ||
|
||
error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied | ||
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:29:23 | ||
| | ||
LL | trait AnotherTrait<T: Trait<T, i32>> {} | ||
| ^^^^^ expected 1 generic argument | ||
| | ||
note: trait defined here, with 1 generic parameter: `T` | ||
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:5:11 | ||
| | ||
LL | pub trait Trait<T> { | ||
| ^^^^^ - | ||
help: replace the generic bound with the associated type | ||
| | ||
LL | trait AnotherTrait<T: Trait<T, Assoc = i32>> {} | ||
| +++++++ | ||
|
||
error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied | ||
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:32:9 | ||
| | ||
LL | impl<T: Trait<u32, String>> Struct<T> {} | ||
| ^^^^^ expected 1 generic argument | ||
| | ||
note: trait defined here, with 1 generic parameter: `T` | ||
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:5:11 | ||
| | ||
LL | pub trait Trait<T> { | ||
| ^^^^^ - | ||
help: replace the generic bound with the associated type | ||
| | ||
LL | impl<T: Trait<u32, Assoc = String>> Struct<T> {} | ||
| +++++++ | ||
|
||
error[E0107]: struct takes 1 generic argument but 2 generic arguments were supplied | ||
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:38:58 | ||
| | ||
LL | impl<T: Trait<u32, Assoc=String>, U> YetAnotherTrait for Struct<T, U> {} | ||
| ^^^^^^ - help: remove this generic argument | ||
| | | ||
| expected 1 generic argument | ||
| | ||
note: struct defined here, with 1 generic parameter: `T` | ||
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:24:8 | ||
| | ||
LL | struct Struct<T: Trait<u32, String>> { | ||
| ^^^^^^ - | ||
|
||
error: aborting due to 7 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0107`. |
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.