diff options
Diffstat (limited to 'crates/mbe/src')
-rw-r--r-- | crates/mbe/src/benchmark.rs | 2 | ||||
-rw-r--r-- | crates/mbe/src/expander/matcher.rs | 21 | ||||
-rw-r--r-- | crates/mbe/src/lib.rs | 10 | ||||
-rw-r--r-- | crates/mbe/src/parser.rs | 2 | ||||
-rw-r--r-- | crates/mbe/src/syntax_bridge.rs | 5 | ||||
-rw-r--r-- | crates/mbe/src/tt_iter.rs | 2 |
6 files changed, 17 insertions, 25 deletions
diff --git a/crates/mbe/src/benchmark.rs b/crates/mbe/src/benchmark.rs index 38707ffa5..18eb97f0d 100644 --- a/crates/mbe/src/benchmark.rs +++ b/crates/mbe/src/benchmark.rs | |||
@@ -187,7 +187,7 @@ fn invocation_fixtures(rules: &FxHashMap<String, MacroRules>) -> Vec<(String, tt | |||
187 | let a = 1664525; | 187 | let a = 1664525; |
188 | let c = 1013904223; | 188 | let c = 1013904223; |
189 | *seed = usize::wrapping_add(usize::wrapping_mul(*seed, a), c); | 189 | *seed = usize::wrapping_add(usize::wrapping_mul(*seed, a), c); |
190 | return *seed; | 190 | *seed |
191 | } | 191 | } |
192 | fn make_ident(ident: &str) -> tt::TokenTree { | 192 | fn make_ident(ident: &str) -> tt::TokenTree { |
193 | tt::Leaf::Ident(tt::Ident { id: tt::TokenId::unspecified(), text: SmolStr::new(ident) }) | 193 | tt::Leaf::Ident(tt::Ident { id: tt::TokenId::unspecified(), text: SmolStr::new(ident) }) |
diff --git a/crates/mbe/src/expander/matcher.rs b/crates/mbe/src/expander/matcher.rs index 84ca3ff87..c982eb58f 100644 --- a/crates/mbe/src/expander/matcher.rs +++ b/crates/mbe/src/expander/matcher.rs | |||
@@ -219,7 +219,7 @@ impl BindingsBuilder { | |||
219 | bindings | 219 | bindings |
220 | } | 220 | } |
221 | 221 | ||
222 | fn build_inner(&self, bindings: &mut Bindings, link_nodes: &Vec<LinkNode<Rc<BindingKind>>>) { | 222 | fn build_inner(&self, bindings: &mut Bindings, link_nodes: &[LinkNode<Rc<BindingKind>>]) { |
223 | let mut nodes = Vec::new(); | 223 | let mut nodes = Vec::new(); |
224 | self.collect_nodes(&link_nodes, &mut nodes); | 224 | self.collect_nodes(&link_nodes, &mut nodes); |
225 | 225 | ||
@@ -301,7 +301,7 @@ impl BindingsBuilder { | |||
301 | 301 | ||
302 | fn collect_nodes<'a>( | 302 | fn collect_nodes<'a>( |
303 | &'a self, | 303 | &'a self, |
304 | link_nodes: &'a Vec<LinkNode<Rc<BindingKind>>>, | 304 | link_nodes: &'a [LinkNode<Rc<BindingKind>>], |
305 | nodes: &mut Vec<&'a Rc<BindingKind>>, | 305 | nodes: &mut Vec<&'a Rc<BindingKind>>, |
306 | ) { | 306 | ) { |
307 | link_nodes.iter().for_each(|it| match it { | 307 | link_nodes.iter().for_each(|it| match it { |
@@ -494,15 +494,8 @@ fn match_loop_inner<'t>( | |||
494 | } | 494 | } |
495 | Some(err) => { | 495 | Some(err) => { |
496 | res.add_err(err); | 496 | res.add_err(err); |
497 | match match_res.value { | 497 | if let Some(fragment) = match_res.value { |
498 | Some(fragment) => { | 498 | bindings_builder.push_fragment(&mut item.bindings, &name, fragment); |
499 | bindings_builder.push_fragment( | ||
500 | &mut item.bindings, | ||
501 | &name, | ||
502 | fragment, | ||
503 | ); | ||
504 | } | ||
505 | _ => {} | ||
506 | } | 499 | } |
507 | item.is_error = true; | 500 | item.is_error = true; |
508 | error_items.push(item); | 501 | error_items.push(item); |
@@ -578,9 +571,9 @@ fn match_loop(pattern: &MetaTemplate, src: &tt::Subtree) -> Match { | |||
578 | ); | 571 | ); |
579 | stdx::always!(cur_items.is_empty()); | 572 | stdx::always!(cur_items.is_empty()); |
580 | 573 | ||
581 | if error_items.len() > 0 { | 574 | if !error_items.is_empty() { |
582 | error_recover_item = error_items.pop().map(|it| it.bindings); | 575 | error_recover_item = error_items.pop().map(|it| it.bindings); |
583 | } else if eof_items.len() > 0 { | 576 | } else if !eof_items.is_empty() { |
584 | error_recover_item = Some(eof_items[0].bindings.clone()); | 577 | error_recover_item = Some(eof_items[0].bindings.clone()); |
585 | } | 578 | } |
586 | 579 | ||
@@ -793,7 +786,7 @@ impl<'a> TtIter<'a> { | |||
793 | _ => (), | 786 | _ => (), |
794 | } | 787 | } |
795 | 788 | ||
796 | let tt = self.next().ok_or_else(|| ())?.clone(); | 789 | let tt = self.next().ok_or(())?.clone(); |
797 | let punct = match tt { | 790 | let punct = match tt { |
798 | tt::TokenTree::Leaf(tt::Leaf::Punct(punct)) if punct.spacing == tt::Spacing::Joint => { | 791 | tt::TokenTree::Leaf(tt::Leaf::Punct(punct)) if punct.spacing == tt::Spacing::Joint => { |
799 | punct | 792 | punct |
diff --git a/crates/mbe/src/lib.rs b/crates/mbe/src/lib.rs index b95374b76..380a50744 100644 --- a/crates/mbe/src/lib.rs +++ b/crates/mbe/src/lib.rs | |||
@@ -295,8 +295,8 @@ fn validate(pattern: &MetaTemplate) -> Result<(), ParseError> { | |||
295 | // Checks that no repetition which could match an empty token | 295 | // Checks that no repetition which could match an empty token |
296 | // https://github.com/rust-lang/rust/blob/a58b1ed44f5e06976de2bdc4d7dc81c36a96934f/src/librustc_expand/mbe/macro_rules.rs#L558 | 296 | // https://github.com/rust-lang/rust/blob/a58b1ed44f5e06976de2bdc4d7dc81c36a96934f/src/librustc_expand/mbe/macro_rules.rs#L558 |
297 | 297 | ||
298 | if separator.is_none() { | 298 | if separator.is_none() |
299 | if subtree.iter().all(|child_op| { | 299 | && subtree.iter().all(|child_op| { |
300 | match child_op { | 300 | match child_op { |
301 | Op::Var { kind, .. } => { | 301 | Op::Var { kind, .. } => { |
302 | // vis is optional | 302 | // vis is optional |
@@ -314,9 +314,9 @@ fn validate(pattern: &MetaTemplate) -> Result<(), ParseError> { | |||
314 | Op::Subtree { .. } => {} | 314 | Op::Subtree { .. } => {} |
315 | } | 315 | } |
316 | false | 316 | false |
317 | }) { | 317 | }) |
318 | return Err(ParseError::RepetitionEmptyTokenTree); | 318 | { |
319 | } | 319 | return Err(ParseError::RepetitionEmptyTokenTree); |
320 | } | 320 | } |
321 | validate(subtree)? | 321 | validate(subtree)? |
322 | } | 322 | } |
diff --git a/crates/mbe/src/parser.rs b/crates/mbe/src/parser.rs index 61b2a4955..04c0d3e75 100644 --- a/crates/mbe/src/parser.rs +++ b/crates/mbe/src/parser.rs | |||
@@ -213,7 +213,7 @@ fn next_op<'a>(first: &tt::TokenTree, src: &mut TtIter<'a>, mode: Mode) -> Resul | |||
213 | Ok(res) | 213 | Ok(res) |
214 | } | 214 | } |
215 | 215 | ||
216 | fn eat_fragment_kind<'a>(src: &mut TtIter<'a>, mode: Mode) -> Result<Option<SmolStr>, ParseError> { | 216 | fn eat_fragment_kind(src: &mut TtIter<'_>, mode: Mode) -> Result<Option<SmolStr>, ParseError> { |
217 | if let Mode::Pattern = mode { | 217 | if let Mode::Pattern = mode { |
218 | src.expect_char(':').map_err(|()| err!("bad fragment specifier 1"))?; | 218 | src.expect_char(':').map_err(|()| err!("bad fragment specifier 1"))?; |
219 | let ident = src.expect_ident().map_err(|()| err!("bad fragment specifier 1"))?; | 219 | let ident = src.expect_ident().map_err(|()| err!("bad fragment specifier 1"))?; |
diff --git a/crates/mbe/src/syntax_bridge.rs b/crates/mbe/src/syntax_bridge.rs index b11172caf..978c75747 100644 --- a/crates/mbe/src/syntax_bridge.rs +++ b/crates/mbe/src/syntax_bridge.rs | |||
@@ -243,8 +243,7 @@ trait TokenConvertor { | |||
243 | type Token: SrcToken; | 243 | type Token: SrcToken; |
244 | 244 | ||
245 | fn go(&mut self) -> tt::Subtree { | 245 | fn go(&mut self) -> tt::Subtree { |
246 | let mut subtree = tt::Subtree::default(); | 246 | let mut subtree = tt::Subtree { delimiter: None, ..Default::default() }; |
247 | subtree.delimiter = None; | ||
248 | while self.peek().is_some() { | 247 | while self.peek().is_some() { |
249 | self.collect_leaf(&mut subtree.token_trees); | 248 | self.collect_leaf(&mut subtree.token_trees); |
250 | } | 249 | } |
@@ -506,7 +505,7 @@ impl TokenConvertor for Convertor { | |||
506 | 505 | ||
507 | fn peek(&self) -> Option<Self::Token> { | 506 | fn peek(&self) -> Option<Self::Token> { |
508 | if let Some((punct, mut offset)) = self.punct_offset.clone() { | 507 | if let Some((punct, mut offset)) = self.punct_offset.clone() { |
509 | offset = offset + TextSize::of('.'); | 508 | offset += TextSize::of('.'); |
510 | if usize::from(offset) < punct.text().len() { | 509 | if usize::from(offset) < punct.text().len() { |
511 | return Some(SynToken::Punch(punct, offset)); | 510 | return Some(SynToken::Punch(punct, offset)); |
512 | } | 511 | } |
diff --git a/crates/mbe/src/tt_iter.rs b/crates/mbe/src/tt_iter.rs index 99a8d250b..bd54f2442 100644 --- a/crates/mbe/src/tt_iter.rs +++ b/crates/mbe/src/tt_iter.rs | |||
@@ -138,7 +138,7 @@ impl<'a> TtIter<'a> { | |||
138 | } | 138 | } |
139 | } | 139 | } |
140 | self.inner = self.inner.as_slice()[res.len()..].iter(); | 140 | self.inner = self.inner.as_slice()[res.len()..].iter(); |
141 | if res.len() == 0 && err.is_none() { | 141 | if res.is_empty() && err.is_none() { |
142 | err = Some(err!("no tokens consumed")); | 142 | err = Some(err!("no tokens consumed")); |
143 | } | 143 | } |
144 | let res = match res.len() { | 144 | let res = match res.len() { |