-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18908 from jnyfah/error-braces
Fix: Detect missing errors for } braces before else in let...else statements
- Loading branch information
Showing
23 changed files
with
637 additions
and
12 deletions.
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
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
79 changes: 79 additions & 0 deletions
79
crates/parser/test_data/parser/err/0056_let_else_right_curly_brace_struct.rast
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,79 @@ | ||
SOURCE_FILE | ||
STRUCT | ||
STRUCT_KW "struct" | ||
WHITESPACE " " | ||
NAME | ||
IDENT "X" | ||
WHITESPACE " " | ||
RECORD_FIELD_LIST | ||
L_CURLY "{" | ||
RECORD_FIELD | ||
NAME | ||
IDENT "a" | ||
COLON ":" | ||
WHITESPACE " " | ||
PATH_TYPE | ||
PATH | ||
PATH_SEGMENT | ||
NAME_REF | ||
IDENT "i32" | ||
R_CURLY "}" | ||
WHITESPACE "\n" | ||
FN | ||
FN_KW "fn" | ||
WHITESPACE " " | ||
NAME | ||
IDENT "f" | ||
PARAM_LIST | ||
L_PAREN "(" | ||
R_PAREN ")" | ||
WHITESPACE " " | ||
BLOCK_EXPR | ||
STMT_LIST | ||
L_CURLY "{" | ||
WHITESPACE "\n " | ||
LET_STMT | ||
LET_KW "let" | ||
WHITESPACE " " | ||
IDENT_PAT | ||
NAME | ||
IDENT "foo" | ||
WHITESPACE " " | ||
EQ "=" | ||
WHITESPACE " " | ||
RECORD_EXPR | ||
PATH | ||
PATH_SEGMENT | ||
NAME_REF | ||
IDENT "X" | ||
WHITESPACE " " | ||
RECORD_EXPR_FIELD_LIST | ||
L_CURLY "{" | ||
WHITESPACE "\n " | ||
RECORD_EXPR_FIELD | ||
NAME_REF | ||
IDENT "a" | ||
COLON ":" | ||
WHITESPACE " " | ||
LITERAL | ||
INT_NUMBER "1" | ||
WHITESPACE "\n " | ||
R_CURLY "}" | ||
WHITESPACE " " | ||
LET_ELSE | ||
ELSE_KW "else" | ||
WHITESPACE " " | ||
BLOCK_EXPR | ||
STMT_LIST | ||
L_CURLY "{" | ||
WHITESPACE "\n " | ||
EXPR_STMT | ||
RETURN_EXPR | ||
RETURN_KW "return" | ||
SEMICOLON ";" | ||
WHITESPACE "\n " | ||
R_CURLY "}" | ||
SEMICOLON ";" | ||
WHITESPACE "\n" | ||
R_CURLY "}" | ||
error 63: right curly brace `}` before `else` in a `let...else` statement not allowed |
8 changes: 8 additions & 0 deletions
8
crates/parser/test_data/parser/err/0056_let_else_right_curly_brace_struct.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,8 @@ | ||
struct X {a: i32} | ||
fn f() { | ||
let foo = X { | ||
a: 1 | ||
} else { | ||
return; | ||
}; | ||
} |
42 changes: 42 additions & 0 deletions
42
crates/parser/test_data/parser/err/0057_let_else_right_curly_brace_arithmetic.rast
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,42 @@ | ||
SOURCE_FILE | ||
ERROR | ||
LET_KW "let" | ||
WHITESPACE " " | ||
IDENT_PAT | ||
NAME | ||
IDENT "foo" | ||
WHITESPACE " " | ||
EQ "=" | ||
WHITESPACE " " | ||
BIN_EXPR | ||
LITERAL | ||
INT_NUMBER "1" | ||
WHITESPACE " " | ||
PLUS "+" | ||
WHITESPACE " " | ||
BLOCK_EXPR | ||
STMT_LIST | ||
L_CURLY "{" | ||
WHITESPACE "\n " | ||
LITERAL | ||
INT_NUMBER "1" | ||
WHITESPACE "\n" | ||
R_CURLY "}" | ||
WHITESPACE " " | ||
LET_ELSE | ||
ELSE_KW "else" | ||
WHITESPACE " " | ||
BLOCK_EXPR | ||
STMT_LIST | ||
L_CURLY "{" | ||
WHITESPACE "\n " | ||
EXPR_STMT | ||
RETURN_EXPR | ||
RETURN_KW "return" | ||
SEMICOLON ";" | ||
WHITESPACE "\n" | ||
R_CURLY "}" | ||
SEMICOLON ";" | ||
WHITESPACE "\n" | ||
error 0: expected an item | ||
error 23: right curly brace `}` before `else` in a `let...else` statement not allowed |
5 changes: 5 additions & 0 deletions
5
crates/parser/test_data/parser/err/0057_let_else_right_curly_brace_arithmetic.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,5 @@ | ||
let foo = 1 + { | ||
1 | ||
} else { | ||
return; | ||
}; |
90 changes: 90 additions & 0 deletions
90
crates/parser/test_data/parser/err/0057_let_else_right_curly_brace_format_args.rast
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,90 @@ | ||
SOURCE_FILE | ||
FN | ||
FN_KW "fn" | ||
WHITESPACE " " | ||
NAME | ||
IDENT "r" | ||
PARAM_LIST | ||
L_PAREN "(" | ||
R_PAREN ")" | ||
WHITESPACE " " | ||
BLOCK_EXPR | ||
STMT_LIST | ||
L_CURLY "{" | ||
WHITESPACE "\n " | ||
LET_STMT | ||
LET_KW "let" | ||
WHITESPACE " " | ||
IDENT_PAT | ||
NAME | ||
IDENT "ok" | ||
WHITESPACE " " | ||
EQ "=" | ||
WHITESPACE " " | ||
MACRO_EXPR | ||
MACRO_CALL | ||
PATH | ||
PATH_SEGMENT | ||
NAME_REF | ||
IDENT "format_args" | ||
BANG "!" | ||
TOKEN_TREE | ||
L_PAREN "(" | ||
STRING "\"\"" | ||
R_PAREN ")" | ||
WHITESPACE " " | ||
LET_ELSE | ||
ELSE_KW "else" | ||
WHITESPACE " " | ||
BLOCK_EXPR | ||
STMT_LIST | ||
L_CURLY "{" | ||
WHITESPACE " " | ||
EXPR_STMT | ||
RETURN_EXPR | ||
RETURN_KW "return" | ||
SEMICOLON ";" | ||
WHITESPACE " " | ||
R_CURLY "}" | ||
SEMICOLON ";" | ||
WHITESPACE "\n\n " | ||
LET_STMT | ||
LET_KW "let" | ||
WHITESPACE " " | ||
IDENT_PAT | ||
NAME | ||
IDENT "bad" | ||
WHITESPACE " " | ||
EQ "=" | ||
WHITESPACE " " | ||
MACRO_EXPR | ||
MACRO_CALL | ||
PATH | ||
PATH_SEGMENT | ||
NAME_REF | ||
IDENT "format_args" | ||
BANG "!" | ||
WHITESPACE " " | ||
TOKEN_TREE | ||
L_CURLY "{" | ||
STRING "\"\"" | ||
R_CURLY "}" | ||
WHITESPACE " " | ||
LET_ELSE | ||
ELSE_KW "else" | ||
WHITESPACE " " | ||
BLOCK_EXPR | ||
STMT_LIST | ||
L_CURLY "{" | ||
WHITESPACE " " | ||
EXPR_STMT | ||
RETURN_EXPR | ||
RETURN_KW "return" | ||
SEMICOLON ";" | ||
WHITESPACE " " | ||
R_CURLY "}" | ||
SEMICOLON ";" | ||
WHITESPACE "\n" | ||
R_CURLY "}" | ||
WHITESPACE "\n" | ||
error 89: right curly brace `}` before `else` in a `let...else` statement not allowed |
5 changes: 5 additions & 0 deletions
5
crates/parser/test_data/parser/err/0057_let_else_right_curly_brace_format_args.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,5 @@ | ||
fn r() { | ||
let ok = format_args!("") else { return; }; | ||
|
||
let bad = format_args! {""} else { return; }; | ||
} |
40 changes: 40 additions & 0 deletions
40
crates/parser/test_data/parser/err/0058_let_else_right_curly_brace_range.rast
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,40 @@ | ||
SOURCE_FILE | ||
ERROR | ||
LET_KW "let" | ||
WHITESPACE " " | ||
IDENT_PAT | ||
NAME | ||
IDENT "foo" | ||
WHITESPACE " " | ||
EQ "=" | ||
WHITESPACE " " | ||
RANGE_EXPR | ||
LITERAL | ||
INT_NUMBER "1" | ||
DOT2 ".." | ||
BLOCK_EXPR | ||
STMT_LIST | ||
L_CURLY "{" | ||
WHITESPACE "\n " | ||
LITERAL | ||
INT_NUMBER "1" | ||
WHITESPACE "\n" | ||
R_CURLY "}" | ||
WHITESPACE " " | ||
LET_ELSE | ||
ELSE_KW "else" | ||
WHITESPACE " " | ||
BLOCK_EXPR | ||
STMT_LIST | ||
L_CURLY "{" | ||
WHITESPACE "\n " | ||
EXPR_STMT | ||
RETURN_EXPR | ||
RETURN_KW "return" | ||
SEMICOLON ";" | ||
WHITESPACE "\n" | ||
R_CURLY "}" | ||
SEMICOLON ";" | ||
WHITESPACE "\n" | ||
error 0: expected an item | ||
error 22: right curly brace `}` before `else` in a `let...else` statement not allowed |
5 changes: 5 additions & 0 deletions
5
crates/parser/test_data/parser/err/0058_let_else_right_curly_brace_range.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,5 @@ | ||
let foo = 1..{ | ||
1 | ||
} else { | ||
return; | ||
}; |
Oops, something went wrong.