diff options
5 files changed, 94 insertions, 13 deletions
diff --git a/crates/ra_syntax/src/grammar/items/traits.rs b/crates/ra_syntax/src/grammar/items/traits.rs index 62ab877fc..5dfdb470c 100644 --- a/crates/ra_syntax/src/grammar/items/traits.rs +++ b/crates/ra_syntax/src/grammar/items/traits.rs | |||
@@ -57,7 +57,7 @@ pub(super) fn impl_item(p: &mut Parser) { | |||
57 | p.eat(EXCL); | 57 | p.eat(EXCL); |
58 | impl_type(p); | 58 | impl_type(p); |
59 | if p.eat(FOR_KW) { | 59 | if p.eat(FOR_KW) { |
60 | types::type_(p); | 60 | impl_type(p); |
61 | } | 61 | } |
62 | type_params::opt_where_clause(p); | 62 | type_params::opt_where_clause(p); |
63 | if p.at(L_CURLY) { | 63 | if p.at(L_CURLY) { |
@@ -116,10 +116,11 @@ fn choose_type_params_over_qpath(p: &Parser) -> bool { | |||
116 | && (p.nth(2) == R_ANGLE || p.nth(2) == COMMA || p.nth(2) == COLON || p.nth(2) == EQ) | 116 | && (p.nth(2) == R_ANGLE || p.nth(2) == COMMA || p.nth(2) == COLON || p.nth(2) == EQ) |
117 | } | 117 | } |
118 | 118 | ||
119 | // test impl_type | ||
119 | // impl Type {} | 120 | // impl Type {} |
120 | // ^^^^ | 121 | // impl Trait1 for T {} |
121 | // impl Trait for T {} | 122 | // impl impl NotType {} |
122 | // ^^^^^ | 123 | // impl Trait2 for impl NotType {} |
123 | pub(crate) fn impl_type(p: &mut Parser) { | 124 | pub(crate) fn impl_type(p: &mut Parser) { |
124 | if p.at(IMPL_KW) { | 125 | if p.at(IMPL_KW) { |
125 | p.error("expected trait or type"); | 126 | p.error("expected trait or type"); |
@@ -128,4 +129,3 @@ pub(crate) fn impl_type(p: &mut Parser) { | |||
128 | types::type_(p); | 129 | types::type_(p); |
129 | } | 130 | } |
130 | 131 | ||
131 | |||
diff --git a/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.rs b/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.rs index eac922109..829ca1c4b 100644 --- a/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.rs +++ b/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.rs | |||
@@ -1,3 +1,2 @@ | |||
1 | impl<T: Clone> | 1 | impl<T: Clone> |
2 | impl<T> OnceCell<T> { | 2 | impl<T> OnceCell<T> {} |
3 | } | ||
diff --git a/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.txt b/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.txt index 60337d6de..9e26f58a0 100644 --- a/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.txt +++ b/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.txt | |||
@@ -1,4 +1,4 @@ | |||
1 | ROOT@[0; 39) | 1 | ROOT@[0; 38) |
2 | IMPL_ITEM@[0; 14) | 2 | IMPL_ITEM@[0; 14) |
3 | IMPL_KW@[0; 4) | 3 | IMPL_KW@[0; 4) |
4 | TYPE_PARAM_LIST@[4; 14) | 4 | TYPE_PARAM_LIST@[4; 14) |
@@ -17,7 +17,7 @@ ROOT@[0; 39) | |||
17 | err: `expected trait or type` | 17 | err: `expected trait or type` |
18 | err: `expected `{`` | 18 | err: `expected `{`` |
19 | WHITESPACE@[14; 15) | 19 | WHITESPACE@[14; 15) |
20 | IMPL_ITEM@[15; 38) | 20 | IMPL_ITEM@[15; 37) |
21 | IMPL_KW@[15; 19) | 21 | IMPL_KW@[15; 19) |
22 | TYPE_PARAM_LIST@[19; 22) | 22 | TYPE_PARAM_LIST@[19; 22) |
23 | L_ANGLE@[19; 20) | 23 | L_ANGLE@[19; 20) |
@@ -41,8 +41,7 @@ ROOT@[0; 39) | |||
41 | IDENT@[32; 33) "T" | 41 | IDENT@[32; 33) "T" |
42 | R_ANGLE@[33; 34) | 42 | R_ANGLE@[33; 34) |
43 | WHITESPACE@[34; 35) | 43 | WHITESPACE@[34; 35) |
44 | ITEM_LIST@[35; 38) | 44 | ITEM_LIST@[35; 37) |
45 | L_CURLY@[35; 36) | 45 | L_CURLY@[35; 36) |
46 | WHITESPACE@[36; 37) | 46 | R_CURLY@[36; 37) |
47 | R_CURLY@[37; 38) | 47 | WHITESPACE@[37; 38) |
48 | WHITESPACE@[38; 39) | ||
diff --git a/crates/ra_syntax/tests/data/parser/inline/0111_impl_type.rs b/crates/ra_syntax/tests/data/parser/inline/0111_impl_type.rs new file mode 100644 index 000000000..b8c7b65e3 --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/0111_impl_type.rs | |||
@@ -0,0 +1,4 @@ | |||
1 | impl Type {} | ||
2 | impl Trait1 for T {} | ||
3 | impl impl NotType {} | ||
4 | impl Trait2 for impl NotType {} | ||
diff --git a/crates/ra_syntax/tests/data/parser/inline/0111_impl_type.txt b/crates/ra_syntax/tests/data/parser/inline/0111_impl_type.txt new file mode 100644 index 000000000..a2907b060 --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/0111_impl_type.txt | |||
@@ -0,0 +1,79 @@ | |||
1 | ROOT@[0; 87) | ||
2 | IMPL_ITEM@[0; 12) | ||
3 | IMPL_KW@[0; 4) | ||
4 | WHITESPACE@[4; 5) | ||
5 | PATH_TYPE@[5; 9) | ||
6 | PATH@[5; 9) | ||
7 | PATH_SEGMENT@[5; 9) | ||
8 | NAME_REF@[5; 9) | ||
9 | IDENT@[5; 9) "Type" | ||
10 | WHITESPACE@[9; 10) | ||
11 | ITEM_LIST@[10; 12) | ||
12 | L_CURLY@[10; 11) | ||
13 | R_CURLY@[11; 12) | ||
14 | WHITESPACE@[12; 13) | ||
15 | IMPL_ITEM@[13; 33) | ||
16 | IMPL_KW@[13; 17) | ||
17 | WHITESPACE@[17; 18) | ||
18 | PATH_TYPE@[18; 24) | ||
19 | PATH@[18; 24) | ||
20 | PATH_SEGMENT@[18; 24) | ||
21 | NAME_REF@[18; 24) | ||
22 | IDENT@[18; 24) "Trait1" | ||
23 | WHITESPACE@[24; 25) | ||
24 | FOR_KW@[25; 28) | ||
25 | WHITESPACE@[28; 29) | ||
26 | PATH_TYPE@[29; 30) | ||
27 | PATH@[29; 30) | ||
28 | PATH_SEGMENT@[29; 30) | ||
29 | NAME_REF@[29; 30) | ||
30 | IDENT@[29; 30) "T" | ||
31 | WHITESPACE@[30; 31) | ||
32 | ITEM_LIST@[31; 33) | ||
33 | L_CURLY@[31; 32) | ||
34 | R_CURLY@[32; 33) | ||
35 | WHITESPACE@[33; 34) | ||
36 | IMPL_ITEM@[34; 38) | ||
37 | IMPL_KW@[34; 38) | ||
38 | err: `expected trait or type` | ||
39 | err: `expected `{`` | ||
40 | WHITESPACE@[38; 39) | ||
41 | IMPL_ITEM@[39; 54) | ||
42 | IMPL_KW@[39; 43) | ||
43 | WHITESPACE@[43; 44) | ||
44 | PATH_TYPE@[44; 51) | ||
45 | PATH@[44; 51) | ||
46 | PATH_SEGMENT@[44; 51) | ||
47 | NAME_REF@[44; 51) | ||
48 | IDENT@[44; 51) "NotType" | ||
49 | WHITESPACE@[51; 52) | ||
50 | ITEM_LIST@[52; 54) | ||
51 | L_CURLY@[52; 53) | ||
52 | R_CURLY@[53; 54) | ||
53 | WHITESPACE@[54; 55) | ||
54 | IMPL_ITEM@[55; 70) | ||
55 | IMPL_KW@[55; 59) | ||
56 | WHITESPACE@[59; 60) | ||
57 | PATH_TYPE@[60; 66) | ||
58 | PATH@[60; 66) | ||
59 | PATH_SEGMENT@[60; 66) | ||
60 | NAME_REF@[60; 66) | ||
61 | IDENT@[60; 66) "Trait2" | ||
62 | WHITESPACE@[66; 67) | ||
63 | FOR_KW@[67; 70) | ||
64 | err: `expected trait or type` | ||
65 | err: `expected `{`` | ||
66 | WHITESPACE@[70; 71) | ||
67 | IMPL_ITEM@[71; 86) | ||
68 | IMPL_KW@[71; 75) | ||
69 | WHITESPACE@[75; 76) | ||
70 | PATH_TYPE@[76; 83) | ||
71 | PATH@[76; 83) | ||
72 | PATH_SEGMENT@[76; 83) | ||
73 | NAME_REF@[76; 83) | ||
74 | IDENT@[76; 83) "NotType" | ||
75 | WHITESPACE@[83; 84) | ||
76 | ITEM_LIST@[84; 86) | ||
77 | L_CURLY@[84; 85) | ||
78 | R_CURLY@[85; 86) | ||
79 | WHITESPACE@[86; 87) | ||