-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Suggest adding a type parameter for impls #85041
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
3 commits
Select commit
Hold shift + click to select a range
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
22 changes: 22 additions & 0 deletions
22
src/test/ui/missing/missing-items/missing-type-parameter2.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,22 @@ | ||
#![allow(incomplete_features)] | ||
#![feature(const_generics_defaults)] | ||
|
||
struct X<const N: u8>(); | ||
|
||
impl X<N> {} | ||
//~^ ERROR cannot find type `N` in this scope | ||
//~| ERROR unresolved item provided when a constant was expected | ||
impl<T, const A: u8 = 2> X<N> {} | ||
//~^ ERROR cannot find type `N` in this scope | ||
//~| ERROR defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions | ||
//~| ERROR unresolved item provided when a constant was expected | ||
|
||
fn foo(_: T) where T: Send {} | ||
//~^ ERROR cannot find type `T` in this scope | ||
//~| ERROR cannot find type `T` in this scope | ||
|
||
fn bar<const N: u8>(_: A) {} | ||
//~^ ERROR cannot find type `A` in this scope | ||
|
||
fn main() { | ||
} |
121 changes: 121 additions & 0 deletions
121
src/test/ui/missing/missing-items/missing-type-parameter2.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,121 @@ | ||
error[E0412]: cannot find type `N` in this scope | ||
--> $DIR/missing-type-parameter2.rs:6:8 | ||
| | ||
LL | struct X<const N: u8>(); | ||
| ------------------------ similarly named struct `X` defined here | ||
LL | | ||
LL | impl X<N> {} | ||
| ^ | ||
| | ||
help: a struct with a similar name exists | ||
| | ||
LL | impl X<X> {} | ||
| ^ | ||
help: you might be missing a type parameter | ||
| | ||
LL | impl<N> X<N> {} | ||
| ^^^ | ||
|
||
error[E0412]: cannot find type `N` in this scope | ||
--> $DIR/missing-type-parameter2.rs:9:28 | ||
| | ||
LL | impl<T, const A: u8 = 2> X<N> {} | ||
| - ^ | ||
| | | ||
| similarly named type parameter `T` defined here | ||
| | ||
help: a type parameter with a similar name exists | ||
| | ||
LL | impl<T, const A: u8 = 2> X<T> {} | ||
| ^ | ||
help: you might be missing a type parameter | ||
| | ||
LL | impl<T, const A: u8 = 2, N> X<N> {} | ||
| ^^^ | ||
|
||
error[E0412]: cannot find type `T` in this scope | ||
--> $DIR/missing-type-parameter2.rs:14:20 | ||
| | ||
LL | struct X<const N: u8>(); | ||
| ------------------------ similarly named struct `X` defined here | ||
... | ||
LL | fn foo(_: T) where T: Send {} | ||
| ^ | ||
| | ||
help: a struct with a similar name exists | ||
| | ||
LL | fn foo(_: T) where X: Send {} | ||
| ^ | ||
help: you might be missing a type parameter | ||
| | ||
LL | fn foo<T>(_: T) where T: Send {} | ||
| ^^^ | ||
|
||
error[E0412]: cannot find type `T` in this scope | ||
--> $DIR/missing-type-parameter2.rs:14:11 | ||
| | ||
LL | struct X<const N: u8>(); | ||
| ------------------------ similarly named struct `X` defined here | ||
... | ||
LL | fn foo(_: T) where T: Send {} | ||
| ^ | ||
| | ||
help: a struct with a similar name exists | ||
| | ||
LL | fn foo(_: X) where T: Send {} | ||
| ^ | ||
help: you might be missing a type parameter | ||
| | ||
LL | fn foo<T>(_: T) where T: Send {} | ||
| ^^^ | ||
|
||
error[E0412]: cannot find type `A` in this scope | ||
--> $DIR/missing-type-parameter2.rs:18:24 | ||
| | ||
LL | struct X<const N: u8>(); | ||
| ------------------------ similarly named struct `X` defined here | ||
... | ||
LL | fn bar<const N: u8>(_: A) {} | ||
| ^ | ||
| | ||
help: a struct with a similar name exists | ||
| | ||
LL | fn bar<const N: u8>(_: X) {} | ||
| ^ | ||
help: you might be missing a type parameter | ||
| | ||
LL | fn bar<const N: u8, A>(_: A) {} | ||
| ^^^ | ||
|
||
error[E0747]: unresolved item provided when a constant was expected | ||
--> $DIR/missing-type-parameter2.rs:6:8 | ||
| | ||
LL | impl X<N> {} | ||
| ^ | ||
| | ||
help: if this generic argument was intended as a const parameter, surround it with braces | ||
| | ||
LL | impl X<{ N }> {} | ||
| ^ ^ | ||
|
||
error: defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions | ||
--> $DIR/missing-type-parameter2.rs:9:15 | ||
| | ||
LL | impl<T, const A: u8 = 2> X<N> {} | ||
| ^ | ||
|
||
error[E0747]: unresolved item provided when a constant was expected | ||
--> $DIR/missing-type-parameter2.rs:9:28 | ||
| | ||
LL | impl<T, const A: u8 = 2> X<N> {} | ||
| ^ | ||
| | ||
help: if this generic argument was intended as a const parameter, surround it with braces | ||
| | ||
LL | impl<T, const A: u8 = 2> X<{ N }> {} | ||
| ^ ^ | ||
|
||
error: aborting due to 8 previous errors | ||
|
||
Some errors have detailed explanations: E0412, E0747. | ||
For more information about an error, try `rustc --explain E0412`. |
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
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.
We should likely filter cases like these, where we suggest the same type we are evaluating, but single letter structs should be uncommon enough that it isn't a problem in practice.