aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-09-26 21:14:28 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-09-26 21:14:28 +0100
commit5e1d109cbb73a66c8bd3282973b8ebeb74894e4e (patch)
treede3bf059782d721efd76b0691020213858784099 /crates/ra_syntax
parent7eb047a105ee42b5dbd8f5cf7d956ca7bdfd551a (diff)
parent8b710e95353d9f840f78645c9593a66adb0636b6 (diff)
Merge #81
81: [WIP] Reject impl keyword inside impl header r=matklad a=csmoe Closes #77 Co-authored-by: csmoe <[email protected]>
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/grammar/items/traits.rs18
-rw-r--r--crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.rs2
-rw-r--r--crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.txt47
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/0111_impl_type.rs4
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/0111_impl_type.txt79
5 files changed, 148 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/grammar/items/traits.rs b/crates/ra_syntax/src/grammar/items/traits.rs
index c21cfb1a9..5dfdb470c 100644
--- a/crates/ra_syntax/src/grammar/items/traits.rs
+++ b/crates/ra_syntax/src/grammar/items/traits.rs
@@ -55,9 +55,9 @@ pub(super) fn impl_item(p: &mut Parser) {
55 // test impl_item_neg 55 // test impl_item_neg
56 // impl !Send for X {} 56 // impl !Send for X {}
57 p.eat(EXCL); 57 p.eat(EXCL);
58 types::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) {
@@ -115,3 +115,17 @@ fn choose_type_params_over_qpath(p: &Parser) -> bool {
115 (p.nth(1) == LIFETIME || p.nth(1) == IDENT) 115 (p.nth(1) == LIFETIME || p.nth(1) == IDENT)
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
119// test impl_type
120// impl Type {}
121// impl Trait1 for T {}
122// impl impl NotType {}
123// impl Trait2 for impl NotType {}
124pub(crate) fn impl_type(p: &mut Parser) {
125 if p.at(IMPL_KW) {
126 p.error("expected trait or type");
127 return;
128 }
129 types::type_(p);
130}
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
new file mode 100644
index 000000000..829ca1c4b
--- /dev/null
+++ b/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.rs
@@ -0,0 +1,2 @@
1impl<T: Clone>
2impl<T> OnceCell<T> {}
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
new file mode 100644
index 000000000..9e26f58a0
--- /dev/null
+++ b/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.txt
@@ -0,0 +1,47 @@
1ROOT@[0; 38)
2 IMPL_ITEM@[0; 14)
3 IMPL_KW@[0; 4)
4 TYPE_PARAM_LIST@[4; 14)
5 L_ANGLE@[4; 5)
6 TYPE_PARAM@[5; 13)
7 NAME@[5; 6)
8 IDENT@[5; 6) "T"
9 COLON@[6; 7)
10 WHITESPACE@[7; 8)
11 PATH_TYPE@[8; 13)
12 PATH@[8; 13)
13 PATH_SEGMENT@[8; 13)
14 NAME_REF@[8; 13)
15 IDENT@[8; 13) "Clone"
16 R_ANGLE@[13; 14)
17 err: `expected trait or type`
18 err: `expected `{``
19 WHITESPACE@[14; 15)
20 IMPL_ITEM@[15; 37)
21 IMPL_KW@[15; 19)
22 TYPE_PARAM_LIST@[19; 22)
23 L_ANGLE@[19; 20)
24 TYPE_PARAM@[20; 21)
25 NAME@[20; 21)
26 IDENT@[20; 21) "T"
27 R_ANGLE@[21; 22)
28 WHITESPACE@[22; 23)
29 PATH_TYPE@[23; 34)
30 PATH@[23; 34)
31 PATH_SEGMENT@[23; 34)
32 NAME_REF@[23; 31)
33 IDENT@[23; 31) "OnceCell"
34 TYPE_ARG_LIST@[31; 34)
35 L_ANGLE@[31; 32)
36 TYPE_ARG@[32; 33)
37 PATH_TYPE@[32; 33)
38 PATH@[32; 33)
39 PATH_SEGMENT@[32; 33)
40 NAME_REF@[32; 33)
41 IDENT@[32; 33) "T"
42 R_ANGLE@[33; 34)
43 WHITESPACE@[34; 35)
44 ITEM_LIST@[35; 37)
45 L_CURLY@[35; 36)
46 R_CURLY@[36; 37)
47 WHITESPACE@[37; 38)
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 @@
1impl Type {}
2impl Trait1 for T {}
3impl impl NotType {}
4impl 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 @@
1ROOT@[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)