Add currently unused UseId variants
This commit is contained in:
parent
f86f6a89eb
commit
ecb6d07d57
9 changed files with 34 additions and 4 deletions
|
@ -485,6 +485,7 @@ impl AttrsWithOwner {
|
||||||
},
|
},
|
||||||
AttrDefId::ExternBlockId(it) => attrs_from_item_tree_loc(db, it),
|
AttrDefId::ExternBlockId(it) => attrs_from_item_tree_loc(db, it),
|
||||||
AttrDefId::ExternCrateId(it) => attrs_from_item_tree_loc(db, it),
|
AttrDefId::ExternCrateId(it) => attrs_from_item_tree_loc(db, it),
|
||||||
|
AttrDefId::UseId(it) => attrs_from_item_tree_loc(db, it),
|
||||||
};
|
};
|
||||||
|
|
||||||
let attrs = raw_attrs.filter(db.upcast(), def.krate(db));
|
let attrs = raw_attrs.filter(db.upcast(), def.krate(db));
|
||||||
|
@ -570,6 +571,7 @@ impl AttrsWithOwner {
|
||||||
},
|
},
|
||||||
AttrDefId::ExternBlockId(id) => any_has_attrs(db, id),
|
AttrDefId::ExternBlockId(id) => any_has_attrs(db, id),
|
||||||
AttrDefId::ExternCrateId(id) => any_has_attrs(db, id),
|
AttrDefId::ExternCrateId(id) => any_has_attrs(db, id),
|
||||||
|
AttrDefId::UseId(id) => any_has_attrs(db, id),
|
||||||
};
|
};
|
||||||
|
|
||||||
AttrSourceMap::new(owner.as_ref().map(|node| node as &dyn HasAttrs))
|
AttrSourceMap::new(owner.as_ref().map(|node| node as &dyn HasAttrs))
|
||||||
|
|
|
@ -15,7 +15,7 @@ use crate::{
|
||||||
nameres::DefMap,
|
nameres::DefMap,
|
||||||
src::{HasChildSource, HasSource},
|
src::{HasChildSource, HasSource},
|
||||||
AdtId, AssocItemId, DefWithBodyId, EnumId, EnumVariantId, ExternCrateId, FieldId, ImplId,
|
AdtId, AssocItemId, DefWithBodyId, EnumId, EnumVariantId, ExternCrateId, FieldId, ImplId,
|
||||||
Lookup, MacroId, ModuleDefId, ModuleId, TraitId, VariantId,
|
Lookup, MacroId, ModuleDefId, ModuleId, TraitId, UseId, VariantId,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub trait ChildBySource {
|
pub trait ChildBySource {
|
||||||
|
@ -92,6 +92,7 @@ impl ChildBySource for ItemScope {
|
||||||
self.declarations().for_each(|item| add_module_def(db, res, file_id, item));
|
self.declarations().for_each(|item| add_module_def(db, res, file_id, item));
|
||||||
self.impls().for_each(|imp| add_impl(db, res, file_id, imp));
|
self.impls().for_each(|imp| add_impl(db, res, file_id, imp));
|
||||||
self.extern_crate_decls().for_each(|ext| add_extern_crate(db, res, file_id, ext));
|
self.extern_crate_decls().for_each(|ext| add_extern_crate(db, res, file_id, ext));
|
||||||
|
self.use_decls().for_each(|ext| add_use(db, res, file_id, ext));
|
||||||
self.unnamed_consts().for_each(|konst| {
|
self.unnamed_consts().for_each(|konst| {
|
||||||
let loc = konst.lookup(db);
|
let loc = konst.lookup(db);
|
||||||
if loc.id.file_id() == file_id {
|
if loc.id.file_id() == file_id {
|
||||||
|
@ -179,6 +180,12 @@ impl ChildBySource for ItemScope {
|
||||||
map[keys::EXTERN_CRATE].insert(loc.source(db).value, ext)
|
map[keys::EXTERN_CRATE].insert(loc.source(db).value, ext)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fn add_use(db: &dyn DefDatabase, map: &mut DynMap, file_id: HirFileId, ext: UseId) {
|
||||||
|
let loc = ext.lookup(db);
|
||||||
|
if loc.id.file_id() == file_id {
|
||||||
|
map[keys::USE].insert(loc.source(db).value, ext)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ use crate::{
|
||||||
dyn_map::{DynMap, Policy},
|
dyn_map::{DynMap, Policy},
|
||||||
ConstId, EnumId, EnumVariantId, ExternCrateId, FieldId, FunctionId, ImplId, LifetimeParamId,
|
ConstId, EnumId, EnumVariantId, ExternCrateId, FieldId, FunctionId, ImplId, LifetimeParamId,
|
||||||
Macro2Id, MacroRulesId, ProcMacroId, StaticId, StructId, TraitAliasId, TraitId, TypeAliasId,
|
Macro2Id, MacroRulesId, ProcMacroId, StaticId, StructId, TraitAliasId, TraitId, TypeAliasId,
|
||||||
TypeOrConstParamId, UnionId,
|
TypeOrConstParamId, UnionId, UseId,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub type Key<K, V> = crate::dyn_map::Key<K, V, AstPtrPolicy<K, V>>;
|
pub type Key<K, V> = crate::dyn_map::Key<K, V, AstPtrPolicy<K, V>>;
|
||||||
|
@ -26,6 +26,7 @@ pub const STRUCT: Key<ast::Struct, StructId> = Key::new();
|
||||||
pub const UNION: Key<ast::Union, UnionId> = Key::new();
|
pub const UNION: Key<ast::Union, UnionId> = Key::new();
|
||||||
pub const ENUM: Key<ast::Enum, EnumId> = Key::new();
|
pub const ENUM: Key<ast::Enum, EnumId> = Key::new();
|
||||||
pub const EXTERN_CRATE: Key<ast::ExternCrate, ExternCrateId> = Key::new();
|
pub const EXTERN_CRATE: Key<ast::ExternCrate, ExternCrateId> = Key::new();
|
||||||
|
pub const USE: Key<ast::Use, UseId> = Key::new();
|
||||||
|
|
||||||
pub const VARIANT: Key<ast::Variant, EnumVariantId> = Key::new();
|
pub const VARIANT: Key<ast::Variant, EnumVariantId> = Key::new();
|
||||||
pub const TUPLE_FIELD: Key<ast::TupleField, FieldId> = Key::new();
|
pub const TUPLE_FIELD: Key<ast::TupleField, FieldId> = Key::new();
|
||||||
|
|
|
@ -16,6 +16,7 @@ use syntax::ast;
|
||||||
use crate::{
|
use crate::{
|
||||||
db::DefDatabase, per_ns::PerNs, visibility::Visibility, AdtId, BuiltinType, ConstId,
|
db::DefDatabase, per_ns::PerNs, visibility::Visibility, AdtId, BuiltinType, ConstId,
|
||||||
ExternCrateId, HasModule, ImplId, LocalModuleId, MacroId, ModuleDefId, ModuleId, TraitId,
|
ExternCrateId, HasModule, ImplId, LocalModuleId, MacroId, ModuleDefId, ModuleId, TraitId,
|
||||||
|
UseId,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
@ -119,6 +120,11 @@ impl ItemScope {
|
||||||
self.extern_crate_decls.iter().copied()
|
self.extern_crate_decls.iter().copied()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn use_decls(&self) -> impl Iterator<Item = UseId> + ExactSizeIterator + '_ {
|
||||||
|
// FIXME: to be implemented
|
||||||
|
std::iter::empty()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn impls(&self) -> impl Iterator<Item = ImplId> + ExactSizeIterator + '_ {
|
pub fn impls(&self) -> impl Iterator<Item = ImplId> + ExactSizeIterator + '_ {
|
||||||
self.impls.iter().copied()
|
self.impls.iter().copied()
|
||||||
}
|
}
|
||||||
|
|
|
@ -842,6 +842,7 @@ pub enum AttrDefId {
|
||||||
GenericParamId(GenericParamId),
|
GenericParamId(GenericParamId),
|
||||||
ExternBlockId(ExternBlockId),
|
ExternBlockId(ExternBlockId),
|
||||||
ExternCrateId(ExternCrateId),
|
ExternCrateId(ExternCrateId),
|
||||||
|
UseId(UseId),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_from!(
|
impl_from!(
|
||||||
|
@ -1079,6 +1080,7 @@ impl AttrDefId {
|
||||||
}
|
}
|
||||||
AttrDefId::MacroId(it) => it.module(db).krate,
|
AttrDefId::MacroId(it) => it.module(db).krate,
|
||||||
AttrDefId::ExternCrateId(it) => it.lookup(db).container.krate,
|
AttrDefId::ExternCrateId(it) => it.lookup(db).container.krate,
|
||||||
|
AttrDefId::UseId(it) => it.lookup(db).container.krate,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ use crate::{
|
||||||
EnumVariantId, ExternBlockId, ExternCrateId, FunctionId, GenericDefId, GenericParamId,
|
EnumVariantId, ExternBlockId, ExternCrateId, FunctionId, GenericDefId, GenericParamId,
|
||||||
HasModule, ImplId, ItemContainerId, LifetimeParamId, LocalModuleId, Lookup, Macro2Id, MacroId,
|
HasModule, ImplId, ItemContainerId, LifetimeParamId, LocalModuleId, Lookup, Macro2Id, MacroId,
|
||||||
MacroRulesId, ModuleDefId, ModuleId, ProcMacroId, StaticId, StructId, TraitAliasId, TraitId,
|
MacroRulesId, ModuleDefId, ModuleId, ProcMacroId, StaticId, StructId, TraitAliasId, TraitId,
|
||||||
TypeAliasId, TypeOrConstParamId, TypeOwnerId, TypeParamId, VariantId,
|
TypeAliasId, TypeOrConstParamId, TypeOwnerId, TypeParamId, UseId, VariantId,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -1024,6 +1024,12 @@ impl HasResolver for ExternCrateId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HasResolver for UseId {
|
||||||
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
||||||
|
self.lookup(db).container.resolver(db)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl HasResolver for TypeOwnerId {
|
impl HasResolver for TypeOwnerId {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
||||||
match self {
|
match self {
|
||||||
|
|
|
@ -176,6 +176,7 @@ impl<'a> DeclValidator<'a> {
|
||||||
AttrDefId::ImplId(iid) => Some(iid.lookup(self.db.upcast()).container.into()),
|
AttrDefId::ImplId(iid) => Some(iid.lookup(self.db.upcast()).container.into()),
|
||||||
AttrDefId::ExternBlockId(id) => Some(id.lookup(self.db.upcast()).container.into()),
|
AttrDefId::ExternBlockId(id) => Some(id.lookup(self.db.upcast()).container.into()),
|
||||||
AttrDefId::ExternCrateId(id) => Some(id.lookup(self.db.upcast()).container.into()),
|
AttrDefId::ExternCrateId(id) => Some(id.lookup(self.db.upcast()).container.into()),
|
||||||
|
AttrDefId::UseId(id) => Some(id.lookup(self.db.upcast()).container.into()),
|
||||||
// These warnings should not explore macro definitions at all
|
// These warnings should not explore macro definitions at all
|
||||||
AttrDefId::MacroId(_) => None,
|
AttrDefId::MacroId(_) => None,
|
||||||
AttrDefId::AdtId(aid) => match aid {
|
AttrDefId::AdtId(aid) => match aid {
|
||||||
|
|
|
@ -173,6 +173,7 @@ fn resolve_doc_path(
|
||||||
AttrDefId::TypeAliasId(it) => it.resolver(db.upcast()),
|
AttrDefId::TypeAliasId(it) => it.resolver(db.upcast()),
|
||||||
AttrDefId::ImplId(it) => it.resolver(db.upcast()),
|
AttrDefId::ImplId(it) => it.resolver(db.upcast()),
|
||||||
AttrDefId::ExternBlockId(it) => it.resolver(db.upcast()),
|
AttrDefId::ExternBlockId(it) => it.resolver(db.upcast()),
|
||||||
|
AttrDefId::UseId(it) => it.resolver(db.upcast()),
|
||||||
AttrDefId::MacroId(it) => it.resolver(db.upcast()),
|
AttrDefId::MacroId(it) => it.resolver(db.upcast()),
|
||||||
AttrDefId::ExternCrateId(it) => it.resolver(db.upcast()),
|
AttrDefId::ExternCrateId(it) => it.resolver(db.upcast()),
|
||||||
AttrDefId::GenericParamId(it) => match it {
|
AttrDefId::GenericParamId(it) => match it {
|
||||||
|
|
|
@ -95,7 +95,7 @@ use hir_def::{
|
||||||
hir::{BindingId, LabelId},
|
hir::{BindingId, LabelId},
|
||||||
AdtId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, ExternCrateId, FieldId,
|
AdtId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, ExternCrateId, FieldId,
|
||||||
FunctionId, GenericDefId, GenericParamId, ImplId, LifetimeParamId, MacroId, ModuleId, StaticId,
|
FunctionId, GenericDefId, GenericParamId, ImplId, LifetimeParamId, MacroId, ModuleId, StaticId,
|
||||||
StructId, TraitAliasId, TraitId, TypeAliasId, TypeParamId, UnionId, VariantId,
|
StructId, TraitAliasId, TraitId, TypeAliasId, TypeParamId, UnionId, UseId, VariantId,
|
||||||
};
|
};
|
||||||
use hir_expand::{attrs::AttrId, name::AsName, HirFileId, MacroCallId};
|
use hir_expand::{attrs::AttrId, name::AsName, HirFileId, MacroCallId};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
@ -209,6 +209,10 @@ impl SourceToDefCtx<'_, '_> {
|
||||||
) -> Option<ExternCrateId> {
|
) -> Option<ExternCrateId> {
|
||||||
self.to_def(src, keys::EXTERN_CRATE)
|
self.to_def(src, keys::EXTERN_CRATE)
|
||||||
}
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub(super) fn use_to_def(&mut self, src: InFile<ast::Use>) -> Option<UseId> {
|
||||||
|
self.to_def(src, keys::USE)
|
||||||
|
}
|
||||||
pub(super) fn adt_to_def(
|
pub(super) fn adt_to_def(
|
||||||
&mut self,
|
&mut self,
|
||||||
InFile { file_id, value }: InFile<ast::Adt>,
|
InFile { file_id, value }: InFile<ast::Adt>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue