From 205a8278a9da4bc1289449b916468e972fb624fc Mon Sep 17 00:00:00 2001 From: csmoe Date: Fri, 7 Jun 2019 19:49:49 +0800 Subject: [PATCH] fix: never type with binding Change-Id: I14e1bc628b9d2dfdb1f40de3d3707f4e872767f2 --- crates/ra_parser/src/grammar/expressions.rs | 4 +- crates/ra_parser/src/parser.rs | 2 +- .../{0049_let_stmt;.rs => 0130_let_stmt.rs} | 2 + .../{0049_let_stmt;.txt => 0130_let_stmt.txt} | 42 ++++++++++++++++--- 4 files changed, 42 insertions(+), 8 deletions(-) rename crates/ra_syntax/tests/data/parser/inline/ok/{0049_let_stmt;.rs => 0130_let_stmt.rs} (70%) rename crates/ra_syntax/tests/data/parser/inline/ok/{0049_let_stmt;.txt => 0130_let_stmt.txt} (63%) diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index 99e32c4e82..795dccea15 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs @@ -137,12 +137,14 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi) { m.complete(p, EXPR_STMT); } - // test let_stmt; + // test let_stmt // fn foo() { // let a; // let b: i32; // let c = 92; // let d: i32 = 92; + // let e: !; + // let _: ! = {}; // } fn let_stmt(p: &mut Parser, m: Marker, with_semi: StmtWithSemi) { assert!(p.at(T![let])); diff --git a/crates/ra_parser/src/parser.rs b/crates/ra_parser/src/parser.rs index 8f654f04c0..8a2e253ac9 100644 --- a/crates/ra_parser/src/parser.rs +++ b/crates/ra_parser/src/parser.rs @@ -272,7 +272,7 @@ impl<'t> Parser<'t> { T![=] if jn1 && la2 == T![=] => Some((T![==], 2)), T![=] if jn1 && la2 == T![>] => Some((T![=>], 2)), - T![!] if la2 == T![=] => Some((T![!=], 2)), + T![!] if jn1 && la2 == T![=] => Some((T![!=], 2)), T![-] if la2 == T![>] => Some((T![->], 2)), _ => None, } diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0049_let_stmt;.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0130_let_stmt.rs similarity index 70% rename from crates/ra_syntax/tests/data/parser/inline/ok/0049_let_stmt;.rs rename to crates/ra_syntax/tests/data/parser/inline/ok/0130_let_stmt.rs index 0a9af907f5..86803fe08a 100644 --- a/crates/ra_syntax/tests/data/parser/inline/ok/0049_let_stmt;.rs +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0130_let_stmt.rs @@ -3,4 +3,6 @@ fn foo() { let b: i32; let c = 92; let d: i32 = 92; + let e: !; + let _: ! = {}; } diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0049_let_stmt;.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0130_let_stmt.txt similarity index 63% rename from crates/ra_syntax/tests/data/parser/inline/ok/0049_let_stmt;.txt rename to crates/ra_syntax/tests/data/parser/inline/ok/0130_let_stmt.txt index 1f7aa35873..82c1eb009b 100644 --- a/crates/ra_syntax/tests/data/parser/inline/ok/0049_let_stmt;.txt +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0130_let_stmt.txt @@ -1,5 +1,5 @@ -SOURCE_FILE@[0; 77) - FN_DEF@[0; 76) +SOURCE_FILE@[0; 110) + FN_DEF@[0; 109) FN_KW@[0; 2) "fn" WHITESPACE@[2; 3) " " NAME@[3; 6) @@ -8,7 +8,7 @@ SOURCE_FILE@[0; 77) L_PAREN@[6; 7) "(" R_PAREN@[7; 8) ")" WHITESPACE@[8; 9) " " - BLOCK@[9; 76) + BLOCK@[9; 109) L_CURLY@[9; 10) "{" WHITESPACE@[10; 15) "\n " LET_STMT@[15; 21) @@ -66,6 +66,36 @@ SOURCE_FILE@[0; 77) LITERAL@[71; 73) INT_NUMBER@[71; 73) "92" SEMI@[73; 74) ";" - WHITESPACE@[74; 75) "\n" - R_CURLY@[75; 76) "}" - WHITESPACE@[76; 77) "\n" + WHITESPACE@[74; 79) "\n " + LET_STMT@[79; 88) + LET_KW@[79; 82) "let" + WHITESPACE@[82; 83) " " + BIND_PAT@[83; 84) + NAME@[83; 84) + IDENT@[83; 84) "e" + COLON@[84; 85) ":" + WHITESPACE@[85; 86) " " + NEVER_TYPE@[86; 87) + EXCL@[86; 87) "!" + SEMI@[87; 88) ";" + WHITESPACE@[88; 93) "\n " + LET_STMT@[93; 107) + LET_KW@[93; 96) "let" + WHITESPACE@[96; 97) " " + PLACEHOLDER_PAT@[97; 98) + UNDERSCORE@[97; 98) "_" + COLON@[98; 99) ":" + WHITESPACE@[99; 100) " " + NEVER_TYPE@[100; 101) + EXCL@[100; 101) "!" + WHITESPACE@[101; 102) " " + EQ@[102; 103) "=" + WHITESPACE@[103; 104) " " + BLOCK_EXPR@[104; 106) + BLOCK@[104; 106) + L_CURLY@[104; 105) "{" + R_CURLY@[105; 106) "}" + SEMI@[106; 107) ";" + WHITESPACE@[107; 108) "\n" + R_CURLY@[108; 109) "}" + WHITESPACE@[109; 110) "\n"