aboutsummaryrefslogtreecommitdiff
path: root/crates/mbe
diff options
context:
space:
mode:
Diffstat (limited to 'crates/mbe')
-rw-r--r--crates/mbe/src/benchmark.rs21
-rw-r--r--crates/mbe/src/expander/matcher.rs14
-rw-r--r--crates/mbe/src/parser.rs2
-rw-r--r--crates/mbe/src/syntax_bridge.rs4
-rw-r--r--crates/mbe/src/tests.rs2
5 files changed, 20 insertions, 23 deletions
diff --git a/crates/mbe/src/benchmark.rs b/crates/mbe/src/benchmark.rs
index 503ad1355..ba814a2e1 100644
--- a/crates/mbe/src/benchmark.rs
+++ b/crates/mbe/src/benchmark.rs
@@ -120,7 +120,7 @@ fn invocation_fixtures(rules: &FxHashMap<String, MacroRules>) -> Vec<(String, tt
120 Some("pat") => parent.token_trees.push(make_ident("foo")), 120 Some("pat") => parent.token_trees.push(make_ident("foo")),
121 Some("path") => parent.token_trees.push(make_ident("foo")), 121 Some("path") => parent.token_trees.push(make_ident("foo")),
122 Some("literal") => parent.token_trees.push(make_literal("1")), 122 Some("literal") => parent.token_trees.push(make_literal("1")),
123 Some("expr") => parent.token_trees.push(make_ident("foo").into()), 123 Some("expr") => parent.token_trees.push(make_ident("foo")),
124 Some("lifetime") => { 124 Some("lifetime") => {
125 parent.token_trees.push(make_punct('\'')); 125 parent.token_trees.push(make_punct('\''));
126 parent.token_trees.push(make_ident("a")); 126 parent.token_trees.push(make_ident("a"));
@@ -157,17 +157,15 @@ fn invocation_fixtures(rules: &FxHashMap<String, MacroRules>) -> Vec<(String, tt
157 if i + 1 != cnt { 157 if i + 1 != cnt {
158 if let Some(sep) = separator { 158 if let Some(sep) = separator {
159 match sep { 159 match sep {
160 Separator::Literal(it) => parent 160 Separator::Literal(it) => {
161 .token_trees 161 parent.token_trees.push(tt::Leaf::Literal(it.clone()).into())
162 .push(tt::Leaf::Literal(it.clone().into()).into()), 162 }
163 Separator::Ident(it) => parent 163 Separator::Ident(it) => {
164 .token_trees 164 parent.token_trees.push(tt::Leaf::Ident(it.clone()).into())
165 .push(tt::Leaf::Ident(it.clone().into()).into()), 165 }
166 Separator::Puncts(puncts) => { 166 Separator::Puncts(puncts) => {
167 for it in puncts { 167 for it in puncts {
168 parent 168 parent.token_trees.push(tt::Leaf::Punct(*it).into())
169 .token_trees
170 .push(tt::Leaf::Punct(it.clone().into()).into())
171 } 169 }
172 } 170 }
173 }; 171 };
@@ -176,8 +174,7 @@ fn invocation_fixtures(rules: &FxHashMap<String, MacroRules>) -> Vec<(String, tt
176 } 174 }
177 } 175 }
178 Op::Subtree { tokens, delimiter } => { 176 Op::Subtree { tokens, delimiter } => {
179 let mut subtree = 177 let mut subtree = tt::Subtree { delimiter: *delimiter, token_trees: Vec::new() };
180 tt::Subtree { delimiter: delimiter.clone(), token_trees: Vec::new() };
181 tokens.iter().for_each(|it| { 178 tokens.iter().for_each(|it| {
182 collect_from_op(it, &mut subtree, seed); 179 collect_from_op(it, &mut subtree, seed);
183 }); 180 });
diff --git a/crates/mbe/src/expander/matcher.rs b/crates/mbe/src/expander/matcher.rs
index 2c69e8968..b6782b4ba 100644
--- a/crates/mbe/src/expander/matcher.rs
+++ b/crates/mbe/src/expander/matcher.rs
@@ -540,7 +540,7 @@ fn match_loop(pattern: &MetaTemplate, src: &tt::Subtree) -> Match {
540 let mut src = TtIter::new(src); 540 let mut src = TtIter::new(src);
541 let mut stack: SmallVec<[TtIter; 1]> = SmallVec::new(); 541 let mut stack: SmallVec<[TtIter; 1]> = SmallVec::new();
542 let mut res = Match::default(); 542 let mut res = Match::default();
543 let mut error_reover_item = None; 543 let mut error_recover_item = None;
544 544
545 let mut bindings_builder = BindingsBuilder::default(); 545 let mut bindings_builder = BindingsBuilder::default();
546 546
@@ -579,9 +579,9 @@ fn match_loop(pattern: &MetaTemplate, src: &tt::Subtree) -> Match {
579 stdx::always!(cur_items.is_empty()); 579 stdx::always!(cur_items.is_empty());
580 580
581 if error_items.len() > 0 { 581 if error_items.len() > 0 {
582 error_reover_item = error_items.pop().map(|it| it.bindings); 582 error_recover_item = error_items.pop().map(|it| it.bindings);
583 } else if eof_items.len() > 0 { 583 } else if eof_items.len() > 0 {
584 error_reover_item = Some(eof_items[0].bindings.clone()); 584 error_recover_item = Some(eof_items[0].bindings.clone());
585 } 585 }
586 586
587 // We need to do some post processing after the `match_loop_inner`. 587 // We need to do some post processing after the `match_loop_inner`.
@@ -594,8 +594,8 @@ fn match_loop(pattern: &MetaTemplate, src: &tt::Subtree) -> Match {
594 res.bindings = bindings_builder.build(&eof_items[0].bindings); 594 res.bindings = bindings_builder.build(&eof_items[0].bindings);
595 } else { 595 } else {
596 // Error recovery 596 // Error recovery
597 if error_reover_item.is_some() { 597 if let Some(item) = error_recover_item {
598 res.bindings = bindings_builder.build(&error_reover_item.unwrap()); 598 res.bindings = bindings_builder.build(&item);
599 } 599 }
600 res.add_err(ExpandError::UnexpectedToken); 600 res.add_err(ExpandError::UnexpectedToken);
601 } 601 }
@@ -618,7 +618,7 @@ fn match_loop(pattern: &MetaTemplate, src: &tt::Subtree) -> Match {
618 } 618 }
619 res.add_err(err!("leftover tokens")); 619 res.add_err(err!("leftover tokens"));
620 620
621 if let Some(error_reover_item) = error_reover_item { 621 if let Some(error_reover_item) = error_recover_item {
622 res.bindings = bindings_builder.build(&error_reover_item); 622 res.bindings = bindings_builder.build(&error_reover_item);
623 } 623 }
624 return res; 624 return res;
@@ -722,7 +722,7 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> ExpandResult<Option<Fragmen
722 input 722 input
723 .expect_literal() 723 .expect_literal()
724 .map(|literal| { 724 .map(|literal| {
725 let lit = tt::Leaf::from(literal.clone()); 725 let lit = literal.clone();
726 match neg { 726 match neg {
727 None => Some(lit.into()), 727 None => Some(lit.into()),
728 Some(neg) => Some(tt::TokenTree::Subtree(tt::Subtree { 728 Some(neg) => Some(tt::TokenTree::Subtree(tt::Subtree {
diff --git a/crates/mbe/src/parser.rs b/crates/mbe/src/parser.rs
index 8671322e1..7b5b8ec16 100644
--- a/crates/mbe/src/parser.rs
+++ b/crates/mbe/src/parser.rs
@@ -262,7 +262,7 @@ fn parse_repeat(src: &mut TtIter) -> Result<(Option<Separator>, RepeatKind), Par
262 if puncts.len() == 3 { 262 if puncts.len() == 3 {
263 return Err(ParseError::InvalidRepeat); 263 return Err(ParseError::InvalidRepeat);
264 } 264 }
265 puncts.push(punct.clone()) 265 puncts.push(*punct)
266 } 266 }
267 _ => return Err(ParseError::InvalidRepeat), 267 _ => return Err(ParseError::InvalidRepeat),
268 } 268 }
diff --git a/crates/mbe/src/syntax_bridge.rs b/crates/mbe/src/syntax_bridge.rs
index b715ebfc4..85163c4b3 100644
--- a/crates/mbe/src/syntax_bridge.rs
+++ b/crates/mbe/src/syntax_bridge.rs
@@ -130,7 +130,7 @@ pub fn parse_exprs_with_sep(tt: &tt::Subtree, sep: char) -> Vec<tt::Subtree> {
130 res.push(match expanded.value { 130 res.push(match expanded.value {
131 None => break, 131 None => break,
132 Some(tt @ tt::TokenTree::Leaf(_)) => { 132 Some(tt @ tt::TokenTree::Leaf(_)) => {
133 tt::Subtree { delimiter: None, token_trees: vec![tt.into()] } 133 tt::Subtree { delimiter: None, token_trees: vec![tt] }
134 } 134 }
135 Some(tt::TokenTree::Subtree(tt)) => tt, 135 Some(tt::TokenTree::Subtree(tt)) => tt,
136 }); 136 });
@@ -727,7 +727,7 @@ impl<'a> TreeSink for TtTreeSink<'a> {
727 // Note: We always assume the semi-colon would be the last token in 727 // Note: We always assume the semi-colon would be the last token in
728 // other parts of RA such that we don't add whitespace here. 728 // other parts of RA such that we don't add whitespace here.
729 if curr.spacing == tt::Spacing::Alone && curr.char != ';' { 729 if curr.spacing == tt::Spacing::Alone && curr.char != ';' {
730 self.inner.token(WHITESPACE, " ".into()); 730 self.inner.token(WHITESPACE, " ");
731 self.text_pos += TextSize::of(' '); 731 self.text_pos += TextSize::of(' ');
732 } 732 }
733 } 733 }
diff --git a/crates/mbe/src/tests.rs b/crates/mbe/src/tests.rs
index eca0bcc18..25c374b9b 100644
--- a/crates/mbe/src/tests.rs
+++ b/crates/mbe/src/tests.rs
@@ -35,7 +35,7 @@ mod rule_parsing {
35 fn test_invalid_arms() { 35 fn test_invalid_arms() {
36 fn check(macro_body: &str, err: ParseError) { 36 fn check(macro_body: &str, err: ParseError) {
37 let m = parse_macro_arm(macro_body); 37 let m = parse_macro_arm(macro_body);
38 assert_eq!(m, Err(err.into())); 38 assert_eq!(m, Err(err));
39 } 39 }
40 check("invalid", ParseError::Expected("expected subtree".into())); 40 check("invalid", ParseError::Expected("expected subtree".into()));
41 41