From 62ed658311a8ea35c5e6752c64e8b15e5f9ed19f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 12 Mar 2022 13:43:53 +0100 Subject: [PATCH] fix clippy::useless_conversion --- crates/hir/src/from_id.rs | 4 ++-- crates/hir_def/src/nameres/collector.rs | 2 +- crates/hir_expand/src/eager.rs | 2 +- crates/hir_ty/src/lower.rs | 2 +- .../ide_assists/src/handlers/extract_function.rs | 2 +- .../ide_assists/src/handlers/extract_module.rs | 10 +++++----- .../ide_assists/src/utils/gen_trait_fn_body.rs | 16 ++++++---------- crates/ide_db/src/helpers.rs | 8 ++++---- crates/ide_db/src/imports/import_assets.rs | 4 ++-- crates/ide_db/src/items_locator.rs | 2 +- crates/text_edit/src/lib.rs | 2 +- 11 files changed, 25 insertions(+), 29 deletions(-) diff --git a/crates/hir/src/from_id.rs b/crates/hir/src/from_id.rs index 5ee7556481..9c7558d191 100644 --- a/crates/hir/src/from_id.rs +++ b/crates/hir/src/from_id.rs @@ -82,8 +82,8 @@ impl From for GenericParamId { fn from(id: GenericParam) -> Self { match id { GenericParam::LifetimeParam(it) => GenericParamId::LifetimeParamId(it.id), - GenericParam::ConstParam(it) => GenericParamId::ConstParamId(it.id.into()), - GenericParam::TypeParam(it) => GenericParamId::TypeParamId(it.id.into()), + GenericParam::ConstParam(it) => GenericParamId::ConstParamId(it.id), + GenericParam::TypeParam(it) => GenericParamId::TypeParamId(it.id), } } } diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 95a50d942e..6a761c505c 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -570,7 +570,7 @@ impl DefCollector<'_> { let proc_macro_id = ProcMacroLoc { container: module_id, id, expander, kind }.intern(self.db); - self.define_proc_macro(def.name.clone(), proc_macro_id.into()); + self.define_proc_macro(def.name.clone(), proc_macro_id); if let ProcMacroKind::CustomDerive { helpers } = def.kind { self.def_map .exported_derives diff --git a/crates/hir_expand/src/eager.rs b/crates/hir_expand/src/eager.rs index a24c24cfb0..5fd099aea7 100644 --- a/crates/hir_expand/src/eager.rs +++ b/crates/hir_expand/src/eager.rs @@ -146,7 +146,7 @@ pub fn expand_eager_macro( if let MacroDefKind::BuiltInEager(eager, _) = def.kind { let res = eager.expand(db, arg_id, &subtree); if let Some(err) = res.err { - diagnostic_sink(err.into()); + diagnostic_sink(err); } let loc = MacroCallLoc { diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 15f91ce799..1d6affe9c7 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -1059,7 +1059,7 @@ pub(crate) fn generic_predicates_for_param_query( | WherePredicate::TypeBound { target, bound, .. } => { match target { WherePredicateTypeTarget::TypeRef(type_ref) => { - if ctx.lower_ty_only_param(type_ref) != Some(param_id.into()) { + if ctx.lower_ty_only_param(type_ref) != Some(param_id) { return false; } } diff --git a/crates/ide_assists/src/handlers/extract_function.rs b/crates/ide_assists/src/handlers/extract_function.rs index 4cc4860ed5..e48a1cd9ef 100644 --- a/crates/ide_assists/src/handlers/extract_function.rs +++ b/crates/ide_assists/src/handlers/extract_function.rs @@ -1518,7 +1518,7 @@ fn make_body( make::expr_path(make::path_from_text("ControlFlow::Continue")), make::arg_list(iter::once(make::expr_unit())), ); - with_tail_expr(block, controlflow_continue.into()) + with_tail_expr(block, controlflow_continue) } FlowHandler::IfOption { .. } => { let none = make::expr_path(make::ext::ident_path("None")); diff --git a/crates/ide_assists/src/handlers/extract_module.rs b/crates/ide_assists/src/handlers/extract_module.rs index 556659d07c..169bc9ed4d 100644 --- a/crates/ide_assists/src/handlers/extract_module.rs +++ b/crates/ide_assists/src/handlers/extract_module.rs @@ -267,7 +267,7 @@ impl Module { match (item.syntax()) { ast::Adt(it) => { if let Some( nod ) = ctx.sema.to_def(&it) { - let node_def = Definition::Adt(nod.into()); + let node_def = Definition::Adt(nod); self.expand_and_group_usages_file_wise(ctx, node_def, &mut refs); //Enum Fields are not allowed to explicitly specify pub, it is implied @@ -301,25 +301,25 @@ impl Module { }, ast::TypeAlias(it) => { if let Some( nod ) = ctx.sema.to_def(&it) { - let node_def = Definition::TypeAlias(nod.into()); + let node_def = Definition::TypeAlias(nod); self.expand_and_group_usages_file_wise(ctx, node_def, &mut refs); } }, ast::Const(it) => { if let Some( nod ) = ctx.sema.to_def(&it) { - let node_def = Definition::Const(nod.into()); + let node_def = Definition::Const(nod); self.expand_and_group_usages_file_wise(ctx, node_def, &mut refs); } }, ast::Static(it) => { if let Some( nod ) = ctx.sema.to_def(&it) { - let node_def = Definition::Static(nod.into()); + let node_def = Definition::Static(nod); self.expand_and_group_usages_file_wise(ctx, node_def, &mut refs); } }, ast::Fn(it) => { if let Some( nod ) = ctx.sema.to_def(&it) { - let node_def = Definition::Function(nod.into()); + let node_def = Definition::Function(nod); self.expand_and_group_usages_file_wise(ctx, node_def, &mut refs); } }, diff --git a/crates/ide_assists/src/utils/gen_trait_fn_body.rs b/crates/ide_assists/src/utils/gen_trait_fn_body.rs index 944346b555..f6ca3b2110 100644 --- a/crates/ide_assists/src/utils/gen_trait_fn_body.rs +++ b/crates/ide_assists/src/utils/gen_trait_fn_body.rs @@ -86,7 +86,7 @@ fn gen_clone_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> { None => { let pattern = make::path_pat(variant_name.clone()); let variant_expr = make::expr_path(variant_name); - arms.push(make::match_arm(Some(pattern.into()), None, variant_expr)); + arms.push(make::match_arm(Some(pattern), None, variant_expr)); } } } @@ -117,7 +117,7 @@ fn gen_clone_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> { let mut fields = vec![]; for (i, _) in field_list.fields().enumerate() { let f_path = make::expr_path(make::ext::ident_path("self")); - let target = make::expr_field(f_path, &format!("{}", i)).into(); + let target = make::expr_field(f_path, &format!("{}", i)); fields.push(gen_clone_call(target)); } let struct_name = make::expr_path(make::ext::ident_path("Self")); @@ -151,7 +151,7 @@ fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> { for variant in list.variants() { let name = variant.name()?; let variant_name = make::ext::path_from_idents(["Self", &format!("{}", name)])?; - let target = make::expr_path(make::ext::ident_path("f").into()); + let target = make::expr_path(make::ext::ident_path("f")); match variant.field_list() { Some(ast::FieldList::RecordFieldList(list)) => { @@ -227,11 +227,7 @@ fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> { let macro_call = make::expr_macro_call(macro_name, args); let variant_name = make::path_pat(variant_name); - arms.push(make::match_arm( - Some(variant_name.into()), - None, - macro_call.into(), - )); + arms.push(make::match_arm(Some(variant_name), None, macro_call)); } } } @@ -264,7 +260,7 @@ fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> { let f_name = make::expr_literal(&(format!("\"{}\"", name))).into(); let f_path = make::expr_path(make::ext::ident_path("self")); let f_path = make::expr_ref(f_path, false); - let f_path = make::expr_field(f_path, &format!("{}", name)).into(); + let f_path = make::expr_field(f_path, &format!("{}", name)); let args = make::arg_list([f_name, f_path]); expr = make::expr_method_call(expr, make::name_ref("field"), args); } @@ -278,7 +274,7 @@ fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> { for (i, _) in field_list.fields().enumerate() { let f_path = make::expr_path(make::ext::ident_path("self")); let f_path = make::expr_ref(f_path, false); - let f_path = make::expr_field(f_path, &format!("{}", i)).into(); + let f_path = make::expr_field(f_path, &format!("{}", i)); let method = make::name_ref("field"); expr = make::expr_method_call(expr, method, make::arg_list(Some(f_path))); } diff --git a/crates/ide_db/src/helpers.rs b/crates/ide_db/src/helpers.rs index c8dd64f61c..4046c2febb 100644 --- a/crates/ide_db/src/helpers.rs +++ b/crates/ide_db/src/helpers.rs @@ -3,7 +3,7 @@ use std::collections::VecDeque; use base_db::FileId; -use hir::{ItemInNs, Macro, ModuleDef, Name, Semantics}; +use hir::{ItemInNs, ModuleDef, Name, Semantics}; use syntax::{ ast::{self, make}, AstToken, SyntaxKind, SyntaxToken, TokenAtOffset, @@ -13,9 +13,9 @@ use crate::{defs::Definition, generated, RootDatabase}; pub fn item_name(db: &RootDatabase, item: ItemInNs) -> Option { match item { - ItemInNs::Types(module_def_id) => ModuleDef::from(module_def_id).name(db), - ItemInNs::Values(module_def_id) => ModuleDef::from(module_def_id).name(db), - ItemInNs::Macros(macro_def_id) => Some(Macro::from(macro_def_id).name(db)), + ItemInNs::Types(module_def_id) => module_def_id.name(db), + ItemInNs::Values(module_def_id) => module_def_id.name(db), + ItemInNs::Macros(macro_def_id) => Some(macro_def_id.name(db)), } } diff --git a/crates/ide_db/src/imports/import_assets.rs b/crates/ide_db/src/imports/import_assets.rs index 86c43ed0ec..9a09c40ee6 100644 --- a/crates/ide_db/src/imports/import_assets.rs +++ b/crates/ide_db/src/imports/import_assets.rs @@ -430,8 +430,8 @@ fn module_with_segment_name( candidate: ItemInNs, ) -> Option { let mut current_module = match candidate { - ItemInNs::Types(module_def_id) => ModuleDef::from(module_def_id).module(db), - ItemInNs::Values(module_def_id) => ModuleDef::from(module_def_id).module(db), + ItemInNs::Types(module_def_id) => module_def_id.module(db), + ItemInNs::Values(module_def_id) => module_def_id.module(db), ItemInNs::Macros(macro_def_id) => ModuleDef::from(macro_def_id).module(db), }; while let Some(module) = current_module { diff --git a/crates/ide_db/src/items_locator.rs b/crates/ide_db/src/items_locator.rs index 891b7c8e92..07a57c883b 100644 --- a/crates/ide_db/src/items_locator.rs +++ b/crates/ide_db/src/items_locator.rs @@ -115,7 +115,7 @@ fn find_items<'a>( }); // Query the local crate using the symbol index. - let local_results = symbol_index::crate_symbols(db, krate.into(), local_query) + let local_results = symbol_index::crate_symbols(db, krate, local_query) .into_iter() .filter_map(move |local_candidate| get_name_definition(sema, &local_candidate)) .filter_map(|name_definition_to_import| match name_definition_to_import { diff --git a/crates/text_edit/src/lib.rs b/crates/text_edit/src/lib.rs index 1a6add0578..bd3fcb870a 100644 --- a/crates/text_edit/src/lib.rs +++ b/crates/text_edit/src/lib.rs @@ -101,7 +101,7 @@ impl TextEdit { max_total_len = max(max_total_len, total_len); } - if let Some(additional) = max_total_len.checked_sub(text_size.into()) { + if let Some(additional) = max_total_len.checked_sub(text_size) { text.reserve(additional.into()); }