aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-23 17:07:33 +0100
committerAleksey Kladov <[email protected]>2018-08-23 17:07:33 +0100
commita077533513de5018e227c740a470e18652b63172 (patch)
tree1b1d109942e916e441136d79b93cd00cd0463bbf /crates
parent8d82d1551ee09faa5d46a58c17c40c2515d3f3b9 (diff)
Allow arbitrary self-types
Diffstat (limited to 'crates')
-rw-r--r--crates/libsyntax2/src/grammar/params.rs39
-rw-r--r--crates/libsyntax2/tests/data/parser/inline/0058_type_arg.rs2
-rw-r--r--crates/libsyntax2/tests/data/parser/inline/0058_type_arg.txt8
-rw-r--r--crates/libsyntax2/tests/data/parser/inline/0104_arb_self_types.rs4
-rw-r--r--crates/libsyntax2/tests/data/parser/inline/0104_arb_self_types.txt69
5 files changed, 104 insertions, 18 deletions
diff --git a/crates/libsyntax2/src/grammar/params.rs b/crates/libsyntax2/src/grammar/params.rs
index 32e905cb2..7e58e8713 100644
--- a/crates/libsyntax2/src/grammar/params.rs
+++ b/crates/libsyntax2/src/grammar/params.rs
@@ -94,20 +94,33 @@ fn value_parameter(p: &mut Parser, flavor: Flavor) {
94// fn d(&'a mut self, x: i32) {} 94// fn d(&'a mut self, x: i32) {}
95// } 95// }
96fn self_param(p: &mut Parser) { 96fn self_param(p: &mut Parser) {
97 let la1 = p.nth(1); 97 let m;
98 let la2 = p.nth(2); 98 if p.at(SELF_KW) {
99 let la3 = p.nth(3); 99 m = p.start();
100 let n_toks = match (p.current(), la1, la2, la3) {
101 (SELF_KW, _, _, _) => 1,
102 (AMP, SELF_KW, _, _) => 2,
103 (AMP, MUT_KW, SELF_KW, _) => 3,
104 (AMP, LIFETIME, SELF_KW, _) => 3,
105 (AMP, LIFETIME, MUT_KW, SELF_KW) => 4,
106 _ => return,
107 };
108 let m = p.start();
109 for _ in 0..n_toks {
110 p.bump(); 100 p.bump();
101 // test arb_self_types
102 // impl S {
103 // fn a(self: &Self) {}
104 // fn b(self: Box<Self>) {}
105 // }
106 if p.at(COLON) {
107 types::ascription(p);
108 }
109 } else {
110 let la1 = p.nth(1);
111 let la2 = p.nth(2);
112 let la3 = p.nth(3);
113 let n_toks = match (p.current(), la1, la2, la3) {
114 (AMP, SELF_KW, _, _) => 2,
115 (AMP, MUT_KW, SELF_KW, _) => 3,
116 (AMP, LIFETIME, SELF_KW, _) => 3,
117 (AMP, LIFETIME, MUT_KW, SELF_KW) => 4,
118 _ => return,
119 };
120 m = p.start();
121 for _ in 0..n_toks {
122 p.bump();
123 }
111 } 124 }
112 m.complete(p, SELF_PARAM); 125 m.complete(p, SELF_PARAM);
113 if !p.at(R_PAREN) { 126 if !p.at(R_PAREN) {
diff --git a/crates/libsyntax2/tests/data/parser/inline/0058_type_arg.rs b/crates/libsyntax2/tests/data/parser/inline/0058_type_arg.rs
index 385c43131..f0c8cc3a8 100644
--- a/crates/libsyntax2/tests/data/parser/inline/0058_type_arg.rs
+++ b/crates/libsyntax2/tests/data/parser/inline/0058_type_arg.rs
@@ -1 +1 @@
type A = B<'static, i32, Item=u64>; type A = B<'static, i32, Item=u64>
diff --git a/crates/libsyntax2/tests/data/parser/inline/0058_type_arg.txt b/crates/libsyntax2/tests/data/parser/inline/0058_type_arg.txt
index 6fc29c03d..297456ec4 100644
--- a/crates/libsyntax2/tests/data/parser/inline/0058_type_arg.txt
+++ b/crates/libsyntax2/tests/data/parser/inline/0058_type_arg.txt
@@ -1,5 +1,5 @@
1FILE@[0; 36) 1FILE@[0; 35)
2 TYPE_DEF@[0; 35) 2 TYPE_DEF@[0; 34)
3 TYPE_KW@[0; 4) 3 TYPE_KW@[0; 4)
4 WHITESPACE@[4; 5) 4 WHITESPACE@[4; 5)
5 NAME@[5; 6) 5 NAME@[5; 6)
@@ -36,5 +36,5 @@ FILE@[0; 36)
36 NAME_REF@[30; 33) 36 NAME_REF@[30; 33)
37 IDENT@[30; 33) "u64" 37 IDENT@[30; 33) "u64"
38 R_ANGLE@[33; 34) 38 R_ANGLE@[33; 34)
39 SEMI@[34; 35) 39 err: `expected SEMI`
40 WHITESPACE@[35; 36) 40 WHITESPACE@[34; 35)
diff --git a/crates/libsyntax2/tests/data/parser/inline/0104_arb_self_types.rs b/crates/libsyntax2/tests/data/parser/inline/0104_arb_self_types.rs
new file mode 100644
index 000000000..2bf2a69f6
--- /dev/null
+++ b/crates/libsyntax2/tests/data/parser/inline/0104_arb_self_types.rs
@@ -0,0 +1,4 @@
1impl S {
2 fn a(self: &Self) {}
3 fn b(self: Box<Self>) {}
4}
diff --git a/crates/libsyntax2/tests/data/parser/inline/0104_arb_self_types.txt b/crates/libsyntax2/tests/data/parser/inline/0104_arb_self_types.txt
new file mode 100644
index 000000000..41e3505fe
--- /dev/null
+++ b/crates/libsyntax2/tests/data/parser/inline/0104_arb_self_types.txt
@@ -0,0 +1,69 @@
1FILE@[0; 65)
2 IMPL_ITEM@[0; 64)
3 IMPL_KW@[0; 4)
4 WHITESPACE@[4; 5)
5 PATH_TYPE@[5; 6)
6 PATH@[5; 6)
7 PATH_SEGMENT@[5; 6)
8 NAME_REF@[5; 6)
9 IDENT@[5; 6) "S"
10 WHITESPACE@[6; 7)
11 L_CURLY@[7; 8)
12 WHITESPACE@[8; 13)
13 FN_DEF@[13; 33)
14 FN_KW@[13; 15)
15 WHITESPACE@[15; 16)
16 NAME@[16; 17)
17 IDENT@[16; 17) "a"
18 PARAM_LIST@[17; 30)
19 L_PAREN@[17; 18)
20 SELF_PARAM@[18; 29)
21 SELF_KW@[18; 22)
22 COLON@[22; 23)
23 WHITESPACE@[23; 24)
24 REFERENCE_TYPE@[24; 29)
25 AMP@[24; 25)
26 PATH_TYPE@[25; 29)
27 PATH@[25; 29)
28 PATH_SEGMENT@[25; 29)
29 NAME_REF@[25; 29)
30 IDENT@[25; 29) "Self"
31 R_PAREN@[29; 30)
32 WHITESPACE@[30; 31)
33 BLOCK_EXPR@[31; 33)
34 L_CURLY@[31; 32)
35 R_CURLY@[32; 33)
36 WHITESPACE@[33; 38)
37 FN_DEF@[38; 62)
38 FN_KW@[38; 40)
39 WHITESPACE@[40; 41)
40 NAME@[41; 42)
41 IDENT@[41; 42) "b"
42 PARAM_LIST@[42; 59)
43 L_PAREN@[42; 43)
44 SELF_PARAM@[43; 58)
45 SELF_KW@[43; 47)
46 COLON@[47; 48)
47 WHITESPACE@[48; 49)
48 PATH_TYPE@[49; 58)
49 PATH@[49; 58)
50 PATH_SEGMENT@[49; 58)
51 NAME_REF@[49; 52)
52 IDENT@[49; 52) "Box"
53 TYPE_ARG_LIST@[52; 58)
54 L_ANGLE@[52; 53)
55 TYPE_ARG@[53; 57)
56 PATH_TYPE@[53; 57)
57 PATH@[53; 57)
58 PATH_SEGMENT@[53; 57)
59 NAME_REF@[53; 57)
60 IDENT@[53; 57) "Self"
61 R_ANGLE@[57; 58)
62 R_PAREN@[58; 59)
63 WHITESPACE@[59; 60)
64 BLOCK_EXPR@[60; 62)
65 L_CURLY@[60; 61)
66 R_CURLY@[61; 62)
67 WHITESPACE@[62; 63)
68 R_CURLY@[63; 64)
69 WHITESPACE@[64; 65)