aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/tests
diff options
context:
space:
mode:
authorRoland Ruckerbauer <[email protected]>2018-12-17 16:10:05 +0000
committerRoland Ruckerbauer <[email protected]>2018-12-17 16:26:24 +0000
commitd0f1334226fc25a8c00ecccd64c0021e4aef9ca5 (patch)
tree273bdffe892f2eeef1850e2d3f7b1ca9ed228285 /crates/ra_syntax/tests
parent8d42deeac354d1f8297d6c4d52b2707fb8d7a771 (diff)
Fixed cast expression parsing in ra_syntax.
The cast expression expected any type via types::type_() function, but the language spec does only allow TypeNoBounds (types without direct extra bounds via `+`). **Example:** ```rust fn test() { 6i8 as i32 + 5; } ``` This fails, because the types::type_() function which should parse the type after the as keyword is greedy, and takes all plus sign after path types as extra. My proposed fix is to replace the not implemented `type_no_plus()` just calls (`type_()`) function, which is used at several places. The replacement is `type_with_bounds_cond(p: &mut Parser, allow_bounds: bool)`, which passes the condition to relevant sub-parsers. This function is then called by `type_()` and the new public `type_no_bounds()`.
Diffstat (limited to 'crates/ra_syntax/tests')
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/0079_cast_expr.rs2
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/0079_cast_expr.txt52
2 files changed, 48 insertions, 6 deletions
diff --git a/crates/ra_syntax/tests/data/parser/inline/0079_cast_expr.rs b/crates/ra_syntax/tests/data/parser/inline/0079_cast_expr.rs
index 3e53d56d6..b571a5860 100644
--- a/crates/ra_syntax/tests/data/parser/inline/0079_cast_expr.rs
+++ b/crates/ra_syntax/tests/data/parser/inline/0079_cast_expr.rs
@@ -1,3 +1,5 @@
1fn foo() { 1fn foo() {
2 82 as i32; 2 82 as i32;
3 81 as i8 + 1;
4 79 as i16 - 1;
3} 5}
diff --git a/crates/ra_syntax/tests/data/parser/inline/0079_cast_expr.txt b/crates/ra_syntax/tests/data/parser/inline/0079_cast_expr.txt
index a80439913..cb56aef0b 100644
--- a/crates/ra_syntax/tests/data/parser/inline/0079_cast_expr.txt
+++ b/crates/ra_syntax/tests/data/parser/inline/0079_cast_expr.txt
@@ -1,5 +1,5 @@
1SOURCE_FILE@[0; 28) 1SOURCE_FILE@[0; 65)
2 FN_DEF@[0; 27) 2 FN_DEF@[0; 64)
3 FN_KW@[0; 2) 3 FN_KW@[0; 2)
4 WHITESPACE@[2; 3) 4 WHITESPACE@[2; 3)
5 NAME@[3; 6) 5 NAME@[3; 6)
@@ -8,7 +8,7 @@ SOURCE_FILE@[0; 28)
8 L_PAREN@[6; 7) 8 L_PAREN@[6; 7)
9 R_PAREN@[7; 8) 9 R_PAREN@[7; 8)
10 WHITESPACE@[8; 9) 10 WHITESPACE@[8; 9)
11 BLOCK@[9; 27) 11 BLOCK@[9; 64)
12 L_CURLY@[9; 10) 12 L_CURLY@[9; 10)
13 WHITESPACE@[10; 15) 13 WHITESPACE@[10; 15)
14 EXPR_STMT@[15; 25) 14 EXPR_STMT@[15; 25)
@@ -24,6 +24,46 @@ SOURCE_FILE@[0; 28)
24 NAME_REF@[21; 24) 24 NAME_REF@[21; 24)
25 IDENT@[21; 24) "i32" 25 IDENT@[21; 24) "i32"
26 SEMI@[24; 25) 26 SEMI@[24; 25)
27 WHITESPACE@[25; 26) 27 WHITESPACE@[25; 30)
28 R_CURLY@[26; 27) 28 EXPR_STMT@[30; 43)
29 WHITESPACE@[27; 28) 29 BIN_EXPR@[30; 42)
30 CAST_EXPR@[30; 38)
31 LITERAL@[30; 32)
32 INT_NUMBER@[30; 32) "81"
33 WHITESPACE@[32; 33)
34 AS_KW@[33; 35)
35 WHITESPACE@[35; 36)
36 PATH_TYPE@[36; 38)
37 PATH@[36; 38)
38 PATH_SEGMENT@[36; 38)
39 NAME_REF@[36; 38)
40 IDENT@[36; 38) "i8"
41 WHITESPACE@[38; 39)
42 PLUS@[39; 40)
43 WHITESPACE@[40; 41)
44 LITERAL@[41; 42)
45 INT_NUMBER@[41; 42) "1"
46 SEMI@[42; 43)
47 WHITESPACE@[43; 48)
48 EXPR_STMT@[48; 62)
49 BIN_EXPR@[48; 61)
50 CAST_EXPR@[48; 57)
51 LITERAL@[48; 50)
52 INT_NUMBER@[48; 50) "79"
53 WHITESPACE@[50; 51)
54 AS_KW@[51; 53)
55 WHITESPACE@[53; 54)
56 PATH_TYPE@[54; 57)
57 PATH@[54; 57)
58 PATH_SEGMENT@[54; 57)
59 NAME_REF@[54; 57)
60 IDENT@[54; 57) "i16"
61 WHITESPACE@[57; 58)
62 MINUS@[58; 59)
63 WHITESPACE@[59; 60)
64 LITERAL@[60; 61)
65 INT_NUMBER@[60; 61) "1"
66 SEMI@[61; 62)
67 WHITESPACE@[62; 63)
68 R_CURLY@[63; 64)
69 WHITESPACE@[64; 65)