Rollup merge of #109203 - Ezrashaw:refactor-ident-parsing, r=Nilstrieb
refactor/feat: refactor identifier parsing a bit \+ error recovery for `expected_ident_found` Prior art: #108854
This commit is contained in:
commit
34fa6daa5c
12 changed files with 256 additions and 101 deletions
16
tests/ui/parser/ident-recovery.rs
Normal file
16
tests/ui/parser/ident-recovery.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
fn ,comma() {
|
||||
//~^ ERROR expected identifier, found `,`
|
||||
struct Foo {
|
||||
x: i32,,
|
||||
//~^ ERROR expected identifier, found `,`
|
||||
y: u32,
|
||||
}
|
||||
}
|
||||
|
||||
fn break() {
|
||||
//~^ ERROR expected identifier, found keyword `break`
|
||||
let continue = 5;
|
||||
//~^ ERROR expected identifier, found keyword `continue`
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
42
tests/ui/parser/ident-recovery.stderr
Normal file
42
tests/ui/parser/ident-recovery.stderr
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
error: expected identifier, found `,`
|
||||
--> $DIR/ident-recovery.rs:1:4
|
||||
|
|
||||
LL | fn ,comma() {
|
||||
| ^
|
||||
| |
|
||||
| expected identifier
|
||||
| help: remove this comma
|
||||
|
||||
error: expected identifier, found `,`
|
||||
--> $DIR/ident-recovery.rs:4:16
|
||||
|
|
||||
LL | x: i32,,
|
||||
| ^
|
||||
| |
|
||||
| expected identifier
|
||||
| help: remove this comma
|
||||
|
||||
error: expected identifier, found keyword `break`
|
||||
--> $DIR/ident-recovery.rs:10:4
|
||||
|
|
||||
LL | fn break() {
|
||||
| ^^^^^ expected identifier, found keyword
|
||||
|
|
||||
help: escape `break` to use it as an identifier
|
||||
|
|
||||
LL | fn r#break() {
|
||||
| ++
|
||||
|
||||
error: expected identifier, found keyword `continue`
|
||||
--> $DIR/ident-recovery.rs:12:9
|
||||
|
|
||||
LL | let continue = 5;
|
||||
| ^^^^^^^^ expected identifier, found keyword
|
||||
|
|
||||
help: escape `continue` to use it as an identifier
|
||||
|
|
||||
LL | let r#continue = 5;
|
||||
| ++
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
@ -4,7 +4,11 @@ error: expected identifier, found `1main`
|
|||
LL | fn 1main() {}
|
||||
| ^^^^^ expected identifier
|
||||
|
|
||||
= help: identifiers cannot start with a number
|
||||
help: identifiers cannot start with a number
|
||||
--> $DIR/integer-literal-start-ident.rs:1:4
|
||||
|
|
||||
LL | fn 1main() {}
|
||||
| ^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -1,26 +1,19 @@
|
|||
fn test() {
|
||||
fn 1234test() {
|
||||
//~^ ERROR expected identifier, found `1234test`
|
||||
if let 123 = 123 { println!("yes"); }
|
||||
}
|
||||
|
||||
fn test_2() {
|
||||
if let 2e1 = 123 {
|
||||
//~^ ERROR mismatched types
|
||||
}
|
||||
|
||||
let 23name = 123;
|
||||
//~^ ERROR expected identifier, found `23name`
|
||||
|
||||
let 2x: i32 = 123;
|
||||
//~^ ERROR expected identifier, found `2x`
|
||||
|
||||
let 1x = 123;
|
||||
//~^ ERROR expected identifier, found `1x`
|
||||
}
|
||||
|
||||
fn test_3() {
|
||||
let 2x: i32 = 123;
|
||||
//~^ ERROR expected identifier, found `2x`
|
||||
}
|
||||
|
||||
fn test_4() {
|
||||
if let 2e1 = 123 {
|
||||
//~^ ERROR mismatched types
|
||||
}
|
||||
}
|
||||
|
||||
fn test_5() {
|
||||
let 23name = 123;
|
||||
//~^ ERROR expected identifier, found `23name`
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,35 +1,59 @@
|
|||
error: expected identifier, found `1x`
|
||||
--> $DIR/issue-104088.rs:6:9
|
||||
error: expected identifier, found `1234test`
|
||||
--> $DIR/issue-104088.rs:1:4
|
||||
|
|
||||
LL | let 1x = 123;
|
||||
| ^^ expected identifier
|
||||
LL | fn 1234test() {
|
||||
| ^^^^^^^^ expected identifier
|
||||
|
|
||||
= help: identifiers cannot start with a number
|
||||
|
||||
error: expected identifier, found `2x`
|
||||
--> $DIR/issue-104088.rs:11:9
|
||||
help: identifiers cannot start with a number
|
||||
--> $DIR/issue-104088.rs:1:4
|
||||
|
|
||||
LL | let 2x: i32 = 123;
|
||||
| ^^ expected identifier
|
||||
|
|
||||
= help: identifiers cannot start with a number
|
||||
LL | fn 1234test() {
|
||||
| ^^^^
|
||||
|
||||
error: expected identifier, found `23name`
|
||||
--> $DIR/issue-104088.rs:22:9
|
||||
--> $DIR/issue-104088.rs:9:9
|
||||
|
|
||||
LL | let 23name = 123;
|
||||
| ^^^^^^ expected identifier
|
||||
|
|
||||
= help: identifiers cannot start with a number
|
||||
help: identifiers cannot start with a number
|
||||
--> $DIR/issue-104088.rs:9:9
|
||||
|
|
||||
LL | let 23name = 123;
|
||||
| ^^
|
||||
|
||||
error: expected identifier, found `2x`
|
||||
--> $DIR/issue-104088.rs:12:9
|
||||
|
|
||||
LL | let 2x: i32 = 123;
|
||||
| ^^ expected identifier
|
||||
|
|
||||
help: identifiers cannot start with a number
|
||||
--> $DIR/issue-104088.rs:12:9
|
||||
|
|
||||
LL | let 2x: i32 = 123;
|
||||
| ^
|
||||
|
||||
error: expected identifier, found `1x`
|
||||
--> $DIR/issue-104088.rs:15:9
|
||||
|
|
||||
LL | let 1x = 123;
|
||||
| ^^ expected identifier
|
||||
|
|
||||
help: identifiers cannot start with a number
|
||||
--> $DIR/issue-104088.rs:15:9
|
||||
|
|
||||
LL | let 1x = 123;
|
||||
| ^
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-104088.rs:16:12
|
||||
--> $DIR/issue-104088.rs:5:12
|
||||
|
|
||||
LL | if let 2e1 = 123 {
|
||||
| ^^^ --- this expression has type `{integer}`
|
||||
| |
|
||||
| expected integer, found floating-point number
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue