-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Recover parse gracefully from <const N>
#151099
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // #84327 | ||
|
|
||
| struct VecWrapper<T>(Vec<T>); | ||
|
|
||
| // Correct | ||
| impl<T, const N: usize> From<[T; N]> for VecWrapper<T> | ||
| where | ||
| T: Clone, | ||
| { | ||
| fn from(slice: [T; N]) -> Self { | ||
| VecWrapper(slice.to_vec()) | ||
| } | ||
| } | ||
|
|
||
| // Forgot const | ||
| impl<T, N: usize> From<[T; N]> for VecWrapper<T> //~ ERROR expected value, found type parameter `N` | ||
| where //~^ ERROR expected trait, found builtin type `usize` | ||
| T: Clone, | ||
| { | ||
| fn from(slice: [T; N]) -> Self { //~ ERROR expected value, found type parameter `N` | ||
| VecWrapper(slice.to_vec()) | ||
| } | ||
| } | ||
|
|
||
| // Forgot type | ||
| impl<T, const N> From<[T; N]> for VecWrapper<T> //~ ERROR expected `:`, found `>` | ||
| where | ||
| T: Clone, | ||
| { | ||
| fn from(slice: [T; N]) -> Self { | ||
| VecWrapper(slice.to_vec()) | ||
| } | ||
| } | ||
|
|
||
| // Forgot const and type | ||
| impl<T, N> From<[T; N]> for VecWrapper<T> //~ ERROR expected value, found type parameter `N` | ||
| where | ||
| T: Clone, | ||
| { | ||
| fn from(slice: [T; N]) -> Self { //~ ERROR expected value, found type parameter `N` | ||
| VecWrapper(slice.to_vec()) | ||
| } | ||
| } | ||
|
|
||
| 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,70 @@ | ||
| error: expected `:`, found `>` | ||
| --> $DIR/incorrect-const-param.rs:26:16 | ||
| | | ||
| LL | impl<T, const N> From<[T; N]> for VecWrapper<T> | ||
| | ^ expected `:` | ||
| | | ||
| help: you likely meant to write the type of the const parameter here | ||
| | | ||
| LL | impl<T, const N: /* Type */> From<[T; N]> for VecWrapper<T> | ||
| | ++++++++++++ | ||
|
|
||
| error[E0423]: expected value, found type parameter `N` | ||
| --> $DIR/incorrect-const-param.rs:16:28 | ||
| | | ||
| LL | impl<T, N: usize> From<[T; N]> for VecWrapper<T> | ||
| | - ^ not a value | ||
| | | | ||
| | found this type parameter | ||
|
|
||
| error[E0404]: expected trait, found builtin type `usize` | ||
| --> $DIR/incorrect-const-param.rs:16:12 | ||
| | | ||
| LL | impl<T, N: usize> From<[T; N]> for VecWrapper<T> | ||
| | ^^^^^ not a trait | ||
| | | ||
| help: you might have meant to write a const parameter here | ||
| | | ||
| LL | impl<T, const N: usize> From<[T; N]> for VecWrapper<T> | ||
| | +++++ | ||
|
|
||
| error[E0423]: expected value, found type parameter `N` | ||
| --> $DIR/incorrect-const-param.rs:20:24 | ||
| | | ||
| LL | impl<T, N: usize> From<[T; N]> for VecWrapper<T> | ||
| | - found this type parameter | ||
| ... | ||
| LL | fn from(slice: [T; N]) -> Self { | ||
| | ^ not a value | ||
|
|
||
| error[E0423]: expected value, found type parameter `N` | ||
| --> $DIR/incorrect-const-param.rs:36:21 | ||
| | | ||
| LL | impl<T, N> From<[T; N]> for VecWrapper<T> | ||
| | - ^ not a value | ||
| | | | ||
| | found this type parameter | ||
| | | ||
| help: you might have meant to write a const parameter here | ||
| | | ||
| LL | impl<T, const N: /* Type */> From<[T; N]> for VecWrapper<T> | ||
| | +++++ ++++++++++++ | ||
|
|
||
| error[E0423]: expected value, found type parameter `N` | ||
| --> $DIR/incorrect-const-param.rs:40:24 | ||
| | | ||
| LL | impl<T, N> From<[T; N]> for VecWrapper<T> | ||
| | - found this type parameter | ||
| ... | ||
| LL | fn from(slice: [T; N]) -> Self { | ||
| | ^ not a value | ||
| | | ||
| help: you might have meant to write a const parameter here | ||
| | | ||
| LL | impl<T, const N: /* Type */> From<[T; N]> for VecWrapper<T> | ||
| | +++++ ++++++++++++ | ||
|
|
||
| error: aborting due to 6 previous errors | ||
|
|
||
| Some errors have detailed explanations: E0404, E0423. | ||
| For more information about an error, try `rustc --explain E0404`. |
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.
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.
I get that it's nice to group all 3 cases from the issue but is it really necessary? We already have tests in separate files for the other 2 cases we've already addressed (in your PR: #151077, and in mine: #120570).
This doesn't increase test coverage unless I've missed sth. and the added test cases exercise things the preexisting tests don't.
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.
It exercises that the parser recovers correctly besides just providing the suggestion. I tend to group related checks either in the same file when possible, or with files with similar naming. I considered only having this case in the test and then a type error, but felt that having all of them (even if redundant because individual cases are already tested) would help in the future if someone makes changes that incidentally touches these to notice that there are similarly handled cases.