From c9b4ac5be4daaabc062ab1ee663eba8594750003 Mon Sep 17 00:00:00 2001 From: Maan2003 Date: Sun, 13 Jun 2021 09:24:16 +0530 Subject: clippy::redudant_borrow --- crates/mbe/src/expander/matcher.rs | 20 ++++++++++---------- crates/mbe/src/expander/transcriber.rs | 8 ++++---- crates/mbe/src/lib.rs | 6 +++--- crates/mbe/src/parser.rs | 14 +++++++------- crates/mbe/src/subtree_source.rs | 6 +++--- crates/mbe/src/syntax_bridge.rs | 2 +- crates/mbe/src/tests/expand.rs | 2 +- crates/mbe/src/tt_iter.rs | 2 +- 8 files changed, 30 insertions(+), 30 deletions(-) (limited to 'crates/mbe/src') diff --git a/crates/mbe/src/expander/matcher.rs b/crates/mbe/src/expander/matcher.rs index c982eb58f..c0e1705c0 100644 --- a/crates/mbe/src/expander/matcher.rs +++ b/crates/mbe/src/expander/matcher.rs @@ -121,7 +121,7 @@ impl Match { /// Matching errors are added to the `Match`. pub(super) fn match_(pattern: &MetaTemplate, input: &tt::Subtree) -> Match { - let mut res = match_loop(pattern, &input); + let mut res = match_loop(pattern, input); res.bound_count = count(res.bindings.bindings()); return res; @@ -202,7 +202,7 @@ impl BindingsBuilder { } fn push_nested(&mut self, parent: &mut BindingsIdx, child: &BindingsIdx) { - let BindingsIdx(idx, nidx) = self.copy(&child); + let BindingsIdx(idx, nidx) = self.copy(child); self.nodes[parent.0].push(LinkNode::Node(Rc::new(BindingKind::Nested(idx, nidx)))); } @@ -221,7 +221,7 @@ impl BindingsBuilder { fn build_inner(&self, bindings: &mut Bindings, link_nodes: &[LinkNode>]) { let mut nodes = Vec::new(); - self.collect_nodes(&link_nodes, &mut nodes); + self.collect_nodes(link_nodes, &mut nodes); for cmd in nodes { match &**cmd { @@ -282,7 +282,7 @@ impl BindingsBuilder { nested_refs.into_iter().for_each(|iter| { let mut child_bindings = Bindings::default(); - self.build_inner(&mut child_bindings, &iter); + self.build_inner(&mut child_bindings, iter); nested.push(child_bindings) }) } @@ -417,7 +417,7 @@ fn match_loop_inner<'t>( let sep_len = item.sep.as_ref().map_or(0, Separator::tt_count); if item.sep.is_some() && sep_idx != sep_len { let sep = item.sep.as_ref().unwrap(); - if src.clone().expect_separator(&sep, sep_idx) { + if src.clone().expect_separator(sep, sep_idx) { item.dot.next(); item.sep_parsed = Some(sep_idx + 1); try_push!(next_items, item); @@ -487,7 +487,7 @@ fn match_loop_inner<'t>( item.meta_result = Some((fork, match_res)); try_push!(bb_items, item); } else { - bindings_builder.push_optional(&mut item.bindings, &name); + bindings_builder.push_optional(&mut item.bindings, name); item.dot.next(); cur_items.push(item); } @@ -495,7 +495,7 @@ fn match_loop_inner<'t>( Some(err) => { res.add_err(err); if let Some(fragment) = match_res.value { - bindings_builder.push_fragment(&mut item.bindings, &name, fragment); + bindings_builder.push_fragment(&mut item.bindings, name, fragment); } item.is_error = true; error_items.push(item); @@ -504,7 +504,7 @@ fn match_loop_inner<'t>( } } OpDelimited::Op(Op::Leaf(leaf)) => { - if let Err(err) = match_leaf(&leaf, &mut src.clone()) { + if let Err(err) = match_leaf(leaf, &mut src.clone()) { res.add_err(err); item.is_error = true; } else { @@ -640,10 +640,10 @@ fn match_loop(pattern: &MetaTemplate, src: &tt::Subtree) -> Match { let (iter, match_res) = item.meta_result.take().unwrap(); match match_res.value { Some(fragment) => { - bindings_builder.push_fragment(&mut item.bindings, &name, fragment); + bindings_builder.push_fragment(&mut item.bindings, name, fragment); } None if match_res.err.is_none() => { - bindings_builder.push_optional(&mut item.bindings, &name); + bindings_builder.push_optional(&mut item.bindings, name); } _ => {} } diff --git a/crates/mbe/src/expander/transcriber.rs b/crates/mbe/src/expander/transcriber.rs index dd7fa97d7..9a9c1a467 100644 --- a/crates/mbe/src/expander/transcriber.rs +++ b/crates/mbe/src/expander/transcriber.rs @@ -55,7 +55,7 @@ pub(super) fn transcribe( template: &MetaTemplate, bindings: &Bindings, ) -> ExpandResult { - let mut ctx = ExpandCtx { bindings: &bindings, nesting: Vec::new() }; + let mut ctx = ExpandCtx { bindings: bindings, nesting: Vec::new() }; let mut arena: Vec = Vec::new(); expand_subtree(&mut ctx, template, None, &mut arena) } @@ -91,12 +91,12 @@ fn expand_subtree( Op::Leaf(tt) => arena.push(tt.clone().into()), Op::Subtree { tokens, delimiter } => { let ExpandResult { value: tt, err: e } = - expand_subtree(ctx, &tokens, *delimiter, arena); + expand_subtree(ctx, tokens, *delimiter, arena); err = err.or(e); arena.push(tt.into()); } Op::Var { name, id, .. } => { - let ExpandResult { value: fragment, err: e } = expand_var(ctx, &name, *id); + let ExpandResult { value: fragment, err: e } = expand_var(ctx, name, *id); err = err.or(e); push_fragment(arena, fragment); } @@ -141,7 +141,7 @@ fn expand_var(ctx: &mut ExpandCtx, v: &SmolStr, id: tt::TokenId) -> ExpandResult .into(); ExpandResult::ok(Fragment::Tokens(tt)) } else { - ctx.bindings.get(&v, &mut ctx.nesting).map_or_else( + ctx.bindings.get(v, &mut ctx.nesting).map_or_else( |e| ExpandResult { value: Fragment::Tokens(tt::TokenTree::empty()), err: Some(e) }, |b| ExpandResult::ok(b.clone()), ) diff --git a/crates/mbe/src/lib.rs b/crates/mbe/src/lib.rs index 380a50744..8c8528aaf 100644 --- a/crates/mbe/src/lib.rs +++ b/crates/mbe/src/lib.rs @@ -280,8 +280,8 @@ impl Rule { .expect_subtree() .map_err(|()| ParseError::Expected("expected subtree".to_string()))?; - let lhs = MetaTemplate(parse_pattern(&lhs)?); - let rhs = MetaTemplate(parse_template(&rhs)?); + let lhs = MetaTemplate(parse_pattern(lhs)?); + let rhs = MetaTemplate(parse_template(rhs)?); Ok(crate::Rule { lhs, rhs }) } @@ -290,7 +290,7 @@ impl Rule { fn validate(pattern: &MetaTemplate) -> Result<(), ParseError> { for op in pattern.iter() { match op { - Op::Subtree { tokens, .. } => validate(&tokens)?, + Op::Subtree { tokens, .. } => validate(tokens)?, Op::Repeat { tokens: subtree, separator, .. } => { // Checks that no repetition which could match an empty token // https://github.com/rust-lang/rust/blob/a58b1ed44f5e06976de2bdc4d7dc81c36a96934f/src/librustc_expand/mbe/macro_rules.rs#L558 diff --git a/crates/mbe/src/parser.rs b/crates/mbe/src/parser.rs index 04c0d3e75..deed884d2 100644 --- a/crates/mbe/src/parser.rs +++ b/crates/mbe/src/parser.rs @@ -42,7 +42,7 @@ impl<'a> OpDelimitedIter<'a> { } pub(crate) fn reset(&self) -> Self { - Self { inner: &self.inner, idx: 0, delimited: self.delimited } + Self { inner: self.inner, idx: 0, delimited: self.delimited } } } @@ -126,11 +126,11 @@ impl Separator { } pub(crate) fn parse_template(template: &tt::Subtree) -> Result, ParseError> { - parse_inner(&template, Mode::Template).into_iter().collect() + parse_inner(template, Mode::Template).into_iter().collect() } pub(crate) fn parse_pattern(pattern: &tt::Subtree) -> Result, ParseError> { - parse_inner(&pattern, Mode::Pattern).into_iter().collect() + parse_inner(pattern, Mode::Pattern).into_iter().collect() } #[derive(Clone, Copy)] @@ -140,7 +140,7 @@ enum Mode { } fn parse_inner(tt: &tt::Subtree, mode: Mode) -> Vec> { - let mut src = TtIter::new(&tt); + let mut src = TtIter::new(tt); std::iter::from_fn(move || { let first = src.next()?; Some(next_op(first, &mut src, mode)) @@ -171,7 +171,7 @@ fn next_op<'a>(first: &tt::TokenTree, src: &mut TtIter<'a>, mode: Mode) -> Resul match second { tt::TokenTree::Subtree(subtree) => { let (separator, kind) = parse_repeat(src)?; - let tokens = parse_inner(&subtree, mode) + let tokens = parse_inner(subtree, mode) .into_iter() .collect::, ParseError>>()?; Op::Repeat { tokens: MetaTemplate(tokens), separator, kind } @@ -191,7 +191,7 @@ fn next_op<'a>(first: &tt::TokenTree, src: &mut TtIter<'a>, mode: Mode) -> Resul Op::Var { name, kind, id } } tt::Leaf::Literal(lit) => { - if is_boolean_literal(&lit) { + if is_boolean_literal(lit) { let name = lit.text.clone(); let kind = eat_fragment_kind(src, mode)?; let id = lit.id; @@ -206,7 +206,7 @@ fn next_op<'a>(first: &tt::TokenTree, src: &mut TtIter<'a>, mode: Mode) -> Resul tt::TokenTree::Leaf(tt) => Op::Leaf(tt.clone()), tt::TokenTree::Subtree(subtree) => { let tokens = - parse_inner(&subtree, mode).into_iter().collect::, ParseError>>()?; + parse_inner(subtree, mode).into_iter().collect::, ParseError>>()?; Op::Subtree { tokens: MetaTemplate(tokens), delimiter: subtree.delimiter } } }; diff --git a/crates/mbe/src/subtree_source.rs b/crates/mbe/src/subtree_source.rs index bde370fdb..ee80807ad 100644 --- a/crates/mbe/src/subtree_source.rs +++ b/crates/mbe/src/subtree_source.rs @@ -22,7 +22,7 @@ impl<'a> SubtreeTokenSource { #[cfg(test)] pub(crate) fn text(&self) -> SmolStr { match self.cached.get(self.curr.1) { - Some(ref tt) => tt.text.clone(), + Some(tt) => tt.text.clone(), _ => SmolStr::new(""), } } @@ -59,7 +59,7 @@ impl<'a> SubtreeTokenSource { current = match tt { Some(tt::buffer::TokenTreeRef::Leaf(leaf, _)) => { - cached.push(convert_leaf(&leaf)); + cached.push(convert_leaf(leaf)); cursor.bump() } Some(tt::buffer::TokenTreeRef::Subtree(subtree, _)) => { @@ -114,7 +114,7 @@ impl<'a> TokenSource for SubtreeTokenSource { /// Is the current token a specified keyword? fn is_keyword(&self, kw: &str) -> bool { match self.cached.get(self.curr.1) { - Some(ref t) => t.text == *kw, + Some(t) => t.text == *kw, _ => false, } } diff --git a/crates/mbe/src/syntax_bridge.rs b/crates/mbe/src/syntax_bridge.rs index 978c75747..cdc22425d 100644 --- a/crates/mbe/src/syntax_bridge.rs +++ b/crates/mbe/src/syntax_bridge.rs @@ -633,7 +633,7 @@ impl<'a> TreeSink for TtTreeSink<'a> { } } }; - self.buf += &text; + self.buf += text; self.text_pos += TextSize::of(text); } diff --git a/crates/mbe/src/tests/expand.rs b/crates/mbe/src/tests/expand.rs index 75c88687c..c788e427e 100644 --- a/crates/mbe/src/tests/expand.rs +++ b/crates/mbe/src/tests/expand.rs @@ -490,7 +490,7 @@ MACRO_ITEMS@0..40 fn to_subtree(tt: &tt::TokenTree) -> &tt::Subtree { if let tt::TokenTree::Subtree(subtree) = tt { - return &subtree; + return subtree; } unreachable!("It is not a subtree"); } diff --git a/crates/mbe/src/tt_iter.rs b/crates/mbe/src/tt_iter.rs index bd54f2442..5a4eca7bf 100644 --- a/crates/mbe/src/tt_iter.rs +++ b/crates/mbe/src/tt_iter.rs @@ -115,7 +115,7 @@ impl<'a> TtIter<'a> { } } - let buffer = TokenBuffer::from_tokens(&self.inner.as_slice()); + let buffer = TokenBuffer::from_tokens(self.inner.as_slice()); let mut src = SubtreeTokenSource::new(&buffer); let mut sink = OffsetTokenSink { cursor: buffer.begin(), error: false }; -- cgit v1.2.3