From 47747cd4120e260a144242aadd7732e11d133fe4 Mon Sep 17 00:00:00 2001 From: Clemens Wasser Date: Mon, 7 Jun 2021 13:59:01 +0200 Subject: Apply some clippy suggestions --- crates/mbe/src/expander/matcher.rs | 8 ++++---- crates/mbe/src/expander/transcriber.rs | 2 +- crates/mbe/src/lib.rs | 10 +++++----- crates/mbe/src/subtree_source.rs | 2 +- crates/mbe/src/syntax_bridge.rs | 2 +- crates/mbe/src/tt_iter.rs | 9 +++++---- 6 files changed, 17 insertions(+), 16 deletions(-) (limited to 'crates/mbe') diff --git a/crates/mbe/src/expander/matcher.rs b/crates/mbe/src/expander/matcher.rs index b4f2fe9a4..0d694b1a7 100644 --- a/crates/mbe/src/expander/matcher.rs +++ b/crates/mbe/src/expander/matcher.rs @@ -645,7 +645,7 @@ fn match_loop(pattern: &MetaTemplate, src: &tt::Subtree) -> Match { None if match_res.err.is_none() => { bindings_builder.push_optional(&mut item.bindings, name); } - _ => {} + None => {} } if let Some(err) = match_res.err { res.add_err(err); @@ -756,7 +756,7 @@ impl<'a> TtIter<'a> { let ok = match separator { Separator::Ident(lhs) if idx == 0 => match fork.expect_ident_or_underscore() { Ok(rhs) => rhs.text == lhs.text, - _ => false, + Err(_) => false, }, Separator::Literal(lhs) if idx == 0 => match fork.expect_literal() { Ok(rhs) => match rhs { @@ -764,11 +764,11 @@ impl<'a> TtIter<'a> { tt::Leaf::Ident(rhs) => rhs.text == lhs.text, tt::Leaf::Punct(_) => false, }, - _ => false, + Err(_) => false, }, Separator::Puncts(lhss) if idx < lhss.len() => match fork.expect_punct() { Ok(rhs) => rhs.char == lhss[idx].char, - _ => false, + Err(_) => false, }, _ => false, }; diff --git a/crates/mbe/src/expander/transcriber.rs b/crates/mbe/src/expander/transcriber.rs index 49a137577..4894e2a0c 100644 --- a/crates/mbe/src/expander/transcriber.rs +++ b/crates/mbe/src/expander/transcriber.rs @@ -241,6 +241,6 @@ fn push_fragment(buf: &mut Vec, fragment: Fragment) { fn push_subtree(buf: &mut Vec, tt: tt::Subtree) { match tt.delimiter { None => buf.extend(tt.token_trees), - _ => buf.push(tt.into()), + Some(_) => buf.push(tt.into()), } } diff --git a/crates/mbe/src/lib.rs b/crates/mbe/src/lib.rs index 8c8528aaf..fcc596756 100644 --- a/crates/mbe/src/lib.rs +++ b/crates/mbe/src/lib.rs @@ -135,7 +135,7 @@ impl Shift { /// Shift given TokenTree token id fn shift_all(self, tt: &mut tt::Subtree) { - for t in tt.token_trees.iter_mut() { + for t in &mut tt.token_trees { match t { tt::TokenTree::Leaf(leaf) => match leaf { tt::Leaf::Ident(ident) => ident.id = self.shift(ident.id), @@ -188,7 +188,7 @@ impl MacroRules { } } - for rule in rules.iter() { + for rule in &rules { validate(&rule.lhs)?; } @@ -241,7 +241,7 @@ impl MacroDef { } rules.push(rule); } - for rule in rules.iter() { + for rule in &rules { validate(&rule.lhs)?; } @@ -268,7 +268,7 @@ impl MacroDef { } impl Rule { - fn parse(src: &mut TtIter, expect_arrow: bool) -> Result { + fn parse(src: &mut TtIter, expect_arrow: bool) -> Result { let lhs = src .expect_subtree() .map_err(|()| ParseError::Expected("expected subtree".to_string()))?; @@ -356,7 +356,7 @@ impl ExpandResult { } pub fn result(self) -> Result { - self.err.map(Err).unwrap_or(Ok(self.value)) + self.err.map_or(Ok(self.value), Err) } } diff --git a/crates/mbe/src/subtree_source.rs b/crates/mbe/src/subtree_source.rs index ee80807ad..ffc2a6017 100644 --- a/crates/mbe/src/subtree_source.rs +++ b/crates/mbe/src/subtree_source.rs @@ -115,7 +115,7 @@ impl<'a> TokenSource for SubtreeTokenSource { fn is_keyword(&self, kw: &str) -> bool { match self.cached.get(self.curr.1) { Some(t) => t.text == *kw, - _ => false, + None => false, } } } diff --git a/crates/mbe/src/syntax_bridge.rs b/crates/mbe/src/syntax_bridge.rs index cdc22425d..7526bd8e6 100644 --- a/crates/mbe/src/syntax_bridge.rs +++ b/crates/mbe/src/syntax_bridge.rs @@ -283,7 +283,7 @@ trait TokenConvertor { let (id, idx) = self.id_alloc().open_delim(range); subtree.delimiter = Some(tt::Delimiter { id, kind }); - while self.peek().map(|it| it.kind() != closed).unwrap_or(false) { + while self.peek().map_or(false, |it| it.kind() != closed) { self.collect_leaf(&mut subtree.token_trees); } let last_range = match self.bump() { diff --git a/crates/mbe/src/tt_iter.rs b/crates/mbe/src/tt_iter.rs index 5a4eca7bf..65da83476 100644 --- a/crates/mbe/src/tt_iter.rs +++ b/crates/mbe/src/tt_iter.rs @@ -121,10 +121,11 @@ impl<'a> TtIter<'a> { parser::parse_fragment(&mut src, &mut sink, fragment_kind); - let mut err = None; - if !sink.cursor.is_root() || sink.error { - err = Some(err!("expected {:?}", fragment_kind)); - } + let mut err = if !sink.cursor.is_root() || sink.error { + Some(err!("expected {:?}", fragment_kind)) + } else { + None + }; let mut curr = buffer.begin(); let mut res = vec![]; -- cgit v1.2.3