mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Use generic ItemLoc for impls
This commit is contained in:
parent
d137df0137
commit
1234dda9ee
5 changed files with 10 additions and 28 deletions
|
@ -754,7 +754,7 @@ impl ImplBlock {
|
||||||
let environment = TraitEnvironment::lower(db, &resolver);
|
let environment = TraitEnvironment::lower(db, &resolver);
|
||||||
let ty = Ty::from_hir(db, &resolver, &impl_data.target_type);
|
let ty = Ty::from_hir(db, &resolver, &impl_data.target_type);
|
||||||
Type {
|
Type {
|
||||||
krate: self.id.lookup(db).container.krate,
|
krate: self.id.lookup(db).container.module(db).krate,
|
||||||
ty: InEnvironment { value: ty, environment },
|
ty: InEnvironment { value: ty, environment },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -768,7 +768,7 @@ impl ImplBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn module(&self, db: &impl DefDatabase) -> Module {
|
pub fn module(&self, db: &impl DefDatabase) -> Module {
|
||||||
self.id.lookup(db).container.into()
|
self.id.lookup(db).container.module(db).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn krate(&self, db: &impl DefDatabase) -> Crate {
|
pub fn krate(&self, db: &impl DefDatabase) -> Crate {
|
||||||
|
|
|
@ -160,27 +160,8 @@ impl_intern!(TypeAliasId, TypeAliasLoc, intern_type_alias, lookup_intern_type_al
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct ImplId(salsa::InternId);
|
pub struct ImplId(salsa::InternId);
|
||||||
impl_intern_key!(ImplId);
|
type ImplLoc = ItemLoc<ast::ImplBlock>;
|
||||||
|
impl_intern!(ImplId, ImplLoc, intern_impl, lookup_intern_impl);
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
||||||
pub struct ImplLoc {
|
|
||||||
pub container: ModuleId,
|
|
||||||
pub ast_id: AstId<ast::ImplBlock>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Intern for ImplLoc {
|
|
||||||
type ID = ImplId;
|
|
||||||
fn intern(self, db: &impl db::DefDatabase) -> ImplId {
|
|
||||||
db.intern_impl(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Lookup for ImplId {
|
|
||||||
type Data = ImplLoc;
|
|
||||||
fn lookup(&self, db: &impl db::DefDatabase) -> ImplLoc {
|
|
||||||
db.lookup_intern_impl(*self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct TypeParamId {
|
pub struct TypeParamId {
|
||||||
|
@ -379,7 +360,7 @@ impl HasModule for AssocContainerId {
|
||||||
fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
|
fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
|
||||||
match *self {
|
match *self {
|
||||||
AssocContainerId::ContainerId(it) => it.module(db),
|
AssocContainerId::ContainerId(it) => it.module(db),
|
||||||
AssocContainerId::ImplId(it) => it.lookup(db).container,
|
AssocContainerId::ImplId(it) => it.lookup(db).container.module(db),
|
||||||
AssocContainerId::TraitId(it) => it.lookup(db).container.module(db),
|
AssocContainerId::TraitId(it) => it.lookup(db).container.module(db),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -431,7 +412,7 @@ impl HasModule for GenericDefId {
|
||||||
GenericDefId::AdtId(it) => it.module(db),
|
GenericDefId::AdtId(it) => it.module(db),
|
||||||
GenericDefId::TraitId(it) => it.lookup(db).container.module(db),
|
GenericDefId::TraitId(it) => it.lookup(db).container.module(db),
|
||||||
GenericDefId::TypeAliasId(it) => it.lookup(db).module(db),
|
GenericDefId::TypeAliasId(it) => it.lookup(db).module(db),
|
||||||
GenericDefId::ImplId(it) => it.lookup(db).container,
|
GenericDefId::ImplId(it) => it.lookup(db).container.module(db),
|
||||||
GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container.module(db),
|
GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container.module(db),
|
||||||
GenericDefId::ConstId(it) => it.lookup(db).module(db),
|
GenericDefId::ConstId(it) => it.lookup(db).module(db),
|
||||||
}
|
}
|
||||||
|
|
|
@ -661,9 +661,10 @@ where
|
||||||
krate: self.def_collector.def_map.krate,
|
krate: self.def_collector.def_map.krate,
|
||||||
local_id: self.module_id,
|
local_id: self.module_id,
|
||||||
};
|
};
|
||||||
|
let container = ContainerId::ModuleId(module);
|
||||||
let ast_id = self.raw_items[imp].ast_id;
|
let ast_id = self.raw_items[imp].ast_id;
|
||||||
let impl_id =
|
let impl_id =
|
||||||
ImplLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) }
|
ImplLoc { container, ast_id: AstId::new(self.file_id, ast_id) }
|
||||||
.intern(self.def_collector.db);
|
.intern(self.def_collector.db);
|
||||||
self.def_collector.def_map.modules[self.module_id].impls.push(impl_id)
|
self.def_collector.def_map.modules[self.module_id].impls.push(impl_id)
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,7 +134,7 @@ impl Ty {
|
||||||
LangItemTarget::ImplBlockId(it) => Some(it),
|
LangItemTarget::ImplBlockId(it) => Some(it),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.map(|it| it.lookup(db).container.krate)
|
.map(|it| it.lookup(db).container.module(db).krate)
|
||||||
.collect();
|
.collect();
|
||||||
Some(res)
|
Some(res)
|
||||||
}
|
}
|
||||||
|
|
|
@ -673,7 +673,7 @@ fn impl_block_datum(
|
||||||
let bound_vars = Substs::bound_vars(&generic_params);
|
let bound_vars = Substs::bound_vars(&generic_params);
|
||||||
let trait_ref = trait_ref.subst(&bound_vars);
|
let trait_ref = trait_ref.subst(&bound_vars);
|
||||||
let trait_ = trait_ref.trait_;
|
let trait_ = trait_ref.trait_;
|
||||||
let impl_type = if impl_id.lookup(db).container.krate == krate {
|
let impl_type = if impl_id.lookup(db).container.module(db).krate == krate {
|
||||||
chalk_rust_ir::ImplType::Local
|
chalk_rust_ir::ImplType::Local
|
||||||
} else {
|
} else {
|
||||||
chalk_rust_ir::ImplType::External
|
chalk_rust_ir::ImplType::External
|
||||||
|
|
Loading…
Reference in a new issue