Skip to content

Commit 3f6077f

Browse files
Merge #6915
6915: Add `AttrDefId::krate` r=jonas-schievink a=jonas-schievink Access to the containing crate will be needed to handle `cfg_attr`. bors r+ Co-authored-by: Jonas Schievink <[email protected]>
2 parents ce8ec28 + eaeabbb commit 3f6077f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

crates/hir_def/src/lib.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,16 @@ impl HasModule for AdtId {
425425
}
426426
}
427427

428+
impl HasModule for VariantId {
429+
fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
430+
match self {
431+
VariantId::EnumVariantId(it) => it.parent.lookup(db).container.module(db),
432+
VariantId::StructId(it) => it.lookup(db).container.module(db),
433+
VariantId::UnionId(it) => it.lookup(db).container.module(db),
434+
}
435+
}
436+
}
437+
428438
impl HasModule for DefWithBodyId {
429439
fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
430440
match self {
@@ -465,6 +475,26 @@ impl HasModule for StaticLoc {
465475
}
466476
}
467477

478+
impl AttrDefId {
479+
pub fn krate(&self, db: &dyn db::DefDatabase) -> CrateId {
480+
match self {
481+
AttrDefId::ModuleId(it) => it.krate,
482+
AttrDefId::FieldId(it) => it.parent.module(db).krate,
483+
AttrDefId::AdtId(it) => it.module(db).krate,
484+
AttrDefId::FunctionId(it) => it.lookup(db).module(db).krate,
485+
AttrDefId::EnumVariantId(it) => it.parent.lookup(db).container.module(db).krate,
486+
AttrDefId::StaticId(it) => it.lookup(db).module(db).krate,
487+
AttrDefId::ConstId(it) => it.lookup(db).module(db).krate,
488+
AttrDefId::TraitId(it) => it.lookup(db).container.module(db).krate,
489+
AttrDefId::TypeAliasId(it) => it.lookup(db).module(db).krate,
490+
AttrDefId::ImplId(it) => it.lookup(db).container.module(db).krate,
491+
// FIXME: `MacroDefId` should store the defining module, then this can implement
492+
// `HasModule`
493+
AttrDefId::MacroDefId(it) => it.krate,
494+
}
495+
}
496+
}
497+
468498
/// A helper trait for converting to MacroCallId
469499
pub trait AsMacroCall {
470500
fn as_call_id(

0 commit comments

Comments
 (0)