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/hir_expand/src/builtin_macro.rs | 6 +++--- crates/hir_expand/src/input.rs | 2 +- crates/hir_expand/src/proc_macro.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/hir_expand/src') diff --git a/crates/hir_expand/src/builtin_macro.rs b/crates/hir_expand/src/builtin_macro.rs index 0b310ba2f..51572226e 100644 --- a/crates/hir_expand/src/builtin_macro.rs +++ b/crates/hir_expand/src/builtin_macro.rs @@ -354,7 +354,7 @@ fn concat_expand( // concat works with string and char literals, so remove any quotes. // It also works with integer, float and boolean literals, so just use the rest // as-is. - let component = unquote_str(&it).unwrap_or_else(|| it.text.to_string()); + let component = unquote_str(it).unwrap_or_else(|| it.text.to_string()); text.push_str(&component); } // handle boolean literals @@ -417,7 +417,7 @@ fn parse_string(tt: &tt::Subtree) -> Result { tt.token_trees .get(0) .and_then(|tt| match tt { - tt::TokenTree::Leaf(tt::Leaf::Literal(it)) => unquote_str(&it), + tt::TokenTree::Leaf(tt::Leaf::Literal(it)) => unquote_str(it), _ => None, }) .ok_or_else(|| mbe::ExpandError::ConversionError) @@ -561,7 +561,7 @@ mod tests { use syntax::ast::NameOwner; fn expand_builtin_macro(ra_fixture: &str) -> String { - let (db, file_id) = TestDB::with_single_file(&ra_fixture); + let (db, file_id) = TestDB::with_single_file(ra_fixture); let parsed = db.parse(file_id); let mut macro_rules: Vec<_> = parsed.syntax_node().descendants().filter_map(ast::MacroRules::cast).collect(); diff --git a/crates/hir_expand/src/input.rs b/crates/hir_expand/src/input.rs index 82dc7f326..bc3ecc593 100644 --- a/crates/hir_expand/src/input.rs +++ b/crates/hir_expand/src/input.rs @@ -78,7 +78,7 @@ mod tests { use super::*; fn test_remove_derives_up_to(attr: usize, ra_fixture: &str, expect: Expect) { - let (db, file_id) = TestDB::with_single_file(&ra_fixture); + let (db, file_id) = TestDB::with_single_file(ra_fixture); let parsed = db.parse(file_id); let mut items: Vec<_> = diff --git a/crates/hir_expand/src/proc_macro.rs b/crates/hir_expand/src/proc_macro.rs index dbe1b446e..3ad2d3bf7 100644 --- a/crates/hir_expand/src/proc_macro.rs +++ b/crates/hir_expand/src/proc_macro.rs @@ -51,7 +51,7 @@ impl ProcMacroExpander { // Proc macros have access to the environment variables of the invoking crate. let env = &krate_graph[calling_crate].env; - proc_macro.expander.expand(&tt, attr_arg, &env).map_err(mbe::ExpandError::from) + proc_macro.expander.expand(tt, attr_arg, env).map_err(mbe::ExpandError::from) } None => Err(mbe::ExpandError::UnresolvedProcMacro), } -- cgit v1.2.3 From 6cc6dee9e96d55dbbd8593523551a9981a691147 Mon Sep 17 00:00:00 2001 From: Maan2003 Date: Sun, 13 Jun 2021 09:25:55 +0530 Subject: clippy::useless_conversion --- crates/hir_expand/src/builtin_derive.rs | 2 +- crates/hir_expand/src/builtin_macro.rs | 8 ++++---- crates/hir_expand/src/db.rs | 2 +- crates/hir_expand/src/eager.rs | 8 +++----- 4 files changed, 9 insertions(+), 11 deletions(-) (limited to 'crates/hir_expand/src') diff --git a/crates/hir_expand/src/builtin_derive.rs b/crates/hir_expand/src/builtin_derive.rs index fe9497b50..4610f6f91 100644 --- a/crates/hir_expand/src/builtin_derive.rs +++ b/crates/hir_expand/src/builtin_derive.rs @@ -325,7 +325,7 @@ $0 }, }; - let id: MacroCallId = db.intern_macro(loc).into(); + let id: MacroCallId = db.intern_macro(loc); let parsed = db.parse_or_expand(id.as_file()).unwrap(); // FIXME text() for syntax nodes parsed from token tree looks weird diff --git a/crates/hir_expand/src/builtin_macro.rs b/crates/hir_expand/src/builtin_macro.rs index 51572226e..f24d1d919 100644 --- a/crates/hir_expand/src/builtin_macro.rs +++ b/crates/hir_expand/src/builtin_macro.rs @@ -430,7 +430,7 @@ fn include_expand( ) -> ExpandResult> { let res = (|| { let path = parse_string(tt)?; - let file_id = relative_file(db, arg_id.into(), &path, false)?; + let file_id = relative_file(db, arg_id, &path, false)?; let subtree = parse_to_token_tree(&db.file_text(file_id)) .ok_or_else(|| mbe::ExpandError::ConversionError)? @@ -480,7 +480,7 @@ fn include_str_expand( // it's unusual to `include_str!` a Rust file), but we can return an empty string. // Ideally, we'd be able to offer a precise expansion if the user asks for macro // expansion. - let file_id = match relative_file(db, arg_id.into(), &path, true) { + let file_id = match relative_file(db, arg_id, &path, true) { Ok(file_id) => file_id, Err(_) => { return ExpandResult::ok(Some(ExpandedEager::new(quote!("")))); @@ -598,7 +598,7 @@ mod tests { }, }; - let id: MacroCallId = db.intern_macro(loc).into(); + let id: MacroCallId = db.intern_macro(loc); id.as_file() } Either::Right(expander) => { @@ -635,7 +635,7 @@ mod tests { kind: MacroCallKind::FnLike { ast_id: call_id, fragment }, }; - let id: MacroCallId = db.intern_macro(loc).into(); + let id: MacroCallId = db.intern_macro(loc); id.as_file() } }; diff --git a/crates/hir_expand/src/db.rs b/crates/hir_expand/src/db.rs index 45e6e446a..4aecf4af5 100644 --- a/crates/hir_expand/src/db.rs +++ b/crates/hir_expand/src/db.rs @@ -57,7 +57,7 @@ impl TokenExpander { // We store the result in salsa db to prevent non-deterministic behavior in // some proc-macro implementation // See #4315 for details - db.expand_proc_macro(id.into()).into() + db.expand_proc_macro(id).into() } } } diff --git a/crates/hir_expand/src/eager.rs b/crates/hir_expand/src/eager.rs index 9093255f4..07799ed2f 100644 --- a/crates/hir_expand/src/eager.rs +++ b/crates/hir_expand/src/eager.rs @@ -128,7 +128,7 @@ pub fn expand_eager_macro( }), kind: MacroCallKind::FnLike { ast_id: call_id, fragment: FragmentKind::Expr }, }); - let arg_file_id: MacroCallId = arg_id.into(); + let arg_file_id: MacroCallId = arg_id; let parsed_args = diagnostic_sink.result(mbe::token_tree_to_syntax_node(&parsed_args, FragmentKind::Expr))?.0; @@ -182,8 +182,7 @@ fn lazy_expand( db, krate, MacroCallKind::FnLike { ast_id: macro_call.with_value(ast_id), fragment }, - ) - .into(); + ); let err = db.macro_expand_error(id); let value = db.parse_or_expand(id.as_file()).map(|node| InFile::new(id.as_file(), node)); @@ -216,8 +215,7 @@ fn eager_macro_recur( def, macro_resolver, diagnostic_sink, - )? - .into(); + )?; db.parse_or_expand(id.as_file()) .expect("successful macro expansion should be parseable") .clone_for_update() -- cgit v1.2.3 From 705f7e6e2644bf5de4255bc05ea8d9d5027c29b0 Mon Sep 17 00:00:00 2001 From: Maan2003 Date: Sun, 13 Jun 2021 09:27:19 +0530 Subject: clippy::clone_on_copy --- crates/hir_expand/src/proc_macro.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'crates/hir_expand/src') diff --git a/crates/hir_expand/src/proc_macro.rs b/crates/hir_expand/src/proc_macro.rs index 3ad2d3bf7..025e10239 100644 --- a/crates/hir_expand/src/proc_macro.rs +++ b/crates/hir_expand/src/proc_macro.rs @@ -45,7 +45,6 @@ impl ProcMacroExpander { let proc_macro = krate_graph[self.krate] .proc_macro .get(id.0 as usize) - .clone() .ok_or_else(|| err!("No derive macro found."))?; // Proc macros have access to the environment variables of the invoking crate. -- cgit v1.2.3 From c50b4579ec842ac7c1f52e0e3c834d50fc9cd1bb Mon Sep 17 00:00:00 2001 From: Maan2003 Date: Sun, 13 Jun 2021 09:35:29 +0530 Subject: clippy::useless_return --- crates/hir_expand/src/db.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/hir_expand/src') diff --git a/crates/hir_expand/src/db.rs b/crates/hir_expand/src/db.rs index 4aecf4af5..66f44202b 100644 --- a/crates/hir_expand/src/db.rs +++ b/crates/hir_expand/src/db.rs @@ -241,7 +241,7 @@ fn parse_macro_expansion( } }; if is_self_replicating(&node, &call_node.value) { - return ExpandResult::only_err(err); + ExpandResult::only_err(err) } else { ExpandResult { value: Some((parse, Arc::new(rev_token_map))), err: Some(err) } } -- cgit v1.2.3 From 5ac6804bb3a07b959e8c2c3534255a8d6bb4948c Mon Sep 17 00:00:00 2001 From: Maan2003 Date: Sun, 13 Jun 2021 09:48:15 +0530 Subject: cargo fmt --- crates/hir_expand/src/eager.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'crates/hir_expand/src') diff --git a/crates/hir_expand/src/eager.rs b/crates/hir_expand/src/eager.rs index 07799ed2f..ddafaddf7 100644 --- a/crates/hir_expand/src/eager.rs +++ b/crates/hir_expand/src/eager.rs @@ -177,12 +177,11 @@ fn lazy_expand( let ast_id = db.ast_id_map(macro_call.file_id).ast_id(¯o_call.value); let fragment = crate::to_fragment_kind(¯o_call.value); - let id: MacroCallId = def - .as_lazy_macro( - db, - krate, - MacroCallKind::FnLike { ast_id: macro_call.with_value(ast_id), fragment }, - ); + let id: MacroCallId = def.as_lazy_macro( + db, + krate, + MacroCallKind::FnLike { ast_id: macro_call.with_value(ast_id), fragment }, + ); let err = db.macro_expand_error(id); let value = db.parse_or_expand(id.as_file()).map(|node| InFile::new(id.as_file(), node)); -- cgit v1.2.3