aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/parser/grammar/items/mod.rs11
-rw-r--r--src/parser/grammar/items/traits.rs7
-rw-r--r--src/parser/grammar/type_params.rs52
3 files changed, 47 insertions, 23 deletions
diff --git a/src/parser/grammar/items/mod.rs b/src/parser/grammar/items/mod.rs
index 12bcf7924..037cdca53 100644
--- a/src/parser/grammar/items/mod.rs
+++ b/src/parser/grammar/items/mod.rs
@@ -149,6 +149,17 @@ fn item(p: &mut Parser) {
149 } 149 }
150 } 150 }
151 } 151 }
152 TRAIT_KW => {
153 traits::trait_item(p);
154 TRAIT_ITEM
155 }
156 // test auto_trait
157 // auto trait T {}
158 IDENT if p.at_contextual_kw("auto") && la == TRAIT_KW => {
159 p.bump_remap(AUTO_KW);
160 traits::trait_item(p);
161 TRAIT_ITEM
162 }
152 IMPL_KW => { 163 IMPL_KW => {
153 traits::impl_item(p); 164 traits::impl_item(p);
154 IMPL_ITEM 165 IMPL_ITEM
diff --git a/src/parser/grammar/items/traits.rs b/src/parser/grammar/items/traits.rs
index 7d657ced0..60158fe41 100644
--- a/src/parser/grammar/items/traits.rs
+++ b/src/parser/grammar/items/traits.rs
@@ -1,9 +1,16 @@
1use super::*; 1use super::*;
2 2
3// test trait_item
4// trait T<U>: Hash + Clone where U: Copy {}
3pub(super) fn trait_item(p: &mut Parser) { 5pub(super) fn trait_item(p: &mut Parser) {
4 assert!(p.at(TRAIT_KW)); 6 assert!(p.at(TRAIT_KW));
5 p.bump(); 7 p.bump();
6 name(p); 8 name(p);
9 type_params::list(p);
10 if p.at(COLON) {
11 type_params::bounds(p);
12 }
13 type_params::where_clause(p);
7 p.expect(L_CURLY); 14 p.expect(L_CURLY);
8 p.expect(R_CURLY); 15 p.expect(R_CURLY);
9} 16}
diff --git a/src/parser/grammar/type_params.rs b/src/parser/grammar/type_params.rs
index ba0d4bfe8..3648ab5f3 100644
--- a/src/parser/grammar/type_params.rs
+++ b/src/parser/grammar/type_params.rs
@@ -39,29 +39,8 @@ pub(super) fn list(p: &mut Parser) {
39 assert!(p.at(IDENT)); 39 assert!(p.at(IDENT));
40 let m = p.start(); 40 let m = p.start();
41 p.bump(); 41 p.bump();
42 if p.eat(COLON) { 42 if p.at(COLON) {
43 // test type_param_bounds 43 bounds(p);
44 // struct S<T: 'a + ?Sized + (Copy)>;
45 loop {
46 let has_paren = p.eat(L_PAREN);
47 p.eat(QUESTION);
48 if p.at(FOR_KW) {
49 //TODO
50 }
51 if p.at(LIFETIME) {
52 p.bump();
53 } else if paths::is_path_start(p) {
54 paths::type_path(p);
55 } else {
56 break;
57 }
58 if has_paren {
59 p.expect(R_PAREN);
60 }
61 if !p.eat(PLUS) {
62 break;
63 }
64 }
65 } 44 }
66 // test type_param_default 45 // test type_param_default
67 // struct S<T = i32>; 46 // struct S<T = i32>;
@@ -73,6 +52,33 @@ pub(super) fn list(p: &mut Parser) {
73 } 52 }
74} 53}
75 54
55// test type_param_bounds
56// struct S<T: 'a + ?Sized + (Copy)>;
57pub(super) fn bounds(p: &mut Parser) {
58 assert!(p.at(COLON));
59 p.bump();
60 loop {
61 let has_paren = p.eat(L_PAREN);
62 p.eat(QUESTION);
63 if p.at(FOR_KW) {
64 //TODO
65 }
66 if p.at(LIFETIME) {
67 p.bump();
68 } else if paths::is_path_start(p) {
69 paths::type_path(p);
70 } else {
71 break;
72 }
73 if has_paren {
74 p.expect(R_PAREN);
75 }
76 if !p.eat(PLUS) {
77 break;
78 }
79 }
80}
81
76pub(super) fn where_clause(p: &mut Parser) { 82pub(super) fn where_clause(p: &mut Parser) {
77 if p.at(WHERE_KW) { 83 if p.at(WHERE_KW) {
78 let m = p.start(); 84 let m = p.start();