From bee4f8f9fee56bb00b462cdf4ad3ed317fed682f Mon Sep 17 00:00:00 2001 From: kjeremy Date: Tue, 26 May 2020 14:12:13 -0400 Subject: [PATCH] Pass trivially copy types as copy --- crates/ra_hir/src/code_model.rs | 18 +++--- crates/ra_hir_def/src/nameres/raw.rs | 2 +- crates/ra_hir_expand/src/proc_macro.rs | 2 +- .../src/completion/complete_trait_impl.rs | 61 +++++++++---------- 4 files changed, 40 insertions(+), 43 deletions(-) diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 840cfdfc82..8d7937d947 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -532,7 +532,7 @@ impl Adt { Some(self.module(db).krate()) } - pub fn name(&self, db: &dyn HirDatabase) -> Name { + pub fn name(self, db: &dyn HirDatabase) -> Name { match self { Adt::Struct(s) => s.name(db), Adt::Union(u) => u.name(db), @@ -1018,15 +1018,15 @@ impl ImplDef { impls.lookup_impl_defs_for_trait(trait_.id).map(Self::from).collect() } - pub fn target_trait(&self, db: &dyn HirDatabase) -> Option { + pub fn target_trait(self, db: &dyn HirDatabase) -> Option { db.impl_data(self.id).target_trait.clone() } - pub fn target_type(&self, db: &dyn HirDatabase) -> TypeRef { + pub fn target_type(self, db: &dyn HirDatabase) -> TypeRef { db.impl_data(self.id).target_type.clone() } - pub fn target_ty(&self, db: &dyn HirDatabase) -> Type { + pub fn target_ty(self, db: &dyn HirDatabase) -> Type { let impl_data = db.impl_data(self.id); let resolver = self.id.resolver(db.upcast()); let ctx = hir_ty::TyLoweringContext::new(db, &resolver); @@ -1038,23 +1038,23 @@ impl ImplDef { } } - pub fn items(&self, db: &dyn HirDatabase) -> Vec { + pub fn items(self, db: &dyn HirDatabase) -> Vec { db.impl_data(self.id).items.iter().map(|it| (*it).into()).collect() } - pub fn is_negative(&self, db: &dyn HirDatabase) -> bool { + pub fn is_negative(self, db: &dyn HirDatabase) -> bool { db.impl_data(self.id).is_negative } - pub fn module(&self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn HirDatabase) -> Module { self.id.lookup(db.upcast()).container.module(db.upcast()).into() } - pub fn krate(&self, db: &dyn HirDatabase) -> Crate { + pub fn krate(self, db: &dyn HirDatabase) -> Crate { Crate { id: self.module(db).id.krate } } - pub fn is_builtin_derive(&self, db: &dyn HirDatabase) -> Option> { + pub fn is_builtin_derive(self, db: &dyn HirDatabase) -> Option> { let src = self.source(db); let item = src.file_id.is_builtin_derive(db.upcast())?; let hygenic = hir_expand::hygiene::Hygiene::new(db.upcast(), item.file_id); diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 4e628b14d9..f44baa5794 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs @@ -175,7 +175,7 @@ pub(super) enum DefKind { } impl DefKind { - pub fn ast_id(&self) -> FileAstId { + pub fn ast_id(self) -> FileAstId { match self { DefKind::Function(it) => it.upcast(), DefKind::Struct(it, _) => it.upcast(), diff --git a/crates/ra_hir_expand/src/proc_macro.rs b/crates/ra_hir_expand/src/proc_macro.rs index 4e0e069c8c..04c0260046 100644 --- a/crates/ra_hir_expand/src/proc_macro.rs +++ b/crates/ra_hir_expand/src/proc_macro.rs @@ -25,7 +25,7 @@ impl ProcMacroExpander { } pub fn expand( - &self, + self, db: &dyn AstDatabase, _id: LazyMacroId, tt: &tt::Subtree, diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs index 039df03e05..21c9316e66 100644 --- a/crates/ra_ide/src/completion/complete_trait_impl.rs +++ b/crates/ra_ide/src/completion/complete_trait_impl.rs @@ -49,56 +49,53 @@ use crate::{ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext) { if let Some((trigger, impl_def)) = completion_match(ctx) { match trigger.kind() { - SyntaxKind::NAME_REF => { - get_missing_assoc_items(&ctx.sema, &impl_def).iter().for_each(|item| match item { + SyntaxKind::NAME_REF => get_missing_assoc_items(&ctx.sema, &impl_def) + .into_iter() + .for_each(|item| match item { hir::AssocItem::Function(fn_item) => { - add_function_impl(&trigger, acc, ctx, &fn_item) + add_function_impl(&trigger, acc, ctx, fn_item) } hir::AssocItem::TypeAlias(type_item) => { - add_type_alias_impl(&trigger, acc, ctx, &type_item) + add_type_alias_impl(&trigger, acc, ctx, type_item) } hir::AssocItem::Const(const_item) => { - add_const_impl(&trigger, acc, ctx, &const_item) + add_const_impl(&trigger, acc, ctx, const_item) } - }) - } + }), SyntaxKind::FN_DEF => { - for missing_fn in - get_missing_assoc_items(&ctx.sema, &impl_def).iter().filter_map(|item| { - match item { - hir::AssocItem::Function(fn_item) => Some(fn_item), - _ => None, - } + for missing_fn in get_missing_assoc_items(&ctx.sema, &impl_def) + .into_iter() + .filter_map(|item| match item { + hir::AssocItem::Function(fn_item) => Some(fn_item), + _ => None, }) { - add_function_impl(&trigger, acc, ctx, &missing_fn); + add_function_impl(&trigger, acc, ctx, missing_fn); } } SyntaxKind::TYPE_ALIAS_DEF => { - for missing_fn in - get_missing_assoc_items(&ctx.sema, &impl_def).iter().filter_map(|item| { - match item { - hir::AssocItem::TypeAlias(type_item) => Some(type_item), - _ => None, - } + for missing_fn in get_missing_assoc_items(&ctx.sema, &impl_def) + .into_iter() + .filter_map(|item| match item { + hir::AssocItem::TypeAlias(type_item) => Some(type_item), + _ => None, }) { - add_type_alias_impl(&trigger, acc, ctx, &missing_fn); + add_type_alias_impl(&trigger, acc, ctx, missing_fn); } } SyntaxKind::CONST_DEF => { - for missing_fn in - get_missing_assoc_items(&ctx.sema, &impl_def).iter().filter_map(|item| { - match item { - hir::AssocItem::Const(const_item) => Some(const_item), - _ => None, - } + for missing_fn in get_missing_assoc_items(&ctx.sema, &impl_def) + .into_iter() + .filter_map(|item| match item { + hir::AssocItem::Const(const_item) => Some(const_item), + _ => None, }) { - add_const_impl(&trigger, acc, ctx, &missing_fn); + add_const_impl(&trigger, acc, ctx, missing_fn); } } @@ -126,9 +123,9 @@ fn add_function_impl( fn_def_node: &SyntaxNode, acc: &mut Completions, ctx: &CompletionContext, - func: &hir::Function, + func: hir::Function, ) { - let signature = FunctionSignature::from_hir(ctx.db, *func); + let signature = FunctionSignature::from_hir(ctx.db, func); let fn_name = func.name(ctx.db).to_string(); @@ -167,7 +164,7 @@ fn add_type_alias_impl( type_def_node: &SyntaxNode, acc: &mut Completions, ctx: &CompletionContext, - type_alias: &hir::TypeAlias, + type_alias: hir::TypeAlias, ) { let alias_name = type_alias.name(ctx.db).to_string(); @@ -187,7 +184,7 @@ fn add_const_impl( const_def_node: &SyntaxNode, acc: &mut Completions, ctx: &CompletionContext, - const_: &hir::Const, + const_: hir::Const, ) { let const_name = const_.name(ctx.db).map(|n| n.to_string());