mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 04:23:25 +00:00
Rename target_ty to self_ty
This commit is contained in:
parent
bb6e1bf811
commit
c2a63b97a8
16 changed files with 27 additions and 27 deletions
|
@ -1574,9 +1574,9 @@ impl Impl {
|
||||||
};
|
};
|
||||||
|
|
||||||
let filter = |impl_def: &Impl| {
|
let filter = |impl_def: &Impl| {
|
||||||
let target_ty = impl_def.target_ty(db);
|
let self_ty = impl_def.self_ty(db);
|
||||||
let rref = target_ty.remove_ref();
|
let rref = self_ty.remove_ref();
|
||||||
ty.equals_ctor(rref.as_ref().map_or(&target_ty.ty, |it| &it.ty))
|
ty.equals_ctor(rref.as_ref().map_or(&self_ty.ty, |it| &it.ty))
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut all = Vec::new();
|
let mut all = Vec::new();
|
||||||
|
@ -1614,16 +1614,16 @@ impl Impl {
|
||||||
|
|
||||||
// FIXME: the return type is wrong. This should be a hir version of
|
// FIXME: the return type is wrong. This should be a hir version of
|
||||||
// `TraitRef` (ie, resolved `TypeRef`).
|
// `TraitRef` (ie, resolved `TypeRef`).
|
||||||
pub fn target_trait(self, db: &dyn HirDatabase) -> Option<TraitRef> {
|
pub fn trait_(self, db: &dyn HirDatabase) -> Option<TraitRef> {
|
||||||
db.impl_data(self.id).target_trait.clone()
|
db.impl_data(self.id).target_trait.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn target_ty(self, db: &dyn HirDatabase) -> Type {
|
pub fn self_ty(self, db: &dyn HirDatabase) -> Type {
|
||||||
let impl_data = db.impl_data(self.id);
|
let impl_data = db.impl_data(self.id);
|
||||||
let resolver = self.id.resolver(db.upcast());
|
let resolver = self.id.resolver(db.upcast());
|
||||||
let krate = self.id.lookup(db.upcast()).container.krate();
|
let krate = self.id.lookup(db.upcast()).container.krate();
|
||||||
let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
|
let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
|
||||||
let ty = ctx.lower_ty(&impl_data.target_type);
|
let ty = ctx.lower_ty(&impl_data.self_ty);
|
||||||
Type::new_with_resolver_inner(db, krate, &resolver, ty)
|
Type::new_with_resolver_inner(db, krate, &resolver, ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,7 @@ impl TraitData {
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct ImplData {
|
pub struct ImplData {
|
||||||
pub target_trait: Option<TraitRef>,
|
pub target_trait: Option<TraitRef>,
|
||||||
pub target_type: TypeRef,
|
pub self_ty: TypeRef,
|
||||||
pub items: Vec<AssocItemId>,
|
pub items: Vec<AssocItemId>,
|
||||||
pub is_negative: bool,
|
pub is_negative: bool,
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,7 @@ impl ImplData {
|
||||||
let item_tree = impl_loc.id.item_tree(db);
|
let item_tree = impl_loc.id.item_tree(db);
|
||||||
let impl_def = &item_tree[impl_loc.id.value];
|
let impl_def = &item_tree[impl_loc.id.value];
|
||||||
let target_trait = impl_def.target_trait.map(|id| item_tree[id].clone());
|
let target_trait = impl_def.target_trait.map(|id| item_tree[id].clone());
|
||||||
let target_type = item_tree[impl_def.target_type].clone();
|
let self_ty = item_tree[impl_def.self_ty].clone();
|
||||||
let is_negative = impl_def.is_negative;
|
let is_negative = impl_def.is_negative;
|
||||||
let module_id = impl_loc.container;
|
let module_id = impl_loc.container;
|
||||||
let container = AssocContainerId::ImplId(id);
|
let container = AssocContainerId::ImplId(id);
|
||||||
|
@ -187,7 +187,7 @@ impl ImplData {
|
||||||
);
|
);
|
||||||
let items = items.into_iter().map(|(_, item)| item).collect();
|
let items = items.into_iter().map(|(_, item)| item).collect();
|
||||||
|
|
||||||
Arc::new(ImplData { target_trait, target_type, items, is_negative })
|
Arc::new(ImplData { target_trait, self_ty, items, is_negative })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -730,7 +730,7 @@ pub struct Trait {
|
||||||
pub struct Impl {
|
pub struct Impl {
|
||||||
pub generic_params: GenericParamsId,
|
pub generic_params: GenericParamsId,
|
||||||
pub target_trait: Option<Idx<TraitRef>>,
|
pub target_trait: Option<Idx<TraitRef>>,
|
||||||
pub target_type: Idx<TypeRef>,
|
pub self_ty: Idx<TypeRef>,
|
||||||
pub is_negative: bool,
|
pub is_negative: bool,
|
||||||
pub items: Box<[AssocItem]>,
|
pub items: Box<[AssocItem]>,
|
||||||
pub ast_id: FileAstId<ast::Impl>,
|
pub ast_id: FileAstId<ast::Impl>,
|
||||||
|
|
|
@ -537,7 +537,7 @@ impl Ctx {
|
||||||
let generic_params =
|
let generic_params =
|
||||||
self.lower_generic_params_and_inner_items(GenericsOwner::Impl, impl_def);
|
self.lower_generic_params_and_inner_items(GenericsOwner::Impl, impl_def);
|
||||||
let target_trait = impl_def.trait_().map(|tr| self.lower_trait_ref(&tr));
|
let target_trait = impl_def.trait_().map(|tr| self.lower_trait_ref(&tr));
|
||||||
let target_type = self.lower_type_ref(&impl_def.self_ty()?);
|
let self_ty = self.lower_type_ref(&impl_def.self_ty()?);
|
||||||
let is_negative = impl_def.excl_token().is_some();
|
let is_negative = impl_def.excl_token().is_some();
|
||||||
|
|
||||||
// We cannot use `assoc_items()` here as that does not include macro calls.
|
// We cannot use `assoc_items()` here as that does not include macro calls.
|
||||||
|
@ -554,7 +554,7 @@ impl Ctx {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let ast_id = self.source_ast_id_map.ast_id(impl_def);
|
let ast_id = self.source_ast_id_map.ast_id(impl_def);
|
||||||
let res = Impl { generic_params, target_trait, target_type, is_negative, items, ast_id };
|
let res = Impl { generic_params, target_trait, self_ty, is_negative, items, ast_id };
|
||||||
Some(id(self.data().impls.alloc(res)))
|
Some(id(self.data().impls.alloc(res)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1252,7 +1252,7 @@ pub(crate) fn impl_self_ty_query(db: &dyn HirDatabase, impl_id: ImplId) -> Binde
|
||||||
let generics = generics(db.upcast(), impl_id.into());
|
let generics = generics(db.upcast(), impl_id.into());
|
||||||
let ctx =
|
let ctx =
|
||||||
TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable);
|
TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable);
|
||||||
Binders::new(generics.len(), ctx.lower_ty(&impl_data.target_type))
|
Binders::new(generics.len(), ctx.lower_ty(&impl_data.self_ty))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn const_param_ty_query(db: &dyn HirDatabase, def: ConstParamId) -> Ty {
|
pub(crate) fn const_param_ty_query(db: &dyn HirDatabase, def: ConstParamId) -> Ty {
|
||||||
|
|
|
@ -214,7 +214,7 @@ fn get_doc_link(db: &RootDatabase, definition: Definition) -> Option<String> {
|
||||||
.and_then(|assoc| match assoc.container(db) {
|
.and_then(|assoc| match assoc.container(db) {
|
||||||
AssocItemContainer::Trait(t) => Some(t.into()),
|
AssocItemContainer::Trait(t) => Some(t.into()),
|
||||||
AssocItemContainer::Impl(impld) => {
|
AssocItemContainer::Impl(impld) => {
|
||||||
impld.target_ty(db).as_adt().map(|adt| adt.into())
|
impld.self_ty(db).as_adt().map(|adt| adt.into())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| f.clone().into()),
|
.unwrap_or_else(|| f.clone().into()),
|
||||||
|
|
|
@ -195,7 +195,7 @@ fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<Hov
|
||||||
let adt = match def {
|
let adt = match def {
|
||||||
Definition::ModuleDef(ModuleDef::Trait(it)) => return it.try_to_nav(db).map(to_action),
|
Definition::ModuleDef(ModuleDef::Trait(it)) => return it.try_to_nav(db).map(to_action),
|
||||||
Definition::ModuleDef(ModuleDef::Adt(it)) => Some(it),
|
Definition::ModuleDef(ModuleDef::Adt(it)) => Some(it),
|
||||||
Definition::SelfType(it) => it.target_ty(db).as_adt(),
|
Definition::SelfType(it) => it.self_ty(db).as_adt(),
|
||||||
_ => None,
|
_ => None,
|
||||||
}?;
|
}?;
|
||||||
adt.try_to_nav(db).map(to_action)
|
adt.try_to_nav(db).map(to_action)
|
||||||
|
@ -318,7 +318,7 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String>
|
||||||
Definition::ModuleDef(md) => match md {
|
Definition::ModuleDef(md) => match md {
|
||||||
ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) {
|
ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) {
|
||||||
AssocItemContainer::Trait(t) => Some(t.name(db)),
|
AssocItemContainer::Trait(t) => Some(t.name(db)),
|
||||||
AssocItemContainer::Impl(i) => i.target_ty(db).as_adt().map(|adt| adt.name(db)),
|
AssocItemContainer::Impl(i) => i.self_ty(db).as_adt().map(|adt| adt.name(db)),
|
||||||
},
|
},
|
||||||
ModuleDef::Variant(e) => Some(e.parent_enum(db).name(db)),
|
ModuleDef::Variant(e) => Some(e.parent_enum(db).name(db)),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -376,7 +376,7 @@ fn hover_for_definition(
|
||||||
},
|
},
|
||||||
Definition::Local(it) => hover_for_local(it, db),
|
Definition::Local(it) => hover_for_local(it, db),
|
||||||
Definition::SelfType(impl_def) => {
|
Definition::SelfType(impl_def) => {
|
||||||
impl_def.target_ty(db).as_adt().and_then(|adt| from_hir_fmt(db, adt, mod_path))
|
impl_def.self_ty(db).as_adt().and_then(|adt| from_hir_fmt(db, adt, mod_path))
|
||||||
}
|
}
|
||||||
Definition::GenericParam(it) => from_hir_fmt(db, it, None),
|
Definition::GenericParam(it) => from_hir_fmt(db, it, None),
|
||||||
Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
|
Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
|
||||||
|
|
|
@ -307,7 +307,7 @@ fn rename_to_self(sema: &Semantics<RootDatabase>, local: hir::Local) -> RenameRe
|
||||||
hir::AssocItemContainer::Impl(impl_) => impl_,
|
hir::AssocItemContainer::Impl(impl_) => impl_,
|
||||||
};
|
};
|
||||||
let first_param_ty = first_param.ty();
|
let first_param_ty = first_param.ty();
|
||||||
let impl_ty = impl_.target_ty(sema.db);
|
let impl_ty = impl_.self_ty(sema.db);
|
||||||
let (ty, self_param) = if impl_ty.remove_ref().is_some() {
|
let (ty, self_param) = if impl_ty.remove_ref().is_some() {
|
||||||
// if the impl is a ref to the type we can just match the `&T` with self directly
|
// if the impl is a ref to the type we can just match the `&T` with self directly
|
||||||
(first_param_ty.clone(), "self")
|
(first_param_ty.clone(), "self")
|
||||||
|
|
|
@ -298,7 +298,7 @@ fn module_def_doctest(sema: &Semantics<RootDatabase>, def: hir::ModuleDef) -> Op
|
||||||
// FIXME: this also looks very wrong
|
// FIXME: this also looks very wrong
|
||||||
if let Some(assoc_def) = assoc_def {
|
if let Some(assoc_def) = assoc_def {
|
||||||
if let hir::AssocItemContainer::Impl(imp) = assoc_def.container(sema.db) {
|
if let hir::AssocItemContainer::Impl(imp) = assoc_def.container(sema.db) {
|
||||||
let ty = imp.target_ty(sema.db);
|
let ty = imp.self_ty(sema.db);
|
||||||
if let Some(adt) = ty.as_adt() {
|
if let Some(adt) = ty.as_adt() {
|
||||||
let name = adt.name(sema.db);
|
let name = adt.name(sema.db);
|
||||||
let idx = path.rfind(':').map_or(0, |idx| idx + 1);
|
let idx = path.rfind(':').map_or(0, |idx| idx + 1);
|
||||||
|
|
|
@ -92,7 +92,7 @@ fn is_default_implemented(ctx: &AssistContext, impl_: &Impl) -> bool {
|
||||||
None => return false,
|
None => return false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let ty = impl_def.target_ty(db);
|
let ty = impl_def.self_ty(db);
|
||||||
let krate = impl_def.module(db).krate();
|
let krate = impl_def.module(db).krate();
|
||||||
let default = FamousDefs(&ctx.sema, Some(krate)).core_default_Default();
|
let default = FamousDefs(&ctx.sema, Some(krate)).core_default_Default();
|
||||||
let default_trait = match default {
|
let default_trait = match default {
|
||||||
|
|
|
@ -91,7 +91,7 @@ fn get_impl_method(
|
||||||
|
|
||||||
let scope = ctx.sema.scope(impl_.syntax());
|
let scope = ctx.sema.scope(impl_.syntax());
|
||||||
let krate = impl_def.module(db).krate();
|
let krate = impl_def.module(db).krate();
|
||||||
let ty = impl_def.target_ty(db);
|
let ty = impl_def.self_ty(db);
|
||||||
let traits_in_scope = scope.traits_in_scope();
|
let traits_in_scope = scope.traits_in_scope();
|
||||||
ty.iterate_method_candidates(db, krate, &traits_in_scope, Some(fn_name), |_, func| Some(func))
|
ty.iterate_method_candidates(db, krate, &traits_in_scope, Some(fn_name), |_, func| Some(func))
|
||||||
}
|
}
|
||||||
|
|
|
@ -338,11 +338,11 @@ pub(crate) fn find_struct_impl(
|
||||||
// (we currently use the wrong type parameter)
|
// (we currently use the wrong type parameter)
|
||||||
// also we wouldn't want to use e.g. `impl S<u32>`
|
// also we wouldn't want to use e.g. `impl S<u32>`
|
||||||
|
|
||||||
let same_ty = match blk.target_ty(db).as_adt() {
|
let same_ty = match blk.self_ty(db).as_adt() {
|
||||||
Some(def) => def == struct_def,
|
Some(def) => def == struct_def,
|
||||||
None => false,
|
None => false,
|
||||||
};
|
};
|
||||||
let not_trait_impl = blk.target_trait(db).is_none();
|
let not_trait_impl = blk.trait_(db).is_none();
|
||||||
|
|
||||||
if !(same_ty && not_trait_impl) {
|
if !(same_ty && not_trait_impl) {
|
||||||
None
|
None
|
||||||
|
|
|
@ -220,7 +220,7 @@ fn complete_enum_variants(
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(impl_) = ctx.impl_def.as_ref().and_then(|impl_| ctx.sema.to_def(impl_)) {
|
if let Some(impl_) = ctx.impl_def.as_ref().and_then(|impl_| ctx.sema.to_def(impl_)) {
|
||||||
if impl_.target_ty(ctx.db) == *ty {
|
if impl_.self_ty(ctx.db) == *ty {
|
||||||
for &variant in &variants {
|
for &variant in &variants {
|
||||||
let self_path = hir::ModPath::from_segments(
|
let self_path = hir::ModPath::from_segments(
|
||||||
hir::PathKind::Plain,
|
hir::PathKind::Plain,
|
||||||
|
|
|
@ -40,7 +40,7 @@ pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
_ => false,
|
_ => false,
|
||||||
},
|
},
|
||||||
hir::ScopeDef::MacroDef(_) => true,
|
hir::ScopeDef::MacroDef(_) => true,
|
||||||
hir::ScopeDef::ImplSelfType(impl_) => match impl_.target_ty(ctx.db).as_adt() {
|
hir::ScopeDef::ImplSelfType(impl_) => match impl_.self_ty(ctx.db).as_adt() {
|
||||||
Some(hir::Adt::Struct(strukt)) => {
|
Some(hir::Adt::Struct(strukt)) => {
|
||||||
acc.add_struct_pat(ctx, strukt, Some(name.clone()));
|
acc.add_struct_pat(ctx, strukt, Some(name.clone()));
|
||||||
true
|
true
|
||||||
|
|
|
@ -117,7 +117,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
|
||||||
if let Some(krate) = ctx.krate {
|
if let Some(krate) = ctx.krate {
|
||||||
let ty = match resolution {
|
let ty = match resolution {
|
||||||
PathResolution::TypeParam(param) => param.ty(ctx.db),
|
PathResolution::TypeParam(param) => param.ty(ctx.db),
|
||||||
PathResolution::SelfType(impl_def) => impl_def.target_ty(ctx.db),
|
PathResolution::SelfType(impl_def) => impl_def.self_ty(ctx.db),
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -361,7 +361,7 @@ fn item_for_path_search(db: &RootDatabase, item: ItemInNs) -> Option<ItemInNs> {
|
||||||
Some(assoc_item) => match assoc_item.container(db) {
|
Some(assoc_item) => match assoc_item.container(db) {
|
||||||
AssocItemContainer::Trait(trait_) => ItemInNs::from(ModuleDef::from(trait_)),
|
AssocItemContainer::Trait(trait_) => ItemInNs::from(ModuleDef::from(trait_)),
|
||||||
AssocItemContainer::Impl(impl_) => {
|
AssocItemContainer::Impl(impl_) => {
|
||||||
ItemInNs::from(ModuleDef::from(impl_.target_ty(db).as_adt()?))
|
ItemInNs::from(ModuleDef::from(impl_.self_ty(db).as_adt()?))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => item,
|
None => item,
|
||||||
|
|
Loading…
Reference in a new issue