From 966c23f5290275ce17564f6027a17ec20cd6078f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Wed, 17 Mar 2021 01:27:56 +0100 Subject: avoid converting types into themselves via .into() (clippy::useless-conversion) example: let x: String = String::from("hello world").into(); --- crates/mbe/src/benchmark.rs | 18 ++++++++---------- crates/mbe/src/expander/matcher.rs | 2 +- crates/mbe/src/syntax_bridge.rs | 4 ++-- crates/mbe/src/tests.rs | 2 +- 4 files changed, 12 insertions(+), 14 deletions(-) (limited to 'crates/mbe/src') diff --git a/crates/mbe/src/benchmark.rs b/crates/mbe/src/benchmark.rs index 503ad1355..bd8ea6452 100644 --- a/crates/mbe/src/benchmark.rs +++ b/crates/mbe/src/benchmark.rs @@ -120,7 +120,7 @@ fn invocation_fixtures(rules: &FxHashMap) -> Vec<(String, tt Some("pat") => parent.token_trees.push(make_ident("foo")), Some("path") => parent.token_trees.push(make_ident("foo")), Some("literal") => parent.token_trees.push(make_literal("1")), - Some("expr") => parent.token_trees.push(make_ident("foo").into()), + Some("expr") => parent.token_trees.push(make_ident("foo")), Some("lifetime") => { parent.token_trees.push(make_punct('\'')); parent.token_trees.push(make_ident("a")); @@ -157,17 +157,15 @@ fn invocation_fixtures(rules: &FxHashMap) -> Vec<(String, tt if i + 1 != cnt { if let Some(sep) = separator { match sep { - Separator::Literal(it) => parent - .token_trees - .push(tt::Leaf::Literal(it.clone().into()).into()), - Separator::Ident(it) => parent - .token_trees - .push(tt::Leaf::Ident(it.clone().into()).into()), + Separator::Literal(it) => { + parent.token_trees.push(tt::Leaf::Literal(it.clone()).into()) + } + Separator::Ident(it) => { + parent.token_trees.push(tt::Leaf::Ident(it.clone()).into()) + } Separator::Puncts(puncts) => { for it in puncts { - parent - .token_trees - .push(tt::Leaf::Punct(it.clone().into()).into()) + parent.token_trees.push(tt::Leaf::Punct(it.clone()).into()) } } }; diff --git a/crates/mbe/src/expander/matcher.rs b/crates/mbe/src/expander/matcher.rs index 2c69e8968..1bf7c2e81 100644 --- a/crates/mbe/src/expander/matcher.rs +++ b/crates/mbe/src/expander/matcher.rs @@ -722,7 +722,7 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> ExpandResult Some(lit.into()), Some(neg) => Some(tt::TokenTree::Subtree(tt::Subtree { 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 { res.push(match expanded.value { None => break, Some(tt @ tt::TokenTree::Leaf(_)) => { - tt::Subtree { delimiter: None, token_trees: vec![tt.into()] } + tt::Subtree { delimiter: None, token_trees: vec![tt] } } Some(tt::TokenTree::Subtree(tt)) => tt, }); @@ -727,7 +727,7 @@ impl<'a> TreeSink for TtTreeSink<'a> { // Note: We always assume the semi-colon would be the last token in // other parts of RA such that we don't add whitespace here. if curr.spacing == tt::Spacing::Alone && curr.char != ';' { - self.inner.token(WHITESPACE, " ".into()); + self.inner.token(WHITESPACE, " "); self.text_pos += TextSize::of(' '); } } 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 { fn test_invalid_arms() { fn check(macro_body: &str, err: ParseError) { let m = parse_macro_arm(macro_body); - assert_eq!(m, Err(err.into())); + assert_eq!(m, Err(err)); } check("invalid", ParseError::Expected("expected subtree".into())); -- cgit v1.2.3 From c5d654d5132b702d028ed00b5ec5c654a0b4a2fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Wed, 17 Mar 2021 01:39:58 +0100 Subject: use if let Some(x) instead of if x.is_some() and x.unwrap() (clippy::unnecessary-unwrap) --- crates/mbe/src/expander/matcher.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'crates/mbe/src') diff --git a/crates/mbe/src/expander/matcher.rs b/crates/mbe/src/expander/matcher.rs index 1bf7c2e81..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 { let mut src = TtIter::new(src); let mut stack: SmallVec<[TtIter; 1]> = SmallVec::new(); let mut res = Match::default(); - let mut error_reover_item = None; + let mut error_recover_item = None; let mut bindings_builder = BindingsBuilder::default(); @@ -579,9 +579,9 @@ fn match_loop(pattern: &MetaTemplate, src: &tt::Subtree) -> Match { stdx::always!(cur_items.is_empty()); if error_items.len() > 0 { - error_reover_item = error_items.pop().map(|it| it.bindings); + error_recover_item = error_items.pop().map(|it| it.bindings); } else if eof_items.len() > 0 { - error_reover_item = Some(eof_items[0].bindings.clone()); + error_recover_item = Some(eof_items[0].bindings.clone()); } // 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 { res.bindings = bindings_builder.build(&eof_items[0].bindings); } else { // Error recovery - if error_reover_item.is_some() { - res.bindings = bindings_builder.build(&error_reover_item.unwrap()); + if let Some(item) = error_recover_item { + res.bindings = bindings_builder.build(&item); } res.add_err(ExpandError::UnexpectedToken); } @@ -618,7 +618,7 @@ fn match_loop(pattern: &MetaTemplate, src: &tt::Subtree) -> Match { } res.add_err(err!("leftover tokens")); - if let Some(error_reover_item) = error_reover_item { + if let Some(error_reover_item) = error_recover_item { res.bindings = bindings_builder.build(&error_reover_item); } return res; -- cgit v1.2.3 From 048dad8c2e86006e53b3a134279729efb28b9e32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Wed, 17 Mar 2021 01:56:31 +0100 Subject: don't clone types that are copy (clippy::clone_on_copy) --- crates/mbe/src/benchmark.rs | 5 ++--- crates/mbe/src/parser.rs | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'crates/mbe/src') diff --git a/crates/mbe/src/benchmark.rs b/crates/mbe/src/benchmark.rs index bd8ea6452..ba814a2e1 100644 --- a/crates/mbe/src/benchmark.rs +++ b/crates/mbe/src/benchmark.rs @@ -165,7 +165,7 @@ fn invocation_fixtures(rules: &FxHashMap) -> Vec<(String, tt } Separator::Puncts(puncts) => { for it in puncts { - parent.token_trees.push(tt::Leaf::Punct(it.clone()).into()) + parent.token_trees.push(tt::Leaf::Punct(*it).into()) } } }; @@ -174,8 +174,7 @@ fn invocation_fixtures(rules: &FxHashMap) -> Vec<(String, tt } } Op::Subtree { tokens, delimiter } => { - let mut subtree = - tt::Subtree { delimiter: delimiter.clone(), token_trees: Vec::new() }; + let mut subtree = tt::Subtree { delimiter: *delimiter, token_trees: Vec::new() }; tokens.iter().for_each(|it| { collect_from_op(it, &mut subtree, seed); }); 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, RepeatKind), Par if puncts.len() == 3 { return Err(ParseError::InvalidRepeat); } - puncts.push(punct.clone()) + puncts.push(*punct) } _ => return Err(ParseError::InvalidRepeat), } -- cgit v1.2.3