-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1951: Lower the precedence of the `as` operator. r=matklad a=goffrie Previously, the `as` operator was being parsed like a postfix expression, and therefore being given the highest possible precedence. That caused it to bind more tightly than prefix operators, which it should not. Instead, parse it somewhat like a normal binary expression with some special-casing. Fixes #1851. Co-authored-by: Geoffry Song <goffrie@gmail.com>
- Loading branch information
Showing
5 changed files
with
160 additions
and
1 deletion.
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
3 changes: 3 additions & 0 deletions
3
crates/ra_syntax/test_data/parser/inline/ok/0146_as_precedence.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,3 @@ | ||
fn foo() { | ||
let _ = &1 as *const i32; | ||
} |
43 changes: 43 additions & 0 deletions
43
crates/ra_syntax/test_data/parser/inline/ok/0146_as_precedence.txt
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,43 @@ | ||
SOURCE_FILE@[0; 43) | ||
FN_DEF@[0; 42) | ||
FN_KW@[0; 2) "fn" | ||
WHITESPACE@[2; 3) " " | ||
NAME@[3; 6) | ||
IDENT@[3; 6) "foo" | ||
PARAM_LIST@[6; 8) | ||
L_PAREN@[6; 7) "(" | ||
R_PAREN@[7; 8) ")" | ||
WHITESPACE@[8; 9) " " | ||
BLOCK_EXPR@[9; 42) | ||
BLOCK@[9; 42) | ||
L_CURLY@[9; 10) "{" | ||
WHITESPACE@[10; 15) "\n " | ||
LET_STMT@[15; 40) | ||
LET_KW@[15; 18) "let" | ||
WHITESPACE@[18; 19) " " | ||
PLACEHOLDER_PAT@[19; 20) | ||
UNDERSCORE@[19; 20) "_" | ||
WHITESPACE@[20; 21) " " | ||
EQ@[21; 22) "=" | ||
WHITESPACE@[22; 23) " " | ||
CAST_EXPR@[23; 39) | ||
REF_EXPR@[23; 25) | ||
AMP@[23; 24) "&" | ||
LITERAL@[24; 25) | ||
INT_NUMBER@[24; 25) "1" | ||
WHITESPACE@[25; 26) " " | ||
AS_KW@[26; 28) "as" | ||
WHITESPACE@[28; 29) " " | ||
POINTER_TYPE@[29; 39) | ||
STAR@[29; 30) "*" | ||
CONST_KW@[30; 35) "const" | ||
WHITESPACE@[35; 36) " " | ||
PATH_TYPE@[36; 39) | ||
PATH@[36; 39) | ||
PATH_SEGMENT@[36; 39) | ||
NAME_REF@[36; 39) | ||
IDENT@[36; 39) "i32" | ||
SEMI@[39; 40) ";" | ||
WHITESPACE@[40; 41) "\n" | ||
R_CURLY@[41; 42) "}" | ||
WHITESPACE@[42; 43) "\n" |
7 changes: 7 additions & 0 deletions
7
crates/ra_syntax/test_data/parser/ok/0058_unary_expr_precedence.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,7 @@ | ||
fn foo() { | ||
1 + *&2 + 3; | ||
*&1 as u64; | ||
*x(1); | ||
&x[1]; | ||
-1..2; | ||
} |
97 changes: 97 additions & 0 deletions
97
crates/ra_syntax/test_data/parser/ok/0058_unary_expr_precedence.txt
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,97 @@ | ||
SOURCE_FILE@[0; 79) | ||
FN_DEF@[0; 78) | ||
FN_KW@[0; 2) "fn" | ||
WHITESPACE@[2; 3) " " | ||
NAME@[3; 6) | ||
IDENT@[3; 6) "foo" | ||
PARAM_LIST@[6; 8) | ||
L_PAREN@[6; 7) "(" | ||
R_PAREN@[7; 8) ")" | ||
WHITESPACE@[8; 9) " " | ||
BLOCK_EXPR@[9; 78) | ||
BLOCK@[9; 78) | ||
L_CURLY@[9; 10) "{" | ||
WHITESPACE@[10; 15) "\n " | ||
EXPR_STMT@[15; 27) | ||
BIN_EXPR@[15; 26) | ||
BIN_EXPR@[15; 22) | ||
LITERAL@[15; 16) | ||
INT_NUMBER@[15; 16) "1" | ||
WHITESPACE@[16; 17) " " | ||
PLUS@[17; 18) "+" | ||
WHITESPACE@[18; 19) " " | ||
PREFIX_EXPR@[19; 22) | ||
STAR@[19; 20) "*" | ||
REF_EXPR@[20; 22) | ||
AMP@[20; 21) "&" | ||
LITERAL@[21; 22) | ||
INT_NUMBER@[21; 22) "2" | ||
WHITESPACE@[22; 23) " " | ||
PLUS@[23; 24) "+" | ||
WHITESPACE@[24; 25) " " | ||
LITERAL@[25; 26) | ||
INT_NUMBER@[25; 26) "3" | ||
SEMI@[26; 27) ";" | ||
WHITESPACE@[27; 32) "\n " | ||
EXPR_STMT@[32; 43) | ||
CAST_EXPR@[32; 42) | ||
PREFIX_EXPR@[32; 35) | ||
STAR@[32; 33) "*" | ||
REF_EXPR@[33; 35) | ||
AMP@[33; 34) "&" | ||
LITERAL@[34; 35) | ||
INT_NUMBER@[34; 35) "1" | ||
WHITESPACE@[35; 36) " " | ||
AS_KW@[36; 38) "as" | ||
WHITESPACE@[38; 39) " " | ||
PATH_TYPE@[39; 42) | ||
PATH@[39; 42) | ||
PATH_SEGMENT@[39; 42) | ||
NAME_REF@[39; 42) | ||
IDENT@[39; 42) "u64" | ||
SEMI@[42; 43) ";" | ||
WHITESPACE@[43; 48) "\n " | ||
EXPR_STMT@[48; 54) | ||
PREFIX_EXPR@[48; 53) | ||
STAR@[48; 49) "*" | ||
CALL_EXPR@[49; 53) | ||
PATH_EXPR@[49; 50) | ||
PATH@[49; 50) | ||
PATH_SEGMENT@[49; 50) | ||
NAME_REF@[49; 50) | ||
IDENT@[49; 50) "x" | ||
ARG_LIST@[50; 53) | ||
L_PAREN@[50; 51) "(" | ||
LITERAL@[51; 52) | ||
INT_NUMBER@[51; 52) "1" | ||
R_PAREN@[52; 53) ")" | ||
SEMI@[53; 54) ";" | ||
WHITESPACE@[54; 59) "\n " | ||
EXPR_STMT@[59; 65) | ||
REF_EXPR@[59; 64) | ||
AMP@[59; 60) "&" | ||
INDEX_EXPR@[60; 64) | ||
PATH_EXPR@[60; 61) | ||
PATH@[60; 61) | ||
PATH_SEGMENT@[60; 61) | ||
NAME_REF@[60; 61) | ||
IDENT@[60; 61) "x" | ||
L_BRACK@[61; 62) "[" | ||
LITERAL@[62; 63) | ||
INT_NUMBER@[62; 63) "1" | ||
R_BRACK@[63; 64) "]" | ||
SEMI@[64; 65) ";" | ||
WHITESPACE@[65; 70) "\n " | ||
EXPR_STMT@[70; 76) | ||
RANGE_EXPR@[70; 75) | ||
PREFIX_EXPR@[70; 72) | ||
MINUS@[70; 71) "-" | ||
LITERAL@[71; 72) | ||
INT_NUMBER@[71; 72) "1" | ||
DOTDOT@[72; 74) ".." | ||
LITERAL@[74; 75) | ||
INT_NUMBER@[74; 75) "2" | ||
SEMI@[75; 76) ";" | ||
WHITESPACE@[76; 77) "\n" | ||
R_CURLY@[77; 78) "}" | ||
WHITESPACE@[78; 79) "\n" |