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/ide_assists/src/handlers/convert_comment_block.rs | 4 ++-- crates/ide_assists/src/handlers/early_return.rs | 4 ++-- crates/ide_assists/src/handlers/extract_function.rs | 8 ++++---- crates/ide_assists/src/handlers/fill_match_arms.rs | 4 ++-- crates/ide_assists/src/handlers/fix_visibility.rs | 2 +- crates/ide_assists/src/handlers/generate_enum_is_method.rs | 2 +- .../ide_assists/src/handlers/generate_enum_projection_method.rs | 2 +- crates/ide_assists/src/handlers/generate_function.rs | 8 ++++---- crates/ide_assists/src/handlers/generate_getter.rs | 2 +- crates/ide_assists/src/handlers/generate_new.rs | 2 +- crates/ide_assists/src/handlers/generate_setter.rs | 2 +- crates/ide_assists/src/handlers/remove_dbg.rs | 2 +- crates/ide_assists/src/handlers/reorder_fields.rs | 2 +- .../ide_assists/src/handlers/replace_derive_with_manual_impl.rs | 2 +- crates/ide_assists/src/handlers/replace_if_let_with_match.rs | 2 +- crates/ide_assists/src/handlers/wrap_return_type_in_result.rs | 2 +- crates/ide_assists/src/tests.rs | 2 +- crates/ide_assists/src/utils.rs | 2 +- crates/ide_assists/src/utils/suggest_name.rs | 2 +- 19 files changed, 28 insertions(+), 28 deletions(-) (limited to 'crates/ide_assists') diff --git a/crates/ide_assists/src/handlers/convert_comment_block.rs b/crates/ide_assists/src/handlers/convert_comment_block.rs index d202a85f9..749e8685b 100644 --- a/crates/ide_assists/src/handlers/convert_comment_block.rs +++ b/crates/ide_assists/src/handlers/convert_comment_block.rs @@ -88,7 +88,7 @@ fn line_to_block(acc: &mut Assists, comment: ast::Comment) -> Option<()> { // We pick a single indentation level for the whole block comment based on the // comment where the assist was invoked. This will be prepended to the // contents of each line comment when they're put into the block comment. - let indentation = IndentLevel::from_token(&comment.syntax()); + let indentation = IndentLevel::from_token(comment.syntax()); let block_comment_body = comments.into_iter().map(|c| line_comment_text(indentation, c)).join("\n"); @@ -167,7 +167,7 @@ fn line_comment_text(indentation: IndentLevel, comm: ast::Comment) -> String { if contents.is_empty() { contents.to_owned() } else { - indentation.to_string() + &contents + indentation.to_string() + contents } } diff --git a/crates/ide_assists/src/handlers/early_return.rs b/crates/ide_assists/src/handlers/early_return.rs index 5eb6a57f0..ef4a7cb50 100644 --- a/crates/ide_assists/src/handlers/early_return.rs +++ b/crates/ide_assists/src/handlers/early_return.rs @@ -108,7 +108,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext) "Convert to guarded return", target, |edit| { - let if_indent_level = IndentLevel::from_node(&if_expr.syntax()); + let if_indent_level = IndentLevel::from_node(if_expr.syntax()); let new_block = match if_let_pat { None => { // If. @@ -174,7 +174,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext) .take_while(|i| *i != end_of_then), ); replace_children( - &parent_block.syntax(), + parent_block.syntax(), RangeInclusive::new( if_expr.clone().syntax().clone().into(), if_expr.syntax().clone().into(), diff --git a/crates/ide_assists/src/handlers/extract_function.rs b/crates/ide_assists/src/handlers/extract_function.rs index a2dba915c..63d28480a 100644 --- a/crates/ide_assists/src/handlers/extract_function.rs +++ b/crates/ide_assists/src/handlers/extract_function.rs @@ -76,7 +76,7 @@ pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext) -> Option let module = ctx.sema.scope(&insert_after).module()?; let vars_defined_in_body_and_outlive = - vars_defined_in_body_and_outlive(ctx, &body, &node.parent().as_ref().unwrap_or(&node)); + vars_defined_in_body_and_outlive(ctx, &body, node.parent().as_ref().unwrap_or(&node)); let ret_ty = body_return_ty(ctx, &body)?; // FIXME: we compute variables that outlive here just to check `never!` condition @@ -808,7 +808,7 @@ trait HasTokenAtOffset { impl HasTokenAtOffset for SyntaxNode { fn token_at_offset(&self, offset: TextSize) -> TokenAtOffset { - SyntaxNode::token_at_offset(&self, offset) + SyntaxNode::token_at_offset(self, offset) } } @@ -854,7 +854,7 @@ fn vars_defined_in_body_and_outlive( body: &FunctionBody, parent: &SyntaxNode, ) -> Vec { - let vars_defined_in_body = vars_defined_in_body(&body, ctx); + let vars_defined_in_body = vars_defined_in_body(body, ctx); vars_defined_in_body .into_iter() .filter_map(|var| var_outlives_body(ctx, body, var, parent)) @@ -868,7 +868,7 @@ fn is_defined_before( src: &hir::InFile>, ) -> bool { src.file_id.original_file(ctx.db()) == ctx.frange.file_id - && !body.contains_node(&either_syntax(&src.value)) + && !body.contains_node(either_syntax(&src.value)) } fn either_syntax(value: &Either) -> &SyntaxNode { diff --git a/crates/ide_assists/src/handlers/fill_match_arms.rs b/crates/ide_assists/src/handlers/fill_match_arms.rs index 3d2cd739a..c8bc923f5 100644 --- a/crates/ide_assists/src/handlers/fill_match_arms.rs +++ b/crates/ide_assists/src/handlers/fill_match_arms.rs @@ -212,7 +212,7 @@ impl ExtendedEnum { } fn resolve_enum_def(sema: &Semantics, expr: &ast::Expr) -> Option { - sema.type_of_expr(&expr)?.autoderef(sema.db).find_map(|ty| match ty.as_adt() { + sema.type_of_expr(expr)?.autoderef(sema.db).find_map(|ty| match ty.as_adt() { Some(Adt::Enum(e)) => Some(ExtendedEnum::Enum(e)), _ => { if ty.is_bool() { @@ -228,7 +228,7 @@ fn resolve_tuple_of_enum_def( sema: &Semantics, expr: &ast::Expr, ) -> Option> { - sema.type_of_expr(&expr)? + sema.type_of_expr(expr)? .tuple_fields(sema.db) .iter() .map(|ty| { diff --git a/crates/ide_assists/src/handlers/fix_visibility.rs b/crates/ide_assists/src/handlers/fix_visibility.rs index 89f7b2c2c..9b432e92f 100644 --- a/crates/ide_assists/src/handlers/fix_visibility.rs +++ b/crates/ide_assists/src/handlers/fix_visibility.rs @@ -43,7 +43,7 @@ fn add_vis_to_referenced_module_def(acc: &mut Assists, ctx: &AssistContext) -> O _ => return None, }; - let current_module = ctx.sema.scope(&path.syntax()).module()?; + let current_module = ctx.sema.scope(path.syntax()).module()?; let target_module = def.module(ctx.db())?; let vis = target_module.visibility_of(ctx.db(), &def)?; diff --git a/crates/ide_assists/src/handlers/generate_enum_is_method.rs b/crates/ide_assists/src/handlers/generate_enum_is_method.rs index a9f71a703..24939f262 100644 --- a/crates/ide_assists/src/handlers/generate_enum_is_method.rs +++ b/crates/ide_assists/src/handlers/generate_enum_is_method.rs @@ -47,7 +47,7 @@ pub(crate) fn generate_enum_is_method(acc: &mut Assists, ctx: &AssistContext) -> let fn_name = format!("is_{}", &to_lower_snake_case(&variant_name.text())); // Return early if we've found an existing new fn - let impl_def = find_struct_impl(&ctx, &parent_enum, &fn_name)?; + let impl_def = find_struct_impl(ctx, &parent_enum, &fn_name)?; let target = variant.syntax().text_range(); acc.add( diff --git a/crates/ide_assists/src/handlers/generate_enum_projection_method.rs b/crates/ide_assists/src/handlers/generate_enum_projection_method.rs index e2f572ba3..986fb2315 100644 --- a/crates/ide_assists/src/handlers/generate_enum_projection_method.rs +++ b/crates/ide_assists/src/handlers/generate_enum_projection_method.rs @@ -136,7 +136,7 @@ fn generate_enum_projection_method( format!("{}_{}", props.fn_name_prefix, &to_lower_snake_case(&variant_name.text())); // Return early if we've found an existing new fn - let impl_def = find_struct_impl(&ctx, &parent_enum, &fn_name)?; + let impl_def = find_struct_impl(ctx, &parent_enum, &fn_name)?; let target = variant.syntax().text_range(); acc.add(AssistId(assist_id, AssistKind::Generate), assist_description, target, |builder| { diff --git a/crates/ide_assists/src/handlers/generate_function.rs b/crates/ide_assists/src/handlers/generate_function.rs index bc9fc524b..706c995ac 100644 --- a/crates/ide_assists/src/handlers/generate_function.rs +++ b/crates/ide_assists/src/handlers/generate_function.rs @@ -59,7 +59,7 @@ pub(crate) fn generate_function(acc: &mut Assists, ctx: &AssistContext) -> Optio None => None, }; - let function_builder = FunctionBuilder::from_call(&ctx, &call, &path, target_module)?; + let function_builder = FunctionBuilder::from_call(ctx, &call, &path, target_module)?; let target = call.syntax().text_range(); acc.add( @@ -128,12 +128,12 @@ impl FunctionBuilder { file = in_file; target } - None => next_space_for_fn_after_call_site(&call)?, + None => next_space_for_fn_after_call_site(call)?, }; let needs_pub = target_module.is_some(); let target_module = target_module.or_else(|| ctx.sema.scope(target.syntax()).module())?; - let fn_name = fn_name(&path)?; - let (type_params, params) = fn_args(ctx, target_module, &call)?; + let fn_name = fn_name(path)?; + let (type_params, params) = fn_args(ctx, target_module, call)?; // should_render_snippet intends to express a rough level of confidence about // the correctness of the return type. diff --git a/crates/ide_assists/src/handlers/generate_getter.rs b/crates/ide_assists/src/handlers/generate_getter.rs index 09971226e..cc020c92c 100644 --- a/crates/ide_assists/src/handlers/generate_getter.rs +++ b/crates/ide_assists/src/handlers/generate_getter.rs @@ -75,7 +75,7 @@ pub(crate) fn generate_getter_impl( if mutable { format_to!(fn_name, "_mut"); } - let impl_def = find_struct_impl(&ctx, &ast::Adt::Struct(strukt.clone()), fn_name.as_str())?; + let impl_def = find_struct_impl(ctx, &ast::Adt::Struct(strukt.clone()), fn_name.as_str())?; let (id, label) = if mutable { ("generate_getter_mut", "Generate a mut getter method") diff --git a/crates/ide_assists/src/handlers/generate_new.rs b/crates/ide_assists/src/handlers/generate_new.rs index 959a1f86c..b65e8387b 100644 --- a/crates/ide_assists/src/handlers/generate_new.rs +++ b/crates/ide_assists/src/handlers/generate_new.rs @@ -36,7 +36,7 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()> }; // Return early if we've found an existing new fn - let impl_def = find_struct_impl(&ctx, &ast::Adt::Struct(strukt.clone()), "new")?; + let impl_def = find_struct_impl(ctx, &ast::Adt::Struct(strukt.clone()), "new")?; let target = strukt.syntax().text_range(); acc.add(AssistId("generate_new", AssistKind::Generate), "Generate `new`", target, |builder| { diff --git a/crates/ide_assists/src/handlers/generate_setter.rs b/crates/ide_assists/src/handlers/generate_setter.rs index 288cf745d..5bdf6b3f4 100644 --- a/crates/ide_assists/src/handlers/generate_setter.rs +++ b/crates/ide_assists/src/handlers/generate_setter.rs @@ -39,7 +39,7 @@ pub(crate) fn generate_setter(acc: &mut Assists, ctx: &AssistContext) -> Option< // Return early if we've found an existing fn let fn_name = to_lower_snake_case(&field_name.to_string()); let impl_def = find_struct_impl( - &ctx, + ctx, &ast::Adt::Struct(strukt.clone()), format!("set_{}", fn_name).as_str(), )?; diff --git a/crates/ide_assists/src/handlers/remove_dbg.rs b/crates/ide_assists/src/handlers/remove_dbg.rs index c8226550f..b20fe992d 100644 --- a/crates/ide_assists/src/handlers/remove_dbg.rs +++ b/crates/ide_assists/src/handlers/remove_dbg.rs @@ -85,7 +85,7 @@ fn whitespace_start(it: SyntaxElement) -> Option { } fn adjusted_macro_contents(macro_call: &ast::MacroCall) -> Option { - let contents = get_valid_macrocall_contents(¯o_call, "dbg")?; + let contents = get_valid_macrocall_contents(macro_call, "dbg")?; let macro_text_with_brackets = macro_call.token_tree()?.syntax().text(); let macro_text_in_brackets = macro_text_with_brackets.slice(TextRange::new( TextSize::of('('), diff --git a/crates/ide_assists/src/handlers/reorder_fields.rs b/crates/ide_assists/src/handlers/reorder_fields.rs index 933acead1..f6a926042 100644 --- a/crates/ide_assists/src/handlers/reorder_fields.rs +++ b/crates/ide_assists/src/handlers/reorder_fields.rs @@ -28,7 +28,7 @@ pub(crate) fn reorder_fields(acc: &mut Assists, ctx: &AssistContext) -> Option<( .or_else(|| ctx.find_node_at_offset::().map(Either::Right))?; let path = record.as_ref().either(|it| it.path(), |it| it.path())?; - let ranks = compute_fields_ranks(&path, &ctx)?; + let ranks = compute_fields_ranks(&path, ctx)?; let get_rank_of_field = |of: Option<_>| *ranks.get(&of.unwrap_or_default()).unwrap_or(&usize::MAX); diff --git a/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs b/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs index 10d9cec31..f9474c9f5 100644 --- a/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs +++ b/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs @@ -112,7 +112,7 @@ fn add_assist( let insert_pos = adt.syntax().text_range().end(); let impl_def_with_items = impl_def_from_trait(&ctx.sema, &annotated_name, trait_, trait_path); - update_attribute(builder, &input, &trait_name, &attr); + update_attribute(builder, input, &trait_name, attr); let trait_path = format!("{}", trait_path); match (ctx.config.snippet_cap, impl_def_with_items) { (None, _) => { diff --git a/crates/ide_assists/src/handlers/replace_if_let_with_match.rs b/crates/ide_assists/src/handlers/replace_if_let_with_match.rs index aee880625..9404aa26d 100644 --- a/crates/ide_assists/src/handlers/replace_if_let_with_match.rs +++ b/crates/ide_assists/src/handlers/replace_if_let_with_match.rs @@ -169,7 +169,7 @@ pub(crate) fn replace_match_with_if_let(acc: &mut Assists, ctx: &AssistContext) } fn is_pat_wildcard_or_sad(sema: &hir::Semantics, pat: &ast::Pat) -> bool { - sema.type_of_pat(&pat) + sema.type_of_pat(pat) .and_then(|ty| TryEnum::from_ty(sema, &ty)) .map(|it| it.sad_pattern().syntax().text() == pat.syntax().text()) .unwrap_or_else(|| matches!(pat, ast::Pat::WildcardPat(_))) diff --git a/crates/ide_assists/src/handlers/wrap_return_type_in_result.rs b/crates/ide_assists/src/handlers/wrap_return_type_in_result.rs index 2f1da82c7..140e27356 100644 --- a/crates/ide_assists/src/handlers/wrap_return_type_in_result.rs +++ b/crates/ide_assists/src/handlers/wrap_return_type_in_result.rs @@ -123,7 +123,7 @@ impl TailReturnCollector { fn handle_exprs(&mut self, expr: &Expr, collect_break: bool) { match expr { Expr::BlockExpr(block_expr) => { - self.collect_jump_exprs(&block_expr, collect_break); + self.collect_jump_exprs(block_expr, collect_break); } Expr::ReturnExpr(ret_expr) => { if let Some(ret_expr_arg) = &ret_expr.expr() { diff --git a/crates/ide_assists/src/tests.rs b/crates/ide_assists/src/tests.rs index 2b7c2d581..bdf9cb71c 100644 --- a/crates/ide_assists/src/tests.rs +++ b/crates/ide_assists/src/tests.rs @@ -74,7 +74,7 @@ pub(crate) fn check_assist_unresolved(assist: Handler, ra_fixture: &str) { #[track_caller] fn check_doc_test(assist_id: &str, before: &str, after: &str) { let after = trim_indent(after); - let (db, file_id, selection) = RootDatabase::with_range_or_offset(&before); + let (db, file_id, selection) = RootDatabase::with_range_or_offset(before); let before = db.file_text(file_id).to_string(); let frange = FileRange { file_id, range: selection.into() }; diff --git a/crates/ide_assists/src/utils.rs b/crates/ide_assists/src/utils.rs index 30128a24a..068df005b 100644 --- a/crates/ide_assists/src/utils.rs +++ b/crates/ide_assists/src/utils.rs @@ -492,7 +492,7 @@ pub(crate) fn add_method_to_adt( let start_offset = impl_def .and_then(|impl_def| find_impl_block_end(impl_def, &mut buf)) .unwrap_or_else(|| { - buf = generate_impl_text(&adt, &buf); + buf = generate_impl_text(adt, &buf); adt.syntax().text_range().end() }); diff --git a/crates/ide_assists/src/utils/suggest_name.rs b/crates/ide_assists/src/utils/suggest_name.rs index b3aabeab3..cb8bc8b2f 100644 --- a/crates/ide_assists/src/utils/suggest_name.rs +++ b/crates/ide_assists/src/utils/suggest_name.rs @@ -187,7 +187,7 @@ fn from_method_call(expr: &ast::Expr) -> Option { } } - normalize(&name) + normalize(name) } fn from_param(expr: &ast::Expr, sema: &Semantics<'_, RootDatabase>) -> Option { -- cgit v1.2.3