Pass trivially copy types as copy

This commit is contained in:
kjeremy 2020-05-26 14:12:13 -04:00
parent e3280eb4ae
commit bee4f8f9fe
4 changed files with 40 additions and 43 deletions

View file

@ -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<TypeRef> {
pub fn target_trait(self, db: &dyn HirDatabase) -> Option<TypeRef> {
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<AssocItem> {
pub fn items(self, db: &dyn HirDatabase) -> Vec<AssocItem> {
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<InFile<ast::Attr>> {
pub fn is_builtin_derive(self, db: &dyn HirDatabase) -> Option<InFile<ast::Attr>> {
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);

View file

@ -175,7 +175,7 @@ pub(super) enum DefKind {
}
impl DefKind {
pub fn ast_id(&self) -> FileAstId<ast::ModuleItem> {
pub fn ast_id(self) -> FileAstId<ast::ModuleItem> {
match self {
DefKind::Function(it) => it.upcast(),
DefKind::Struct(it, _) => it.upcast(),

View file

@ -25,7 +25,7 @@ impl ProcMacroExpander {
}
pub fn expand(
&self,
self,
db: &dyn AstDatabase,
_id: LazyMacroId,
tt: &tt::Subtree,

View file

@ -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());