aboutsummaryrefslogtreecommitdiff
path: root/crates/parser/src/grammar/items/traits.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/parser/src/grammar/items/traits.rs')
-rw-r--r--crates/parser/src/grammar/items/traits.rs38
1 files changed, 8 insertions, 30 deletions
diff --git a/crates/parser/src/grammar/items/traits.rs b/crates/parser/src/grammar/items/traits.rs
index 751ce65f2..8394020da 100644
--- a/crates/parser/src/grammar/items/traits.rs
+++ b/crates/parser/src/grammar/items/traits.rs
@@ -5,11 +5,11 @@ use super::*;
5// test trait_item 5// test trait_item
6// trait T<U>: Hash + Clone where U: Copy {} 6// trait T<U>: Hash + Clone where U: Copy {}
7// trait X<U: Debug + Display>: Hash + Clone where U: Copy {} 7// trait X<U: Debug + Display>: Hash + Clone where U: Copy {}
8pub(super) fn trait_def(p: &mut Parser) { 8pub(super) fn trait_(p: &mut Parser) {
9 assert!(p.at(T![trait])); 9 assert!(p.at(T![trait]));
10 p.bump(T![trait]); 10 p.bump(T![trait]);
11 name_r(p, ITEM_RECOVERY_SET); 11 name_r(p, ITEM_RECOVERY_SET);
12 type_params::opt_type_param_list(p); 12 type_params::opt_generic_param_list(p);
13 // test trait_alias 13 // test trait_alias
14 // trait Z<U> = T<U>; 14 // trait Z<U> = T<U>;
15 // trait Z<U> = T<U> where U: Copy; 15 // trait Z<U> = T<U> where U: Copy;
@@ -25,41 +25,19 @@ pub(super) fn trait_def(p: &mut Parser) {
25 } 25 }
26 type_params::opt_where_clause(p); 26 type_params::opt_where_clause(p);
27 if p.at(T!['{']) { 27 if p.at(T!['{']) {
28 trait_item_list(p); 28 assoc_item_list(p);
29 } else { 29 } else {
30 p.error("expected `{`"); 30 p.error("expected `{`");
31 } 31 }
32} 32}
33 33
34// test trait_item_list
35// impl F {
36// type A: Clone;
37// const B: i32;
38// fn foo() {}
39// fn bar(&self);
40// }
41pub(crate) fn trait_item_list(p: &mut Parser) {
42 assert!(p.at(T!['{']));
43 let m = p.start();
44 p.bump(T!['{']);
45 while !p.at(EOF) && !p.at(T!['}']) {
46 if p.at(T!['{']) {
47 error_block(p, "expected an item");
48 continue;
49 }
50 item_or_macro(p, true);
51 }
52 p.expect(T!['}']);
53 m.complete(p, ASSOC_ITEM_LIST);
54}
55
56// test impl_def 34// test impl_def
57// impl Foo {} 35// impl Foo {}
58pub(super) fn impl_def(p: &mut Parser) { 36pub(super) fn impl_(p: &mut Parser) {
59 assert!(p.at(T![impl])); 37 assert!(p.at(T![impl]));
60 p.bump(T![impl]); 38 p.bump(T![impl]);
61 if choose_type_params_over_qpath(p) { 39 if choose_type_params_over_qpath(p) {
62 type_params::opt_type_param_list(p); 40 type_params::opt_generic_param_list(p);
63 } 41 }
64 42
65 // FIXME: never type 43 // FIXME: never type
@@ -74,7 +52,7 @@ pub(super) fn impl_def(p: &mut Parser) {
74 } 52 }
75 type_params::opt_where_clause(p); 53 type_params::opt_where_clause(p);
76 if p.at(T!['{']) { 54 if p.at(T!['{']) {
77 impl_item_list(p); 55 assoc_item_list(p);
78 } else { 56 } else {
79 p.error("expected `{`"); 57 p.error("expected `{`");
80 } 58 }
@@ -87,7 +65,7 @@ pub(super) fn impl_def(p: &mut Parser) {
87// fn foo() {} 65// fn foo() {}
88// fn bar(&self) {} 66// fn bar(&self) {}
89// } 67// }
90pub(crate) fn impl_item_list(p: &mut Parser) { 68pub(crate) fn assoc_item_list(p: &mut Parser) {
91 assert!(p.at(T!['{'])); 69 assert!(p.at(T!['{']));
92 let m = p.start(); 70 let m = p.start();
93 p.bump(T!['{']); 71 p.bump(T!['{']);
@@ -97,7 +75,7 @@ pub(crate) fn impl_item_list(p: &mut Parser) {
97 // //! This is a doc comment 75 // //! This is a doc comment
98 // #![doc("This is also a doc comment")] 76 // #![doc("This is also a doc comment")]
99 // } 77 // }
100 attributes::inner_attributes(p); 78 attributes::inner_attrs(p);
101 79
102 while !p.at(EOF) && !p.at(T!['}']) { 80 while !p.at(EOF) && !p.at(T!['}']) {
103 if p.at(T!['{']) { 81 if p.at(T!['{']) {