mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-14 16:03:17 +00:00
Add AttrDefId::krate
Access to the containing crate will be needed to handle `cfg_attr`
This commit is contained in:
parent
ce8ec28638
commit
eaeabbb815
@ -425,6 +425,16 @@ impl HasModule for AdtId {
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModule for VariantId {
|
||||
fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
|
||||
match self {
|
||||
VariantId::EnumVariantId(it) => it.parent.lookup(db).container.module(db),
|
||||
VariantId::StructId(it) => it.lookup(db).container.module(db),
|
||||
VariantId::UnionId(it) => it.lookup(db).container.module(db),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModule for DefWithBodyId {
|
||||
fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
|
||||
match self {
|
||||
@ -465,6 +475,26 @@ impl HasModule for StaticLoc {
|
||||
}
|
||||
}
|
||||
|
||||
impl AttrDefId {
|
||||
pub fn krate(&self, db: &dyn db::DefDatabase) -> CrateId {
|
||||
match self {
|
||||
AttrDefId::ModuleId(it) => it.krate,
|
||||
AttrDefId::FieldId(it) => it.parent.module(db).krate,
|
||||
AttrDefId::AdtId(it) => it.module(db).krate,
|
||||
AttrDefId::FunctionId(it) => it.lookup(db).module(db).krate,
|
||||
AttrDefId::EnumVariantId(it) => it.parent.lookup(db).container.module(db).krate,
|
||||
AttrDefId::StaticId(it) => it.lookup(db).module(db).krate,
|
||||
AttrDefId::ConstId(it) => it.lookup(db).module(db).krate,
|
||||
AttrDefId::TraitId(it) => it.lookup(db).container.module(db).krate,
|
||||
AttrDefId::TypeAliasId(it) => it.lookup(db).module(db).krate,
|
||||
AttrDefId::ImplId(it) => it.lookup(db).container.module(db).krate,
|
||||
// FIXME: `MacroDefId` should store the defining module, then this can implement
|
||||
// `HasModule`
|
||||
AttrDefId::MacroDefId(it) => it.krate,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A helper trait for converting to MacroCallId
|
||||
pub trait AsMacroCall {
|
||||
fn as_call_id(
|
||||
|
Loading…
Reference in New Issue
Block a user