mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 14:03:35 +00:00
Auto merge of #15086 - Veykril:import-intern, r=Veykril
internal: Intern use and extern crate items like other items Looking a bit into supporting use aliases and attributes better
This commit is contained in:
commit
67e1f52062
10 changed files with 124 additions and 46 deletions
|
@ -462,6 +462,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),
|
||||||
};
|
};
|
||||||
|
|
||||||
let attrs = raw_attrs.filter(db.upcast(), def.krate(db));
|
let attrs = raw_attrs.filter(db.upcast(), def.krate(db));
|
||||||
|
@ -546,6 +547,7 @@ impl AttrsWithOwner {
|
||||||
.map(|source| ast::AnyHasAttrs::new(source[id.local_id].clone())),
|
.map(|source| ast::AnyHasAttrs::new(source[id.local_id].clone())),
|
||||||
},
|
},
|
||||||
AttrDefId::ExternBlockId(id) => any_has_attrs(db, id),
|
AttrDefId::ExternBlockId(id) => any_has_attrs(db, id),
|
||||||
|
AttrDefId::ExternCrateId(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))
|
||||||
|
|
|
@ -24,11 +24,12 @@ use crate::{
|
||||||
proc_macro::{parse_macro_name_and_helper_attrs, ProcMacroKind},
|
proc_macro::{parse_macro_name_and_helper_attrs, ProcMacroKind},
|
||||||
DefMap, MacroSubNs,
|
DefMap, MacroSubNs,
|
||||||
},
|
},
|
||||||
|
path::ImportAlias,
|
||||||
type_ref::{TraitRef, TypeBound, TypeRef},
|
type_ref::{TraitRef, TypeBound, TypeRef},
|
||||||
visibility::RawVisibility,
|
visibility::RawVisibility,
|
||||||
AssocItemId, AstIdWithPath, ConstId, ConstLoc, FunctionId, FunctionLoc, HasModule, ImplId,
|
AssocItemId, AstIdWithPath, ConstId, ConstLoc, ExternCrateId, FunctionId, FunctionLoc,
|
||||||
Intern, ItemContainerId, ItemLoc, Lookup, Macro2Id, MacroRulesId, ModuleId, ProcMacroId,
|
HasModule, ImplId, Intern, ItemContainerId, ItemLoc, Lookup, Macro2Id, MacroRulesId, ModuleId,
|
||||||
StaticId, TraitAliasId, TraitId, TypeAliasId, TypeAliasLoc,
|
ProcMacroId, StaticId, TraitAliasId, TraitId, TypeAliasId, TypeAliasLoc,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
@ -424,6 +425,7 @@ impl MacroRulesData {
|
||||||
Arc::new(MacroRulesData { name: makro.name.clone(), macro_export })
|
Arc::new(MacroRulesData { name: makro.name.clone(), macro_export })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct ProcMacroData {
|
pub struct ProcMacroData {
|
||||||
pub name: Name,
|
pub name: Name,
|
||||||
|
@ -460,6 +462,30 @@ impl ProcMacroData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct ExternCrateDeclData {
|
||||||
|
pub name: Name,
|
||||||
|
pub alias: Option<ImportAlias>,
|
||||||
|
pub visibility: RawVisibility,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ExternCrateDeclData {
|
||||||
|
pub(crate) fn extern_crate_decl_data_query(
|
||||||
|
db: &dyn DefDatabase,
|
||||||
|
extern_crate: ExternCrateId,
|
||||||
|
) -> Arc<ExternCrateDeclData> {
|
||||||
|
let loc = extern_crate.lookup(db);
|
||||||
|
let item_tree = loc.id.item_tree(db);
|
||||||
|
let extern_crate = &item_tree[loc.id.value];
|
||||||
|
|
||||||
|
Arc::new(Self {
|
||||||
|
name: extern_crate.name.clone(),
|
||||||
|
visibility: item_tree[extern_crate.visibility].clone(),
|
||||||
|
alias: extern_crate.alias.clone(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct ConstData {
|
pub struct ConstData {
|
||||||
/// `None` for `const _: () = ();`
|
/// `None` for `const _: () = ();`
|
||||||
|
|
|
@ -12,8 +12,8 @@ use crate::{
|
||||||
body::{scope::ExprScopes, Body, BodySourceMap},
|
body::{scope::ExprScopes, Body, BodySourceMap},
|
||||||
data::{
|
data::{
|
||||||
adt::{EnumData, StructData},
|
adt::{EnumData, StructData},
|
||||||
ConstData, FunctionData, ImplData, Macro2Data, MacroRulesData, ProcMacroData, StaticData,
|
ConstData, ExternCrateDeclData, FunctionData, ImplData, Macro2Data, MacroRulesData,
|
||||||
TraitAliasData, TraitData, TypeAliasData,
|
ProcMacroData, StaticData, TraitAliasData, TraitData, TypeAliasData,
|
||||||
},
|
},
|
||||||
generics::GenericParams,
|
generics::GenericParams,
|
||||||
import_map::ImportMap,
|
import_map::ImportMap,
|
||||||
|
@ -22,17 +22,21 @@ use crate::{
|
||||||
nameres::{diagnostics::DefDiagnostic, DefMap},
|
nameres::{diagnostics::DefDiagnostic, DefMap},
|
||||||
visibility::{self, Visibility},
|
visibility::{self, Visibility},
|
||||||
AttrDefId, BlockId, BlockLoc, ConstBlockId, ConstBlockLoc, ConstId, ConstLoc, DefWithBodyId,
|
AttrDefId, BlockId, BlockLoc, ConstBlockId, ConstBlockLoc, ConstId, ConstLoc, DefWithBodyId,
|
||||||
EnumId, EnumLoc, ExternBlockId, ExternBlockLoc, FunctionId, FunctionLoc, GenericDefId, ImplId,
|
EnumId, EnumLoc, ExternBlockId, ExternBlockLoc, ExternCrateId, ExternCrateLoc, FunctionId,
|
||||||
ImplLoc, InTypeConstId, InTypeConstLoc, LocalEnumVariantId, LocalFieldId, Macro2Id, Macro2Loc,
|
FunctionLoc, GenericDefId, ImplId, ImplLoc, ImportId, ImportLoc, InTypeConstId, InTypeConstLoc,
|
||||||
MacroRulesId, MacroRulesLoc, ProcMacroId, ProcMacroLoc, StaticId, StaticLoc, StructId,
|
LocalEnumVariantId, LocalFieldId, Macro2Id, Macro2Loc, MacroRulesId, MacroRulesLoc,
|
||||||
StructLoc, TraitAliasId, TraitAliasLoc, TraitId, TraitLoc, TypeAliasId, TypeAliasLoc, UnionId,
|
ProcMacroId, ProcMacroLoc, StaticId, StaticLoc, StructId, StructLoc, TraitAliasId,
|
||||||
UnionLoc, VariantId,
|
TraitAliasLoc, TraitId, TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, VariantId,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[salsa::query_group(InternDatabaseStorage)]
|
#[salsa::query_group(InternDatabaseStorage)]
|
||||||
pub trait InternDatabase: SourceDatabase {
|
pub trait InternDatabase: SourceDatabase {
|
||||||
// region: items
|
// region: items
|
||||||
#[salsa::interned]
|
#[salsa::interned]
|
||||||
|
fn intern_import(&self, loc: ImportLoc) -> ImportId;
|
||||||
|
#[salsa::interned]
|
||||||
|
fn intern_extern_crate(&self, loc: ExternCrateLoc) -> ExternCrateId;
|
||||||
|
#[salsa::interned]
|
||||||
fn intern_function(&self, loc: FunctionLoc) -> FunctionId;
|
fn intern_function(&self, loc: FunctionLoc) -> FunctionId;
|
||||||
#[salsa::interned]
|
#[salsa::interned]
|
||||||
fn intern_struct(&self, loc: StructLoc) -> StructId;
|
fn intern_struct(&self, loc: StructLoc) -> StructId;
|
||||||
|
@ -160,6 +164,9 @@ pub trait DefDatabase: InternDatabase + ExpandDatabase + Upcast<dyn ExpandDataba
|
||||||
#[salsa::invoke(ProcMacroData::proc_macro_data_query)]
|
#[salsa::invoke(ProcMacroData::proc_macro_data_query)]
|
||||||
fn proc_macro_data(&self, makro: ProcMacroId) -> Arc<ProcMacroData>;
|
fn proc_macro_data(&self, makro: ProcMacroId) -> Arc<ProcMacroData>;
|
||||||
|
|
||||||
|
#[salsa::invoke(ExternCrateDeclData::extern_crate_decl_data_query)]
|
||||||
|
fn extern_crate_decl_data(&self, extern_crate: ExternCrateId) -> Arc<ExternCrateDeclData>;
|
||||||
|
|
||||||
// endregion:data
|
// endregion:data
|
||||||
|
|
||||||
#[salsa::invoke(Body::body_with_source_map_query)]
|
#[salsa::invoke(Body::body_with_source_map_query)]
|
||||||
|
|
|
@ -8,8 +8,8 @@ use syntax::{ast, AstNode, AstPtr};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
dyn_map::{DynMap, Policy},
|
dyn_map::{DynMap, Policy},
|
||||||
ConstId, EnumId, EnumVariantId, FieldId, FunctionId, ImplId, LifetimeParamId, Macro2Id,
|
ConstId, EnumId, EnumVariantId, ExternCrateId, FieldId, FunctionId, ImplId, LifetimeParamId,
|
||||||
MacroRulesId, ProcMacroId, StaticId, StructId, TraitAliasId, TraitId, TypeAliasId,
|
Macro2Id, MacroRulesId, ProcMacroId, StaticId, StructId, TraitAliasId, TraitId, TypeAliasId,
|
||||||
TypeOrConstParamId, UnionId,
|
TypeOrConstParamId, UnionId,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ pub const TRAIT_ALIAS: Key<ast::TraitAlias, TraitAliasId> = Key::new();
|
||||||
pub const STRUCT: Key<ast::Struct, StructId> = Key::new();
|
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 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();
|
||||||
|
|
|
@ -14,8 +14,8 @@ use stdx::format_to;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::DefDatabase, per_ns::PerNs, visibility::Visibility, AdtId, BuiltinType, ConstId, HasModule,
|
db::DefDatabase, per_ns::PerNs, visibility::Visibility, AdtId, BuiltinType, ConstId,
|
||||||
ImplId, LocalModuleId, MacroId, ModuleDefId, ModuleId, TraitId,
|
ExternCrateId, HasModule, ImplId, LocalModuleId, MacroId, ModuleDefId, ModuleId, TraitId,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
@ -50,6 +50,7 @@ pub struct ItemScope {
|
||||||
unnamed_consts: Vec<ConstId>,
|
unnamed_consts: Vec<ConstId>,
|
||||||
/// Traits imported via `use Trait as _;`.
|
/// Traits imported via `use Trait as _;`.
|
||||||
unnamed_trait_imports: FxHashMap<TraitId, Visibility>,
|
unnamed_trait_imports: FxHashMap<TraitId, Visibility>,
|
||||||
|
extern_crate_decls: Vec<ExternCrateId>,
|
||||||
/// Macros visible in current module in legacy textual scope
|
/// Macros visible in current module in legacy textual scope
|
||||||
///
|
///
|
||||||
/// For macros invoked by an unqualified identifier like `bar!()`, `legacy_macros` will be searched in first.
|
/// For macros invoked by an unqualified identifier like `bar!()`, `legacy_macros` will be searched in first.
|
||||||
|
@ -188,7 +189,11 @@ impl ItemScope {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn define_impl(&mut self, imp: ImplId) {
|
pub(crate) fn define_impl(&mut self, imp: ImplId) {
|
||||||
self.impls.push(imp)
|
self.impls.push(imp);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn define_extern_crate_decl(&mut self, extern_crate: ExternCrateId) {
|
||||||
|
self.extern_crate_decls.push(extern_crate);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn define_unnamed_const(&mut self, konst: ConstId) {
|
pub(crate) fn define_unnamed_const(&mut self, konst: ConstId) {
|
||||||
|
@ -397,6 +402,7 @@ impl ItemScope {
|
||||||
legacy_macros,
|
legacy_macros,
|
||||||
attr_macros,
|
attr_macros,
|
||||||
derive_macros,
|
derive_macros,
|
||||||
|
extern_crate_decls,
|
||||||
} = self;
|
} = self;
|
||||||
types.shrink_to_fit();
|
types.shrink_to_fit();
|
||||||
values.shrink_to_fit();
|
values.shrink_to_fit();
|
||||||
|
@ -409,6 +415,7 @@ impl ItemScope {
|
||||||
legacy_macros.shrink_to_fit();
|
legacy_macros.shrink_to_fit();
|
||||||
attr_macros.shrink_to_fit();
|
attr_macros.shrink_to_fit();
|
||||||
derive_macros.shrink_to_fit();
|
derive_macros.shrink_to_fit();
|
||||||
|
extern_crate_decls.shrink_to_fit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,8 +88,8 @@ use crate::{
|
||||||
builtin_type::BuiltinType,
|
builtin_type::BuiltinType,
|
||||||
data::adt::VariantData,
|
data::adt::VariantData,
|
||||||
item_tree::{
|
item_tree::{
|
||||||
Const, Enum, Function, Impl, ItemTreeId, ItemTreeNode, MacroDef, MacroRules, Static,
|
Const, Enum, ExternCrate, Function, Impl, Import, ItemTreeId, ItemTreeNode, MacroDef,
|
||||||
Struct, Trait, TraitAlias, TypeAlias, Union,
|
MacroRules, Static, Struct, Trait, TraitAlias, TypeAlias, Union,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -313,6 +313,16 @@ pub struct ImplId(salsa::InternId);
|
||||||
type ImplLoc = ItemLoc<Impl>;
|
type ImplLoc = ItemLoc<Impl>;
|
||||||
impl_intern!(ImplId, ImplLoc, intern_impl, lookup_intern_impl);
|
impl_intern!(ImplId, ImplLoc, intern_impl, lookup_intern_impl);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
|
||||||
|
pub struct ImportId(salsa::InternId);
|
||||||
|
type ImportLoc = ItemLoc<Import>;
|
||||||
|
impl_intern!(ImportId, ImportLoc, intern_import, lookup_intern_import);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
|
||||||
|
pub struct ExternCrateId(salsa::InternId);
|
||||||
|
type ExternCrateLoc = ItemLoc<ExternCrate>;
|
||||||
|
impl_intern!(ExternCrateId, ExternCrateLoc, intern_extern_crate, lookup_intern_extern_crate);
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
|
||||||
pub struct ExternBlockId(salsa::InternId);
|
pub struct ExternBlockId(salsa::InternId);
|
||||||
type ExternBlockLoc = ItemLoc<ExternBlock>;
|
type ExternBlockLoc = ItemLoc<ExternBlock>;
|
||||||
|
@ -821,6 +831,7 @@ pub enum AttrDefId {
|
||||||
ImplId(ImplId),
|
ImplId(ImplId),
|
||||||
GenericParamId(GenericParamId),
|
GenericParamId(GenericParamId),
|
||||||
ExternBlockId(ExternBlockId),
|
ExternBlockId(ExternBlockId),
|
||||||
|
ExternCrateId(ExternCrateId),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_from!(
|
impl_from!(
|
||||||
|
@ -835,7 +846,8 @@ impl_from!(
|
||||||
TypeAliasId,
|
TypeAliasId,
|
||||||
MacroId(Macro2Id, MacroRulesId, ProcMacroId),
|
MacroId(Macro2Id, MacroRulesId, ProcMacroId),
|
||||||
ImplId,
|
ImplId,
|
||||||
GenericParamId
|
GenericParamId,
|
||||||
|
ExternCrateId
|
||||||
for AttrDefId
|
for AttrDefId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -927,6 +939,12 @@ impl HasModule for AdtId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HasModule for ExternCrateId {
|
||||||
|
fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
|
||||||
|
self.lookup(db).container
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl HasModule for VariantId {
|
impl HasModule for VariantId {
|
||||||
fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
|
fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
|
||||||
match self {
|
match self {
|
||||||
|
@ -1050,6 +1068,7 @@ impl AttrDefId {
|
||||||
.krate
|
.krate
|
||||||
}
|
}
|
||||||
AttrDefId::MacroId(it) => it.module(db).krate,
|
AttrDefId::MacroId(it) => it.module(db).krate,
|
||||||
|
AttrDefId::ExternCrateId(it) => it.lookup(db).container.krate,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,10 +52,10 @@ use crate::{
|
||||||
tt,
|
tt,
|
||||||
visibility::{RawVisibility, Visibility},
|
visibility::{RawVisibility, Visibility},
|
||||||
AdtId, AstId, AstIdWithPath, ConstLoc, CrateRootModuleId, EnumLoc, EnumVariantId,
|
AdtId, AstId, AstIdWithPath, ConstLoc, CrateRootModuleId, EnumLoc, EnumVariantId,
|
||||||
ExternBlockLoc, FunctionId, FunctionLoc, ImplLoc, Intern, ItemContainerId, LocalModuleId,
|
ExternBlockLoc, ExternCrateLoc, FunctionId, FunctionLoc, ImplLoc, ImportLoc, Intern,
|
||||||
Macro2Id, Macro2Loc, MacroExpander, MacroId, MacroRulesId, MacroRulesLoc, ModuleDefId,
|
ItemContainerId, LocalModuleId, Macro2Id, Macro2Loc, MacroExpander, MacroId, MacroRulesId,
|
||||||
ModuleId, ProcMacroId, ProcMacroLoc, StaticLoc, StructLoc, TraitAliasLoc, TraitLoc,
|
MacroRulesLoc, ModuleDefId, ModuleId, ProcMacroId, ProcMacroLoc, StaticLoc, StructLoc,
|
||||||
TypeAliasLoc, UnionLoc, UnresolvedMacro,
|
TraitAliasLoc, TraitLoc, TypeAliasLoc, UnionLoc, UnresolvedMacro,
|
||||||
};
|
};
|
||||||
|
|
||||||
static GLOB_RECURSION_LIMIT: Limit = Limit::new(100);
|
static GLOB_RECURSION_LIMIT: Limit = Limit::new(100);
|
||||||
|
@ -156,10 +156,9 @@ struct Import {
|
||||||
alias: Option<ImportAlias>,
|
alias: Option<ImportAlias>,
|
||||||
visibility: RawVisibility,
|
visibility: RawVisibility,
|
||||||
kind: ImportKind,
|
kind: ImportKind,
|
||||||
is_prelude: bool,
|
|
||||||
is_extern_crate: bool,
|
|
||||||
is_macro_use: bool,
|
|
||||||
source: ImportSource,
|
source: ImportSource,
|
||||||
|
is_prelude: bool,
|
||||||
|
is_macro_use: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Import {
|
impl Import {
|
||||||
|
@ -168,26 +167,23 @@ impl Import {
|
||||||
krate: CrateId,
|
krate: CrateId,
|
||||||
tree: &ItemTree,
|
tree: &ItemTree,
|
||||||
id: ItemTreeId<item_tree::Import>,
|
id: ItemTreeId<item_tree::Import>,
|
||||||
) -> Vec<Self> {
|
mut cb: impl FnMut(Self),
|
||||||
|
) {
|
||||||
let it = &tree[id.value];
|
let it = &tree[id.value];
|
||||||
let attrs = &tree.attrs(db, krate, ModItem::from(id.value).into());
|
let attrs = &tree.attrs(db, krate, ModItem::from(id.value).into());
|
||||||
let visibility = &tree[it.visibility];
|
let visibility = &tree[it.visibility];
|
||||||
let is_prelude = attrs.by_key("prelude_import").exists();
|
let is_prelude = attrs.by_key("prelude_import").exists();
|
||||||
|
|
||||||
let mut res = Vec::new();
|
|
||||||
it.use_tree.expand(|idx, path, kind, alias| {
|
it.use_tree.expand(|idx, path, kind, alias| {
|
||||||
res.push(Self {
|
cb(Self {
|
||||||
path,
|
path,
|
||||||
alias,
|
alias,
|
||||||
visibility: visibility.clone(),
|
visibility: visibility.clone(),
|
||||||
kind,
|
kind,
|
||||||
is_prelude,
|
is_prelude,
|
||||||
is_extern_crate: false,
|
|
||||||
is_macro_use: false,
|
is_macro_use: false,
|
||||||
source: ImportSource::Import { id, use_tree: idx },
|
source: ImportSource::Import { id, use_tree: idx },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_extern_crate(
|
fn from_extern_crate(
|
||||||
|
@ -205,7 +201,6 @@ impl Import {
|
||||||
visibility: visibility.clone(),
|
visibility: visibility.clone(),
|
||||||
kind: ImportKind::Plain,
|
kind: ImportKind::Plain,
|
||||||
is_prelude: false,
|
is_prelude: false,
|
||||||
is_extern_crate: true,
|
|
||||||
is_macro_use: attrs.by_key("macro_use").exists(),
|
is_macro_use: attrs.by_key("macro_use").exists(),
|
||||||
source: ImportSource::ExternCrate(id),
|
source: ImportSource::ExternCrate(id),
|
||||||
}
|
}
|
||||||
|
@ -776,7 +771,7 @@ impl DefCollector<'_> {
|
||||||
let _p = profile::span("resolve_import")
|
let _p = profile::span("resolve_import")
|
||||||
.detail(|| format!("{}", import.path.display(self.db.upcast())));
|
.detail(|| format!("{}", import.path.display(self.db.upcast())));
|
||||||
tracing::debug!("resolving import: {:?} ({:?})", import, self.def_map.data.edition);
|
tracing::debug!("resolving import: {:?} ({:?})", import, self.def_map.data.edition);
|
||||||
if import.is_extern_crate {
|
if matches!(import.source, ImportSource::ExternCrate { .. }) {
|
||||||
let name = import
|
let name = import
|
||||||
.path
|
.path
|
||||||
.as_ident()
|
.as_ident()
|
||||||
|
@ -867,7 +862,7 @@ impl DefCollector<'_> {
|
||||||
tracing::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def);
|
tracing::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def);
|
||||||
|
|
||||||
// extern crates in the crate root are special-cased to insert entries into the extern prelude: rust-lang/rust#54658
|
// extern crates in the crate root are special-cased to insert entries into the extern prelude: rust-lang/rust#54658
|
||||||
if import.is_extern_crate
|
if matches!(import.source, ImportSource::ExternCrate { .. })
|
||||||
&& self.def_map.block.is_none()
|
&& self.def_map.block.is_none()
|
||||||
&& module_id == DefMap::ROOT
|
&& module_id == DefMap::ROOT
|
||||||
{
|
{
|
||||||
|
@ -1585,21 +1580,34 @@ impl ModCollector<'_, '_> {
|
||||||
match item {
|
match item {
|
||||||
ModItem::Mod(m) => self.collect_module(m, &attrs),
|
ModItem::Mod(m) => self.collect_module(m, &attrs),
|
||||||
ModItem::Import(import_id) => {
|
ModItem::Import(import_id) => {
|
||||||
let imports = Import::from_use(
|
let _import_id = ImportLoc {
|
||||||
|
container: module,
|
||||||
|
id: ItemTreeId::new(self.tree_id, import_id),
|
||||||
|
}
|
||||||
|
.intern(db);
|
||||||
|
Import::from_use(
|
||||||
db,
|
db,
|
||||||
krate,
|
krate,
|
||||||
self.item_tree,
|
self.item_tree,
|
||||||
ItemTreeId::new(self.tree_id, import_id),
|
ItemTreeId::new(self.tree_id, import_id),
|
||||||
);
|
|import| {
|
||||||
self.def_collector.unresolved_imports.extend(imports.into_iter().map(
|
self.def_collector.unresolved_imports.push(ImportDirective {
|
||||||
|import| ImportDirective {
|
module_id: self.module_id,
|
||||||
module_id: self.module_id,
|
import,
|
||||||
import,
|
status: PartialResolvedImport::Unresolved,
|
||||||
status: PartialResolvedImport::Unresolved,
|
});
|
||||||
},
|
},
|
||||||
));
|
)
|
||||||
}
|
}
|
||||||
ModItem::ExternCrate(import_id) => {
|
ModItem::ExternCrate(import_id) => {
|
||||||
|
let extern_crate_id = ExternCrateLoc {
|
||||||
|
container: module,
|
||||||
|
id: ItemTreeId::new(self.tree_id, import_id),
|
||||||
|
}
|
||||||
|
.intern(db);
|
||||||
|
self.def_collector.def_map.modules[self.module_id]
|
||||||
|
.scope
|
||||||
|
.define_extern_crate_decl(extern_crate_id);
|
||||||
self.def_collector.unresolved_imports.push(ImportDirective {
|
self.def_collector.unresolved_imports.push(ImportDirective {
|
||||||
module_id: self.module_id,
|
module_id: self.module_id,
|
||||||
import: Import::from_extern_crate(
|
import: Import::from_extern_crate(
|
||||||
|
|
|
@ -22,10 +22,10 @@ use crate::{
|
||||||
per_ns::PerNs,
|
per_ns::PerNs,
|
||||||
visibility::{RawVisibility, Visibility},
|
visibility::{RawVisibility, Visibility},
|
||||||
AdtId, AssocItemId, ConstId, ConstParamId, CrateRootModuleId, DefWithBodyId, EnumId,
|
AdtId, AssocItemId, ConstId, ConstParamId, CrateRootModuleId, DefWithBodyId, EnumId,
|
||||||
EnumVariantId, ExternBlockId, FunctionId, GenericDefId, GenericParamId, HasModule, ImplId,
|
EnumVariantId, ExternBlockId, ExternCrateId, FunctionId, GenericDefId, GenericParamId,
|
||||||
ItemContainerId, LifetimeParamId, LocalModuleId, Lookup, Macro2Id, MacroId, MacroRulesId,
|
HasModule, ImplId, ItemContainerId, LifetimeParamId, LocalModuleId, Lookup, Macro2Id, MacroId,
|
||||||
ModuleDefId, ModuleId, ProcMacroId, StaticId, StructId, TraitAliasId, TraitId, TypeAliasId,
|
MacroRulesId, ModuleDefId, ModuleId, ProcMacroId, StaticId, StructId, TraitAliasId, TraitId,
|
||||||
TypeOrConstParamId, TypeOwnerId, TypeParamId, VariantId,
|
TypeAliasId, TypeOrConstParamId, TypeOwnerId, TypeParamId, VariantId,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -1018,6 +1018,12 @@ impl HasResolver for ExternBlockId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HasResolver for ExternCrateId {
|
||||||
|
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 {
|
||||||
|
|
|
@ -181,6 +181,7 @@ impl<'a> DeclValidator<'a> {
|
||||||
AttrDefId::TraitAliasId(taid) => Some(taid.lookup(self.db.upcast()).container.into()),
|
AttrDefId::TraitAliasId(taid) => Some(taid.lookup(self.db.upcast()).container.into()),
|
||||||
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()),
|
||||||
// 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 {
|
||||||
|
|
|
@ -141,6 +141,7 @@ fn resolve_doc_path(
|
||||||
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::MacroId(it) => it.resolver(db.upcast()),
|
AttrDefId::MacroId(it) => it.resolver(db.upcast()),
|
||||||
|
AttrDefId::ExternCrateId(it) => it.resolver(db.upcast()),
|
||||||
AttrDefId::GenericParamId(it) => match it {
|
AttrDefId::GenericParamId(it) => match it {
|
||||||
GenericParamId::TypeParamId(it) => it.parent(),
|
GenericParamId::TypeParamId(it) => it.parent(),
|
||||||
GenericParamId::ConstParamId(it) => it.parent(),
|
GenericParamId::ConstParamId(it) => it.parent(),
|
||||||
|
|
Loading…
Reference in a new issue