use syntax::SmolStr;
use crate::{
- db::DefDatabase, AdtId, AttrDefId, CrateId, EnumId, FunctionId, ImplId, ModuleDefId, StaticId,
- StructId, TraitId,
+ db::DefDatabase, AdtId, AttrDefId, CrateId, EnumId, EnumVariantId, FunctionId, ImplId,
+ ModuleDefId, StaticId, StructId, TraitId,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
StaticId(StaticId),
StructId(StructId),
TraitId(TraitId),
+ EnumVariantId(EnumVariantId),
}
impl LangItemTarget {
_ => None,
}
}
+
+ pub fn as_enum_variant(self) -> Option<EnumVariantId> {
+ match self {
+ LangItemTarget::EnumVariantId(id) => Some(id),
+ _ => None,
+ }
+ }
}
#[derive(Default, Debug, Clone, PartialEq, Eq)]
for def in module_data.scope.declarations() {
match def {
ModuleDefId::TraitId(trait_) => {
- lang_items.collect_lang_item(db, trait_, LangItemTarget::TraitId)
+ lang_items.collect_lang_item(db, trait_, LangItemTarget::TraitId);
+ db.trait_data(trait_).items.iter().for_each(|&(_, assoc_id)| {
+ if let crate::AssocItemId::FunctionId(f) = assoc_id {
+ lang_items.collect_lang_item(db, f, LangItemTarget::FunctionId);
+ }
+ });
}
ModuleDefId::AdtId(AdtId::EnumId(e)) => {
- lang_items.collect_lang_item(db, e, LangItemTarget::EnumId)
+ lang_items.collect_lang_item(db, e, LangItemTarget::EnumId);
+ db.enum_data(e).variants.iter().for_each(|(local_id, _)| {
+ lang_items.collect_lang_item(
+ db,
+ EnumVariantId { parent: e, local_id },
+ LangItemTarget::EnumVariantId,
+ );
+ });
}
ModuleDefId::AdtId(AdtId::StructId(s)) => {
- lang_items.collect_lang_item(db, s, LangItemTarget::StructId)
+ lang_items.collect_lang_item(db, s, LangItemTarget::StructId);
}
ModuleDefId::FunctionId(f) => {
- lang_items.collect_lang_item(db, f, LangItemTarget::FunctionId)
+ lang_items.collect_lang_item(db, f, LangItemTarget::FunctionId);
}
ModuleDefId::StaticId(s) => {
- lang_items.collect_lang_item(db, s, LangItemTarget::StaticId)
+ lang_items.collect_lang_item(db, s, LangItemTarget::StaticId);
}
_ => {}
}
let _p = profile::span("lang_item_query");
let lang_items = db.crate_lang_items(start_crate);
let start_crate_target = lang_items.items.get(&item);
- if let Some(target) = start_crate_target {
- return Some(*target);
+ if let Some(&target) = start_crate_target {
+ return Some(target);
}
db.crate_graph()[start_crate]
.dependencies
) where
T: Into<AttrDefId> + Copy,
{
+ let _p = profile::span("collect_lang_item");
if let Some(lang_item_name) = lang_attr(db, item) {
self.items.entry(lang_item_name).or_insert_with(|| constructor(item));
}