mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Switch type aliases to new sources
This commit is contained in:
parent
b7a36b5443
commit
64c21ed195
9 changed files with 162 additions and 73 deletions
|
@ -13,7 +13,7 @@ use hir_def::{
|
|||
traits::TraitData,
|
||||
type_ref::{Mutability, TypeRef},
|
||||
AssocItemId, CrateModuleId, FunctionContainerId, HasModule, ImplId, LocalEnumVariantId,
|
||||
LocalStructFieldId, Lookup, ModuleId, UnionId,
|
||||
LocalStructFieldId, Lookup, ModuleId, TypeAliasContainerId, UnionId,
|
||||
};
|
||||
use hir_expand::{
|
||||
diagnostics::DiagnosticSink,
|
||||
|
@ -954,30 +954,34 @@ pub struct TypeAlias {
|
|||
|
||||
impl TypeAlias {
|
||||
pub fn module(self, db: &impl DefDatabase) -> Module {
|
||||
Module { id: self.id.module(db) }
|
||||
Module { id: self.id.lookup(db).module(db) }
|
||||
}
|
||||
|
||||
pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> {
|
||||
Some(self.module(db).krate())
|
||||
}
|
||||
|
||||
/// The containing impl block, if this is a method.
|
||||
/// The containing impl block, if this is a type alias.
|
||||
pub fn impl_block(self, db: &impl DefDatabase) -> Option<ImplBlock> {
|
||||
ImplBlock::containing(db, self.into())
|
||||
match self.container(db) {
|
||||
Some(Container::ImplBlock(it)) => Some(it),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The containing trait, if this is a trait method definition.
|
||||
/// The containing trait, if this is a trait type alias definition.
|
||||
pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> {
|
||||
db.trait_items_index(self.module(db).id).get_parent_trait(self.id.into()).map(Trait::from)
|
||||
match self.container(db) {
|
||||
Some(Container::Trait(it)) => Some(it),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn container(self, db: &impl DefDatabase) -> Option<Container> {
|
||||
if let Some(impl_block) = self.impl_block(db) {
|
||||
Some(impl_block.into())
|
||||
} else if let Some(trait_) = self.parent_trait(db) {
|
||||
Some(trait_.into())
|
||||
} else {
|
||||
None
|
||||
match self.id.lookup(db).container {
|
||||
TypeAliasContainerId::TraitId(it) => Some(Container::Trait(it.into())),
|
||||
TypeAliasContainerId::ImplId(it) => Some(Container::ImplBlock(it.into())),
|
||||
TypeAliasContainerId::ModuleId(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue