-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Handle mismatched generic param kinds in trait impls betterly #96717
Merged
bors
merged 5 commits into
rust-lang:master
from
BoxyUwU:gats_const_param_types_mismatch_err
May 10, 2022
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6225e98
handle mismatched generic parameter kinds
BoxyUwU 4208c53
exit out of `compare_number_of_generics` early
BoxyUwU fea1d76
make `compare_generic_param_kinds` errors consistent
BoxyUwU 2819b2d
wording tweaks
BoxyUwU e4b8ed5
move closure down
BoxyUwU 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 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
41 changes: 41 additions & 0 deletions
41
src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.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,41 @@ | ||
trait Trait { | ||
fn foo<U>() {} | ||
} | ||
impl Trait for () { | ||
fn foo<const M: u64>() {} | ||
//~^ error: method `foo` has an incompatible generic parameter for trait | ||
} | ||
|
||
trait Other { | ||
fn bar<const M: u8>() {} | ||
} | ||
impl Other for () { | ||
fn bar<T>() {} | ||
//~^ error: method `bar` has an incompatible generic parameter for trait | ||
} | ||
|
||
trait Uwu { | ||
fn baz<const N: u32>() {} | ||
} | ||
impl Uwu for () { | ||
fn baz<const N: i32>() {} | ||
//~^ error: method `baz` has an incompatible generic parameter for trait | ||
} | ||
|
||
trait Aaaaaa { | ||
fn bbbb<const N: u32, T>() {} | ||
} | ||
impl Aaaaaa for () { | ||
fn bbbb<T, const N: u32>() {} | ||
//~^ error: method `bbbb` has an incompatible generic parameter for trait | ||
} | ||
|
||
trait Names { | ||
fn abcd<T, const N: u32>() {} | ||
} | ||
impl Names for () { | ||
fn abcd<const N: u32, T>() {} | ||
//~^ error: method `abcd` has an incompatible generic parameter for trait | ||
} | ||
|
||
fn main() {} |
68 changes: 68 additions & 0 deletions
68
src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.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,68 @@ | ||
error[E0053]: method `foo` has an incompatible generic parameter for trait: `Trait` | ||
--> $DIR/mismatched_ty_const_in_trait_impl.rs:5:12 | ||
| | ||
LL | trait Trait { | ||
| ----- | ||
LL | fn foo<U>() {} | ||
| - expected type parameter | ||
LL | } | ||
LL | impl Trait for () { | ||
| ----------------- | ||
LL | fn foo<const M: u64>() {} | ||
| ^^^^^^^^^^^^ found const parameter with type `u64` | ||
|
||
error[E0053]: method `bar` has an incompatible generic parameter for trait: `Other` | ||
--> $DIR/mismatched_ty_const_in_trait_impl.rs:13:12 | ||
| | ||
LL | trait Other { | ||
| ----- | ||
LL | fn bar<const M: u8>() {} | ||
| ----------- expected const parameter with type `u8` | ||
LL | } | ||
LL | impl Other for () { | ||
| ----------------- | ||
LL | fn bar<T>() {} | ||
| ^ found type parameter | ||
|
||
error[E0053]: method `baz` has an incompatible generic parameter for trait: `Uwu` | ||
--> $DIR/mismatched_ty_const_in_trait_impl.rs:21:12 | ||
| | ||
LL | trait Uwu { | ||
| --- | ||
LL | fn baz<const N: u32>() {} | ||
| ------------ expected const parameter with type `u32` | ||
LL | } | ||
LL | impl Uwu for () { | ||
| --------------- | ||
LL | fn baz<const N: i32>() {} | ||
| ^^^^^^^^^^^^ found const parameter with type `i32` | ||
|
||
error[E0053]: method `bbbb` has an incompatible generic parameter for trait: `Aaaaaa` | ||
--> $DIR/mismatched_ty_const_in_trait_impl.rs:29:13 | ||
| | ||
LL | trait Aaaaaa { | ||
| ------ | ||
LL | fn bbbb<const N: u32, T>() {} | ||
| ------------ expected const parameter with type `u32` | ||
LL | } | ||
LL | impl Aaaaaa for () { | ||
| ------------------ | ||
LL | fn bbbb<T, const N: u32>() {} | ||
| ^ found type parameter | ||
|
||
error[E0053]: method `abcd` has an incompatible generic parameter for trait: `Names` | ||
--> $DIR/mismatched_ty_const_in_trait_impl.rs:37:13 | ||
| | ||
LL | trait Names { | ||
| ----- | ||
LL | fn abcd<T, const N: u32>() {} | ||
| - expected type parameter | ||
LL | } | ||
LL | impl Names for () { | ||
| ----------------- | ||
LL | fn abcd<const N: u32, T>() {} | ||
| ^^^^^^^^^^^^ found const parameter with type `u32` | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0053`. |
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
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.
For me "of type" seems more natural here, idk 😅
Considering that this closure doesn't capture anything, can you move it out of the loop to
ty_const_params_of
?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.
Changed the error wording.
I don't think it'd be good to have the closure be by
ty_const_params_of
since then its really far away from the code actually calling the closure. I pushed code moving it furthur down so its closer to the call site, imo makes it easier to understand the code.