From d0f1334226fc25a8c00ecccd64c0021e4aef9ca5 Mon Sep 17 00:00:00 2001 From: Roland Ruckerbauer Date: Mon, 17 Dec 2018 17:10:05 +0100 Subject: 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()`. --- .../tests/data/parser/inline/0079_cast_expr.rs | 2 + .../tests/data/parser/inline/0079_cast_expr.txt | 52 +++++++++++++++++++--- 2 files changed, 48 insertions(+), 6 deletions(-) (limited to 'crates/ra_syntax/tests/data/parser/inline') 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 @@ fn foo() { 82 as i32; + 81 as i8 + 1; + 79 as i16 - 1; } 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 @@ -SOURCE_FILE@[0; 28) - FN_DEF@[0; 27) +SOURCE_FILE@[0; 65) + FN_DEF@[0; 64) FN_KW@[0; 2) WHITESPACE@[2; 3) NAME@[3; 6) @@ -8,7 +8,7 @@ SOURCE_FILE@[0; 28) L_PAREN@[6; 7) R_PAREN@[7; 8) WHITESPACE@[8; 9) - BLOCK@[9; 27) + BLOCK@[9; 64) L_CURLY@[9; 10) WHITESPACE@[10; 15) EXPR_STMT@[15; 25) @@ -24,6 +24,46 @@ SOURCE_FILE@[0; 28) NAME_REF@[21; 24) IDENT@[21; 24) "i32" SEMI@[24; 25) - WHITESPACE@[25; 26) - R_CURLY@[26; 27) - WHITESPACE@[27; 28) + WHITESPACE@[25; 30) + EXPR_STMT@[30; 43) + BIN_EXPR@[30; 42) + CAST_EXPR@[30; 38) + LITERAL@[30; 32) + INT_NUMBER@[30; 32) "81" + WHITESPACE@[32; 33) + AS_KW@[33; 35) + WHITESPACE@[35; 36) + PATH_TYPE@[36; 38) + PATH@[36; 38) + PATH_SEGMENT@[36; 38) + NAME_REF@[36; 38) + IDENT@[36; 38) "i8" + WHITESPACE@[38; 39) + PLUS@[39; 40) + WHITESPACE@[40; 41) + LITERAL@[41; 42) + INT_NUMBER@[41; 42) "1" + SEMI@[42; 43) + WHITESPACE@[43; 48) + EXPR_STMT@[48; 62) + BIN_EXPR@[48; 61) + CAST_EXPR@[48; 57) + LITERAL@[48; 50) + INT_NUMBER@[48; 50) "79" + WHITESPACE@[50; 51) + AS_KW@[51; 53) + WHITESPACE@[53; 54) + PATH_TYPE@[54; 57) + PATH@[54; 57) + PATH_SEGMENT@[54; 57) + NAME_REF@[54; 57) + IDENT@[54; 57) "i16" + WHITESPACE@[57; 58) + MINUS@[58; 59) + WHITESPACE@[59; 60) + LITERAL@[60; 61) + INT_NUMBER@[60; 61) "1" + SEMI@[61; 62) + WHITESPACE@[62; 63) + R_CURLY@[63; 64) + WHITESPACE@[64; 65) -- cgit v1.2.3