diff options
author | Aleksey Kladov <[email protected]> | 2018-08-23 23:19:38 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-23 23:19:38 +0100 |
commit | dc40f1298a8d4dcb7a26d5af38c4fb7ef3d6c5df (patch) | |
tree | 618354b471933003577ff2a5616c27bd272f62f3 /crates | |
parent | cf7d4a2a243cac1975b9b28d47ed91a6bd01b34f (diff) |
better self-types
Diffstat (limited to 'crates')
8 files changed, 67 insertions, 45 deletions
diff --git a/crates/libsyntax2/src/grammar/items/mod.rs b/crates/libsyntax2/src/grammar/items/mod.rs index c74266133..d460612b4 100644 --- a/crates/libsyntax2/src/grammar/items/mod.rs +++ b/crates/libsyntax2/src/grammar/items/mod.rs | |||
@@ -208,7 +208,7 @@ fn extern_crate_item(p: &mut Parser) { | |||
208 | assert!(p.at(CRATE_KW)); | 208 | assert!(p.at(CRATE_KW)); |
209 | p.bump(); | 209 | p.bump(); |
210 | name(p); | 210 | name(p); |
211 | alias(p); | 211 | opt_alias(p); |
212 | p.expect(SEMI); | 212 | p.expect(SEMI); |
213 | } | 213 | } |
214 | 214 | ||
diff --git a/crates/libsyntax2/src/grammar/items/use_item.rs b/crates/libsyntax2/src/grammar/items/use_item.rs index a3f7f0da8..3da40a629 100644 --- a/crates/libsyntax2/src/grammar/items/use_item.rs +++ b/crates/libsyntax2/src/grammar/items/use_item.rs | |||
@@ -26,7 +26,7 @@ fn use_tree(p: &mut Parser) { | |||
26 | paths::use_path(p); | 26 | paths::use_path(p); |
27 | match p.current() { | 27 | match p.current() { |
28 | AS_KW => { | 28 | AS_KW => { |
29 | alias(p); | 29 | opt_alias(p); |
30 | } | 30 | } |
31 | COLONCOLON => { | 31 | COLONCOLON => { |
32 | p.bump(); | 32 | p.bump(); |
diff --git a/crates/libsyntax2/src/grammar/mod.rs b/crates/libsyntax2/src/grammar/mod.rs index bbdc4f807..d09a9dc9c 100644 --- a/crates/libsyntax2/src/grammar/mod.rs +++ b/crates/libsyntax2/src/grammar/mod.rs | |||
@@ -92,14 +92,14 @@ fn opt_visibility(p: &mut Parser) { | |||
92 | _ => (), | 92 | _ => (), |
93 | } | 93 | } |
94 | } | 94 | } |
95 | fn alias(p: &mut Parser) -> bool { | 95 | |
96 | fn opt_alias(p: &mut Parser) { | ||
96 | if p.at(AS_KW) { | 97 | if p.at(AS_KW) { |
97 | let alias = p.start(); | 98 | let m = p.start(); |
98 | p.bump(); | 99 | p.bump(); |
99 | name(p); | 100 | name(p); |
100 | alias.complete(p, ALIAS); | 101 | m.complete(p, ALIAS); |
101 | } | 102 | } |
102 | true //FIXME: return false if three are errors | ||
103 | } | 103 | } |
104 | 104 | ||
105 | fn abi(p: &mut Parser) { | 105 | fn abi(p: &mut Parser) { |
diff --git a/crates/libsyntax2/src/grammar/params.rs b/crates/libsyntax2/src/grammar/params.rs index 7e58e8713..47567ec8a 100644 --- a/crates/libsyntax2/src/grammar/params.rs +++ b/crates/libsyntax2/src/grammar/params.rs | |||
@@ -92,16 +92,18 @@ fn value_parameter(p: &mut Parser, flavor: Flavor) { | |||
92 | // fn b(&self,) {} | 92 | // fn b(&self,) {} |
93 | // fn c(&'a self,) {} | 93 | // fn c(&'a self,) {} |
94 | // fn d(&'a mut self, x: i32) {} | 94 | // fn d(&'a mut self, x: i32) {} |
95 | // fn e(mut self) {} | ||
95 | // } | 96 | // } |
96 | fn self_param(p: &mut Parser) { | 97 | fn self_param(p: &mut Parser) { |
97 | let m; | 98 | let m; |
98 | if p.at(SELF_KW) { | 99 | if p.at(SELF_KW) || p.at(MUT_KW) && p.nth(1) == SELF_KW { |
99 | m = p.start(); | 100 | m = p.start(); |
100 | p.bump(); | 101 | p.eat(MUT_KW); |
102 | p.eat(SELF_KW); | ||
101 | // test arb_self_types | 103 | // test arb_self_types |
102 | // impl S { | 104 | // impl S { |
103 | // fn a(self: &Self) {} | 105 | // fn a(self: &Self) {} |
104 | // fn b(self: Box<Self>) {} | 106 | // fn b(mut self: Box<Self>) {} |
105 | // } | 107 | // } |
106 | if p.at(COLON) { | 108 | if p.at(COLON) { |
107 | types::ascription(p); | 109 | types::ascription(p); |
diff --git a/crates/libsyntax2/tests/data/parser/inline/0055_self_param.rs b/crates/libsyntax2/tests/data/parser/inline/0055_self_param.rs index 7bb1ca50c..80c0a43f5 100644 --- a/crates/libsyntax2/tests/data/parser/inline/0055_self_param.rs +++ b/crates/libsyntax2/tests/data/parser/inline/0055_self_param.rs | |||
@@ -3,4 +3,5 @@ impl S { | |||
3 | fn b(&self,) {} | 3 | fn b(&self,) {} |
4 | fn c(&'a self,) {} | 4 | fn c(&'a self,) {} |
5 | fn d(&'a mut self, x: i32) {} | 5 | fn d(&'a mut self, x: i32) {} |
6 | fn e(mut self) {} | ||
6 | } | 7 | } |
diff --git a/crates/libsyntax2/tests/data/parser/inline/0055_self_param.txt b/crates/libsyntax2/tests/data/parser/inline/0055_self_param.txt index 8b420909f..dd21dfe94 100644 --- a/crates/libsyntax2/tests/data/parser/inline/0055_self_param.txt +++ b/crates/libsyntax2/tests/data/parser/inline/0055_self_param.txt | |||
@@ -1,5 +1,5 @@ | |||
1 | FILE@[0; 106) | 1 | FILE@[0; 128) |
2 | IMPL_ITEM@[0; 105) | 2 | IMPL_ITEM@[0; 127) |
3 | IMPL_KW@[0; 4) | 3 | IMPL_KW@[0; 4) |
4 | WHITESPACE@[4; 5) | 4 | WHITESPACE@[4; 5) |
5 | PATH_TYPE@[5; 6) | 5 | PATH_TYPE@[5; 6) |
@@ -93,6 +93,23 @@ FILE@[0; 106) | |||
93 | BLOCK_EXPR@[101; 103) | 93 | BLOCK_EXPR@[101; 103) |
94 | L_CURLY@[101; 102) | 94 | L_CURLY@[101; 102) |
95 | R_CURLY@[102; 103) | 95 | R_CURLY@[102; 103) |
96 | WHITESPACE@[103; 104) | 96 | WHITESPACE@[103; 108) |
97 | R_CURLY@[104; 105) | 97 | FN_DEF@[108; 125) |
98 | WHITESPACE@[105; 106) | 98 | FN_KW@[108; 110) |
99 | WHITESPACE@[110; 111) | ||
100 | NAME@[111; 112) | ||
101 | IDENT@[111; 112) "e" | ||
102 | PARAM_LIST@[112; 122) | ||
103 | L_PAREN@[112; 113) | ||
104 | SELF_PARAM@[113; 121) | ||
105 | MUT_KW@[113; 116) | ||
106 | WHITESPACE@[116; 117) | ||
107 | SELF_KW@[117; 121) | ||
108 | R_PAREN@[121; 122) | ||
109 | WHITESPACE@[122; 123) | ||
110 | BLOCK_EXPR@[123; 125) | ||
111 | L_CURLY@[123; 124) | ||
112 | R_CURLY@[124; 125) | ||
113 | WHITESPACE@[125; 126) | ||
114 | R_CURLY@[126; 127) | ||
115 | WHITESPACE@[127; 128) | ||
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 index 2bf2a69f6..6a170d5ac 100644 --- a/crates/libsyntax2/tests/data/parser/inline/0104_arb_self_types.rs +++ b/crates/libsyntax2/tests/data/parser/inline/0104_arb_self_types.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | impl S { | 1 | impl S { |
2 | fn a(self: &Self) {} | 2 | fn a(self: &Self) {} |
3 | fn b(self: Box<Self>) {} | 3 | fn b(mut self: Box<Self>) {} |
4 | } | 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 index 41e3505fe..de94b4c63 100644 --- a/crates/libsyntax2/tests/data/parser/inline/0104_arb_self_types.txt +++ b/crates/libsyntax2/tests/data/parser/inline/0104_arb_self_types.txt | |||
@@ -1,5 +1,5 @@ | |||
1 | FILE@[0; 65) | 1 | FILE@[0; 69) |
2 | IMPL_ITEM@[0; 64) | 2 | IMPL_ITEM@[0; 68) |
3 | IMPL_KW@[0; 4) | 3 | IMPL_KW@[0; 4) |
4 | WHITESPACE@[4; 5) | 4 | WHITESPACE@[4; 5) |
5 | PATH_TYPE@[5; 6) | 5 | PATH_TYPE@[5; 6) |
@@ -34,36 +34,38 @@ FILE@[0; 65) | |||
34 | L_CURLY@[31; 32) | 34 | L_CURLY@[31; 32) |
35 | R_CURLY@[32; 33) | 35 | R_CURLY@[32; 33) |
36 | WHITESPACE@[33; 38) | 36 | WHITESPACE@[33; 38) |
37 | FN_DEF@[38; 62) | 37 | FN_DEF@[38; 66) |
38 | FN_KW@[38; 40) | 38 | FN_KW@[38; 40) |
39 | WHITESPACE@[40; 41) | 39 | WHITESPACE@[40; 41) |
40 | NAME@[41; 42) | 40 | NAME@[41; 42) |
41 | IDENT@[41; 42) "b" | 41 | IDENT@[41; 42) "b" |
42 | PARAM_LIST@[42; 59) | 42 | PARAM_LIST@[42; 63) |
43 | L_PAREN@[42; 43) | 43 | L_PAREN@[42; 43) |
44 | SELF_PARAM@[43; 58) | 44 | SELF_PARAM@[43; 62) |
45 | SELF_KW@[43; 47) | 45 | MUT_KW@[43; 46) |
46 | COLON@[47; 48) | 46 | WHITESPACE@[46; 47) |
47 | WHITESPACE@[48; 49) | 47 | SELF_KW@[47; 51) |
48 | PATH_TYPE@[49; 58) | 48 | COLON@[51; 52) |
49 | PATH@[49; 58) | 49 | WHITESPACE@[52; 53) |
50 | PATH_SEGMENT@[49; 58) | 50 | PATH_TYPE@[53; 62) |
51 | NAME_REF@[49; 52) | 51 | PATH@[53; 62) |
52 | IDENT@[49; 52) "Box" | 52 | PATH_SEGMENT@[53; 62) |
53 | TYPE_ARG_LIST@[52; 58) | 53 | NAME_REF@[53; 56) |
54 | L_ANGLE@[52; 53) | 54 | IDENT@[53; 56) "Box" |
55 | TYPE_ARG@[53; 57) | 55 | TYPE_ARG_LIST@[56; 62) |
56 | PATH_TYPE@[53; 57) | 56 | L_ANGLE@[56; 57) |
57 | PATH@[53; 57) | 57 | TYPE_ARG@[57; 61) |
58 | PATH_SEGMENT@[53; 57) | 58 | PATH_TYPE@[57; 61) |
59 | NAME_REF@[53; 57) | 59 | PATH@[57; 61) |
60 | IDENT@[53; 57) "Self" | 60 | PATH_SEGMENT@[57; 61) |
61 | R_ANGLE@[57; 58) | 61 | NAME_REF@[57; 61) |
62 | R_PAREN@[58; 59) | 62 | IDENT@[57; 61) "Self" |
63 | WHITESPACE@[59; 60) | 63 | R_ANGLE@[61; 62) |
64 | BLOCK_EXPR@[60; 62) | 64 | R_PAREN@[62; 63) |
65 | L_CURLY@[60; 61) | 65 | WHITESPACE@[63; 64) |
66 | R_CURLY@[61; 62) | 66 | BLOCK_EXPR@[64; 66) |
67 | WHITESPACE@[62; 63) | 67 | L_CURLY@[64; 65) |
68 | R_CURLY@[63; 64) | 68 | R_CURLY@[65; 66) |
69 | WHITESPACE@[64; 65) | 69 | WHITESPACE@[66; 67) |
70 | R_CURLY@[67; 68) | ||
71 | WHITESPACE@[68; 69) | ||