-
Notifications
You must be signed in to change notification settings - Fork 13.4k
feat(rustc_parse): recover from pre-RFC-2000 const generics syntax #89029
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 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d8e9db0
feat(rustc_parse): recover from pre-RFC-2000 const generics syntax
notriddle 8a7c130
Use less verbose syntax for error annotations
notriddle befdfb5
Improve error messages for bad type constraints
notriddle 105b60f
feat(rustc_typeck): avoid erroring with "wrong number of generics" if…
notriddle 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
16 changes: 16 additions & 0 deletions
16
src/test/ui/const-generics/parser-error-recovery/issue-89013-no-assoc.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,16 @@ | ||
trait Foo<const N: usize> { | ||
fn do_x(&self) -> [u8; N]; | ||
} | ||
|
||
struct Bar; | ||
|
||
const T: usize = 42; | ||
|
||
impl Foo<const 3> for Bar { | ||
//~^ERROR expected lifetime, type, or constant, found keyword `const` | ||
fn do_x(&self) -> [u8; 3] { | ||
[0u8; 3] | ||
} | ||
} | ||
|
||
fn main() {} |
8 changes: 8 additions & 0 deletions
8
src/test/ui/const-generics/parser-error-recovery/issue-89013-no-assoc.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,8 @@ | ||
error: expected lifetime, type, or constant, found keyword `const` | ||
--> $DIR/issue-89013-no-assoc.rs:9:10 | ||
| | ||
LL | impl Foo<const 3> for Bar { | ||
| ^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
18 changes: 18 additions & 0 deletions
18
src/test/ui/const-generics/parser-error-recovery/issue-89013-no-kw.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,18 @@ | ||
trait Foo<const N: usize> { | ||
fn do_x(&self) -> [u8; N]; | ||
} | ||
|
||
struct Bar; | ||
|
||
const T: usize = 42; | ||
|
||
impl Foo<N = 3> for Bar { | ||
//~^ERROR cannot constrain an associated constant to a value | ||
//~^^ERROR this trait takes 1 generic argument but 0 generic arguments | ||
//~^^^ERROR associated type bindings are not allowed here | ||
fn do_x(&self) -> [u8; 3] { | ||
[0u8; 3] | ||
} | ||
} | ||
|
||
fn main() {} |
35 changes: 35 additions & 0 deletions
35
src/test/ui/const-generics/parser-error-recovery/issue-89013-no-kw.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,35 @@ | ||
error: cannot constrain an associated constant to a value | ||
--> $DIR/issue-89013-no-kw.rs:9:10 | ||
| | ||
LL | impl Foo<N = 3> for Bar { | ||
| -^^^- | ||
| | | | ||
| | ...cannot be constrained to this value | ||
| this associated constant... | ||
|
||
error[E0107]: this trait takes 1 generic argument but 0 generic arguments were supplied | ||
--> $DIR/issue-89013-no-kw.rs:9:6 | ||
| | ||
LL | impl Foo<N = 3> for Bar { | ||
| ^^^ expected 1 generic argument | ||
| | ||
note: trait defined here, with 1 generic parameter: `N` | ||
--> $DIR/issue-89013-no-kw.rs:1:7 | ||
| | ||
LL | trait Foo<const N: usize> { | ||
| ^^^ - | ||
help: add missing generic argument | ||
| | ||
LL | impl Foo<N, N = 3> for Bar { | ||
| ++ | ||
|
||
error[E0229]: associated type bindings are not allowed here | ||
--> $DIR/issue-89013-no-kw.rs:9:10 | ||
| | ||
LL | impl Foo<N = 3> for Bar { | ||
| ^^^^^ associated type not allowed here | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
Some errors have detailed explanations: E0107, E0229. | ||
For more information about an error, try `rustc --explain E0107`. |
17 changes: 17 additions & 0 deletions
17
src/test/ui/const-generics/parser-error-recovery/issue-89013-type.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 @@ | ||
trait Foo<const N: usize> { | ||
fn do_x(&self) -> [u8; N]; | ||
} | ||
|
||
struct Bar; | ||
|
||
const T: usize = 42; | ||
|
||
impl Foo<N = type 3> for Bar { | ||
//~^ERROR missing type to the right of `=` | ||
//~^^ERROR found keyword `type` | ||
fn do_x(&self) -> [u8; 3] { | ||
[0u8; 3] | ||
} | ||
} | ||
|
||
fn main() {} |
24 changes: 24 additions & 0 deletions
24
src/test/ui/const-generics/parser-error-recovery/issue-89013-type.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,24 @@ | ||
error: missing type to the right of `=` | ||
--> $DIR/issue-89013-type.rs:9:13 | ||
| | ||
LL | impl Foo<N = type 3> for Bar { | ||
| ^ | ||
| | ||
help: to constrain the associated type, add a type after `=` | ||
| | ||
LL | impl Foo<N = TheType type 3> for Bar { | ||
| +++++++ | ||
help: remove the `=` if `N` is a type | ||
| | ||
LL - impl Foo<N = type 3> for Bar { | ||
LL + impl Foo<N type 3> for Bar { | ||
| | ||
|
||
error: expected one of `,`, `>`, a const expression, lifetime, or type, found keyword `type` | ||
--> $DIR/issue-89013-type.rs:9:14 | ||
| | ||
LL | impl Foo<N = type 3> for Bar { | ||
| ^^^^ expected one of `,`, `>`, a const expression, lifetime, or type | ||
notriddle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
error: aborting due to 2 previous errors | ||
|
19 changes: 19 additions & 0 deletions
19
src/test/ui/const-generics/parser-error-recovery/issue-89013.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,19 @@ | ||
trait Foo<const N: usize> { | ||
fn do_x(&self) -> [u8; N]; | ||
} | ||
|
||
struct Bar; | ||
|
||
const T: usize = 42; | ||
|
||
impl Foo<N = const 3> for Bar { | ||
//~^ERROR expected lifetime, type, or constant, found keyword `const` | ||
//~^^ERROR cannot constrain an associated constant to a value | ||
//~^^^ERROR this trait takes 1 generic argument but 0 generic arguments | ||
//~^^^^ERROR associated type bindings are not allowed here | ||
notriddle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fn do_x(&self) -> [u8; 3] { | ||
[0u8; 3] | ||
} | ||
} | ||
|
||
fn main() {} |
41 changes: 41 additions & 0 deletions
41
src/test/ui/const-generics/parser-error-recovery/issue-89013.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,41 @@ | ||
error: expected lifetime, type, or constant, found keyword `const` | ||
--> $DIR/issue-89013.rs:9:14 | ||
| | ||
LL | impl Foo<N = const 3> for Bar { | ||
| ^^^^^ | ||
|
||
error: cannot constrain an associated constant to a value | ||
--> $DIR/issue-89013.rs:9:10 | ||
| | ||
LL | impl Foo<N = const 3> for Bar { | ||
| -^^^^^^^^^- | ||
| | | | ||
| | ...cannot be constrained to this value | ||
| this associated constant... | ||
|
||
error[E0107]: this trait takes 1 generic argument but 0 generic arguments were supplied | ||
--> $DIR/issue-89013.rs:9:6 | ||
| | ||
LL | impl Foo<N = const 3> for Bar { | ||
| ^^^ expected 1 generic argument | ||
| | ||
note: trait defined here, with 1 generic parameter: `N` | ||
--> $DIR/issue-89013.rs:1:7 | ||
| | ||
LL | trait Foo<const N: usize> { | ||
| ^^^ - | ||
help: add missing generic argument | ||
| | ||
LL | impl Foo<N, N = const 3> for Bar { | ||
| ++ | ||
|
||
error[E0229]: associated type bindings are not allowed here | ||
--> $DIR/issue-89013.rs:9:10 | ||
| | ||
LL | impl Foo<N = const 3> for Bar { | ||
| ^^^^^^^^^^^ associated type not allowed here | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
Some errors have detailed explanations: E0107, E0229. | ||
For more information about an 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.