mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Merge pull request #19018 from Veykril/push-wxqqunxwrply
internal: Record the use tree index in glob imports
This commit is contained in:
commit
6e4c29f7ce
@ -167,8 +167,8 @@ impl ImportMap {
|
|||||||
let attr_id = if let Some(import) = import {
|
let attr_id = if let Some(import) = import {
|
||||||
match import {
|
match import {
|
||||||
ImportOrExternCrate::ExternCrate(id) => Some(id.into()),
|
ImportOrExternCrate::ExternCrate(id) => Some(id.into()),
|
||||||
ImportOrExternCrate::Import(id) => Some(id.import.into()),
|
ImportOrExternCrate::Import(id) => Some(id.use_.into()),
|
||||||
ImportOrExternCrate::Glob(id) => Some(id.into()),
|
ImportOrExternCrate::Glob(id) => Some(id.use_.into()),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match item {
|
match item {
|
||||||
|
@ -31,7 +31,7 @@ pub struct PerNsGlobImports {
|
|||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
pub enum ImportOrExternCrate {
|
pub enum ImportOrExternCrate {
|
||||||
Glob(UseId),
|
Glob(GlobId),
|
||||||
Import(ImportId),
|
Import(ImportId),
|
||||||
ExternCrate(ExternCrateId),
|
ExternCrate(ExternCrateId),
|
||||||
}
|
}
|
||||||
@ -45,29 +45,41 @@ impl From<ImportOrGlob> for ImportOrExternCrate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ImportType> for ImportOrExternCrate {
|
|
||||||
fn from(value: ImportType) -> Self {
|
|
||||||
match value {
|
|
||||||
ImportType::Glob(it) => ImportOrExternCrate::Glob(it),
|
|
||||||
ImportType::Import(it) => ImportOrExternCrate::Import(it),
|
|
||||||
ImportType::ExternCrate(it) => ImportOrExternCrate::ExternCrate(it),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ImportOrExternCrate {
|
impl ImportOrExternCrate {
|
||||||
pub fn into_import(self) -> Option<ImportOrGlob> {
|
pub fn import_or_glob(self) -> Option<ImportOrGlob> {
|
||||||
match self {
|
match self {
|
||||||
ImportOrExternCrate::Import(it) => Some(ImportOrGlob::Import(it)),
|
ImportOrExternCrate::Import(it) => Some(ImportOrGlob::Import(it)),
|
||||||
ImportOrExternCrate::Glob(it) => Some(ImportOrGlob::Glob(it)),
|
ImportOrExternCrate::Glob(it) => Some(ImportOrGlob::Glob(it)),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn import(self) -> Option<ImportId> {
|
||||||
|
match self {
|
||||||
|
ImportOrExternCrate::Import(it) => Some(it),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn glob(self) -> Option<GlobId> {
|
||||||
|
match self {
|
||||||
|
ImportOrExternCrate::Glob(id) => Some(id),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn use_(self) -> Option<UseId> {
|
||||||
|
match self {
|
||||||
|
ImportOrExternCrate::Glob(id) => Some(id.use_),
|
||||||
|
ImportOrExternCrate::Import(id) => Some(id.use_),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
pub enum ImportOrGlob {
|
pub enum ImportOrGlob {
|
||||||
Glob(UseId),
|
Glob(GlobId),
|
||||||
Import(ImportId),
|
Import(ImportId),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,17 +91,11 @@ impl ImportOrGlob {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
|
||||||
pub(crate) enum ImportType {
|
|
||||||
Import(ImportId),
|
|
||||||
Glob(UseId),
|
|
||||||
ExternCrate(ExternCrateId),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
pub enum ImportOrDef {
|
pub enum ImportOrDef {
|
||||||
Import(ImportId),
|
Import(ImportId),
|
||||||
Glob(UseId),
|
Glob(GlobId),
|
||||||
ExternCrate(ExternCrateId),
|
ExternCrate(ExternCrateId),
|
||||||
Def(ModuleDefId),
|
Def(ModuleDefId),
|
||||||
}
|
}
|
||||||
@ -115,7 +121,13 @@ impl From<ImportOrGlob> for ImportOrDef {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
|
||||||
pub struct ImportId {
|
pub struct ImportId {
|
||||||
pub import: UseId,
|
pub use_: UseId,
|
||||||
|
pub idx: Idx<ast::UseTree>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
|
||||||
|
pub struct GlobId {
|
||||||
|
pub use_: UseId,
|
||||||
pub idx: Idx<ast::UseTree>,
|
pub idx: Idx<ast::UseTree>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +248,7 @@ impl ItemScope {
|
|||||||
self.use_imports_types
|
self.use_imports_types
|
||||||
.keys()
|
.keys()
|
||||||
.copied()
|
.copied()
|
||||||
.filter_map(ImportOrExternCrate::into_import)
|
.filter_map(ImportOrExternCrate::import_or_glob)
|
||||||
.chain(self.use_imports_values.keys().copied())
|
.chain(self.use_imports_values.keys().copied())
|
||||||
.chain(self.use_imports_macros.keys().copied())
|
.chain(self.use_imports_macros.keys().copied())
|
||||||
.filter_map(ImportOrGlob::into_import)
|
.filter_map(ImportOrGlob::into_import)
|
||||||
@ -252,7 +264,7 @@ impl ItemScope {
|
|||||||
while let Some(&m) = scope.use_imports_macros.get(&ImportOrGlob::Import(import)) {
|
while let Some(&m) = scope.use_imports_macros.get(&ImportOrGlob::Import(import)) {
|
||||||
match m {
|
match m {
|
||||||
ImportOrDef::Import(i) => {
|
ImportOrDef::Import(i) => {
|
||||||
let module_id = i.import.lookup(db).container;
|
let module_id = i.use_.lookup(db).container;
|
||||||
def_map = module_id.def_map(db);
|
def_map = module_id.def_map(db);
|
||||||
scope = &def_map[module_id.local_id].scope;
|
scope = &def_map[module_id.local_id].scope;
|
||||||
import = i;
|
import = i;
|
||||||
@ -268,7 +280,7 @@ impl ItemScope {
|
|||||||
while let Some(&m) = scope.use_imports_types.get(&ImportOrExternCrate::Import(import)) {
|
while let Some(&m) = scope.use_imports_types.get(&ImportOrExternCrate::Import(import)) {
|
||||||
match m {
|
match m {
|
||||||
ImportOrDef::Import(i) => {
|
ImportOrDef::Import(i) => {
|
||||||
let module_id = i.import.lookup(db).container;
|
let module_id = i.use_.lookup(db).container;
|
||||||
def_map = module_id.def_map(db);
|
def_map = module_id.def_map(db);
|
||||||
scope = &def_map[module_id.local_id].scope;
|
scope = &def_map[module_id.local_id].scope;
|
||||||
import = i;
|
import = i;
|
||||||
@ -284,7 +296,7 @@ impl ItemScope {
|
|||||||
while let Some(&m) = scope.use_imports_values.get(&ImportOrGlob::Import(import)) {
|
while let Some(&m) = scope.use_imports_values.get(&ImportOrGlob::Import(import)) {
|
||||||
match m {
|
match m {
|
||||||
ImportOrDef::Import(i) => {
|
ImportOrDef::Import(i) => {
|
||||||
let module_id = i.import.lookup(db).container;
|
let module_id = i.use_.lookup(db).container;
|
||||||
def_map = module_id.def_map(db);
|
def_map = module_id.def_map(db);
|
||||||
scope = &def_map[module_id.local_id].scope;
|
scope = &def_map[module_id.local_id].scope;
|
||||||
import = i;
|
import = i;
|
||||||
@ -545,9 +557,13 @@ impl ItemScope {
|
|||||||
self.unnamed_trait_imports.get(&tr).map(|trait_| trait_.vis)
|
self.unnamed_trait_imports.get(&tr).map(|trait_| trait_.vis)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn push_unnamed_trait(&mut self, tr: TraitId, vis: Visibility) {
|
pub(crate) fn push_unnamed_trait(
|
||||||
// FIXME: import
|
&mut self,
|
||||||
self.unnamed_trait_imports.insert(tr, Item { def: (), vis, import: None });
|
tr: TraitId,
|
||||||
|
vis: Visibility,
|
||||||
|
import: Option<ImportId>,
|
||||||
|
) {
|
||||||
|
self.unnamed_trait_imports.insert(tr, Item { def: (), vis, import });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn push_res_with_import(
|
pub(crate) fn push_res_with_import(
|
||||||
@ -555,7 +571,7 @@ impl ItemScope {
|
|||||||
glob_imports: &mut PerNsGlobImports,
|
glob_imports: &mut PerNsGlobImports,
|
||||||
lookup: (LocalModuleId, Name),
|
lookup: (LocalModuleId, Name),
|
||||||
def: PerNs,
|
def: PerNs,
|
||||||
import: Option<ImportType>,
|
import: Option<ImportOrExternCrate>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
|
|
||||||
@ -566,12 +582,11 @@ impl ItemScope {
|
|||||||
match existing {
|
match existing {
|
||||||
Entry::Vacant(entry) => {
|
Entry::Vacant(entry) => {
|
||||||
match import {
|
match import {
|
||||||
Some(ImportType::Glob(_)) => {
|
Some(ImportOrExternCrate::Glob(_)) => {
|
||||||
glob_imports.types.insert(lookup.clone());
|
glob_imports.types.insert(lookup.clone());
|
||||||
}
|
}
|
||||||
_ => _ = glob_imports.types.remove(&lookup),
|
_ => _ = glob_imports.types.remove(&lookup),
|
||||||
}
|
}
|
||||||
let import = import.map(Into::into);
|
|
||||||
let prev = std::mem::replace(&mut fld.import, import);
|
let prev = std::mem::replace(&mut fld.import, import);
|
||||||
if let Some(import) = import {
|
if let Some(import) = import {
|
||||||
self.use_imports_types
|
self.use_imports_types
|
||||||
@ -582,7 +597,7 @@ impl ItemScope {
|
|||||||
}
|
}
|
||||||
Entry::Occupied(mut entry) => {
|
Entry::Occupied(mut entry) => {
|
||||||
match import {
|
match import {
|
||||||
Some(ImportType::Glob(..)) => {
|
Some(ImportOrExternCrate::Glob(..)) => {
|
||||||
// Multiple globs may import the same item and they may
|
// Multiple globs may import the same item and they may
|
||||||
// override visibility from previously resolved globs. This is
|
// override visibility from previously resolved globs. This is
|
||||||
// currently handled by `DefCollector`, because we need to
|
// currently handled by `DefCollector`, because we need to
|
||||||
@ -591,7 +606,6 @@ impl ItemScope {
|
|||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
if glob_imports.types.remove(&lookup) {
|
if glob_imports.types.remove(&lookup) {
|
||||||
let import = import.map(Into::into);
|
|
||||||
let prev = std::mem::replace(&mut fld.import, import);
|
let prev = std::mem::replace(&mut fld.import, import);
|
||||||
if let Some(import) = import {
|
if let Some(import) = import {
|
||||||
self.use_imports_types.insert(
|
self.use_imports_types.insert(
|
||||||
@ -614,16 +628,12 @@ impl ItemScope {
|
|||||||
match existing {
|
match existing {
|
||||||
Entry::Vacant(entry) => {
|
Entry::Vacant(entry) => {
|
||||||
match import {
|
match import {
|
||||||
Some(ImportType::Glob(_)) => {
|
Some(ImportOrExternCrate::Glob(_)) => {
|
||||||
glob_imports.values.insert(lookup.clone());
|
glob_imports.values.insert(lookup.clone());
|
||||||
}
|
}
|
||||||
_ => _ = glob_imports.values.remove(&lookup),
|
_ => _ = glob_imports.values.remove(&lookup),
|
||||||
}
|
}
|
||||||
let import = match import {
|
let import = import.and_then(ImportOrExternCrate::import_or_glob);
|
||||||
Some(ImportType::Import(import)) => Some(ImportOrGlob::Import(import)),
|
|
||||||
Some(ImportType::Glob(u)) => Some(ImportOrGlob::Glob(u)),
|
|
||||||
_ => None,
|
|
||||||
};
|
|
||||||
let prev = std::mem::replace(&mut fld.import, import);
|
let prev = std::mem::replace(&mut fld.import, import);
|
||||||
if let Some(import) = import {
|
if let Some(import) = import {
|
||||||
self.use_imports_values
|
self.use_imports_values
|
||||||
@ -632,15 +642,13 @@ impl ItemScope {
|
|||||||
entry.insert(fld);
|
entry.insert(fld);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
Entry::Occupied(mut entry) if !matches!(import, Some(ImportType::Glob(..))) => {
|
Entry::Occupied(mut entry)
|
||||||
|
if !matches!(import, Some(ImportOrExternCrate::Glob(..))) =>
|
||||||
|
{
|
||||||
if glob_imports.values.remove(&lookup) {
|
if glob_imports.values.remove(&lookup) {
|
||||||
cov_mark::hit!(import_shadowed);
|
cov_mark::hit!(import_shadowed);
|
||||||
|
|
||||||
let import = match import {
|
let import = import.and_then(ImportOrExternCrate::import_or_glob);
|
||||||
Some(ImportType::Import(import)) => Some(ImportOrGlob::Import(import)),
|
|
||||||
Some(ImportType::Glob(u)) => Some(ImportOrGlob::Glob(u)),
|
|
||||||
_ => None,
|
|
||||||
};
|
|
||||||
let prev = std::mem::replace(&mut fld.import, import);
|
let prev = std::mem::replace(&mut fld.import, import);
|
||||||
if let Some(import) = import {
|
if let Some(import) = import {
|
||||||
self.use_imports_values
|
self.use_imports_values
|
||||||
@ -659,16 +667,12 @@ impl ItemScope {
|
|||||||
match existing {
|
match existing {
|
||||||
Entry::Vacant(entry) => {
|
Entry::Vacant(entry) => {
|
||||||
match import {
|
match import {
|
||||||
Some(ImportType::Glob(_)) => {
|
Some(ImportOrExternCrate::Glob(_)) => {
|
||||||
glob_imports.macros.insert(lookup.clone());
|
glob_imports.macros.insert(lookup.clone());
|
||||||
}
|
}
|
||||||
_ => _ = glob_imports.macros.remove(&lookup),
|
_ => _ = glob_imports.macros.remove(&lookup),
|
||||||
}
|
}
|
||||||
let import = match import {
|
let import = import.and_then(ImportOrExternCrate::import_or_glob);
|
||||||
Some(ImportType::Import(import)) => Some(ImportOrGlob::Import(import)),
|
|
||||||
Some(ImportType::Glob(u)) => Some(ImportOrGlob::Glob(u)),
|
|
||||||
_ => None,
|
|
||||||
};
|
|
||||||
let prev = std::mem::replace(&mut fld.import, import);
|
let prev = std::mem::replace(&mut fld.import, import);
|
||||||
if let Some(import) = import {
|
if let Some(import) = import {
|
||||||
self.use_imports_macros.insert(
|
self.use_imports_macros.insert(
|
||||||
@ -679,14 +683,12 @@ impl ItemScope {
|
|||||||
entry.insert(fld);
|
entry.insert(fld);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
Entry::Occupied(mut entry) if !matches!(import, Some(ImportType::Glob(..))) => {
|
Entry::Occupied(mut entry)
|
||||||
|
if !matches!(import, Some(ImportOrExternCrate::Glob(..))) =>
|
||||||
|
{
|
||||||
if glob_imports.macros.remove(&lookup) {
|
if glob_imports.macros.remove(&lookup) {
|
||||||
cov_mark::hit!(import_shadowed);
|
cov_mark::hit!(import_shadowed);
|
||||||
let import = match import {
|
let import = import.and_then(ImportOrExternCrate::import_or_glob);
|
||||||
Some(ImportType::Import(import)) => Some(ImportOrGlob::Import(import)),
|
|
||||||
Some(ImportType::Glob(u)) => Some(ImportOrGlob::Glob(u)),
|
|
||||||
_ => None,
|
|
||||||
};
|
|
||||||
let prev = std::mem::replace(&mut fld.import, import);
|
let prev = std::mem::replace(&mut fld.import, import);
|
||||||
if let Some(import) = import {
|
if let Some(import) = import {
|
||||||
self.use_imports_macros.insert(
|
self.use_imports_macros.insert(
|
||||||
@ -856,7 +858,7 @@ impl PerNs {
|
|||||||
match def {
|
match def {
|
||||||
ModuleDefId::ModuleId(_) => PerNs::types(def, v, import),
|
ModuleDefId::ModuleId(_) => PerNs::types(def, v, import),
|
||||||
ModuleDefId::FunctionId(_) => {
|
ModuleDefId::FunctionId(_) => {
|
||||||
PerNs::values(def, v, import.and_then(ImportOrExternCrate::into_import))
|
PerNs::values(def, v, import.and_then(ImportOrExternCrate::import_or_glob))
|
||||||
}
|
}
|
||||||
ModuleDefId::AdtId(adt) => match adt {
|
ModuleDefId::AdtId(adt) => match adt {
|
||||||
AdtId::UnionId(_) => PerNs::types(def, v, import),
|
AdtId::UnionId(_) => PerNs::types(def, v, import),
|
||||||
@ -871,14 +873,14 @@ impl PerNs {
|
|||||||
},
|
},
|
||||||
ModuleDefId::EnumVariantId(_) => PerNs::both(def, def, v, import),
|
ModuleDefId::EnumVariantId(_) => PerNs::both(def, def, v, import),
|
||||||
ModuleDefId::ConstId(_) | ModuleDefId::StaticId(_) => {
|
ModuleDefId::ConstId(_) | ModuleDefId::StaticId(_) => {
|
||||||
PerNs::values(def, v, import.and_then(ImportOrExternCrate::into_import))
|
PerNs::values(def, v, import.and_then(ImportOrExternCrate::import_or_glob))
|
||||||
}
|
}
|
||||||
ModuleDefId::TraitId(_) => PerNs::types(def, v, import),
|
ModuleDefId::TraitId(_) => PerNs::types(def, v, import),
|
||||||
ModuleDefId::TraitAliasId(_) => PerNs::types(def, v, import),
|
ModuleDefId::TraitAliasId(_) => PerNs::types(def, v, import),
|
||||||
ModuleDefId::TypeAliasId(_) => PerNs::types(def, v, import),
|
ModuleDefId::TypeAliasId(_) => PerNs::types(def, v, import),
|
||||||
ModuleDefId::BuiltinType(_) => PerNs::types(def, v, import),
|
ModuleDefId::BuiltinType(_) => PerNs::types(def, v, import),
|
||||||
ModuleDefId::MacroId(mac) => {
|
ModuleDefId::MacroId(mac) => {
|
||||||
PerNs::macros(mac, v, import.and_then(ImportOrExternCrate::into_import))
|
PerNs::macros(mac, v, import.and_then(ImportOrExternCrate::import_or_glob))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ use triomphe::Arc;
|
|||||||
use crate::{
|
use crate::{
|
||||||
attr::Attrs,
|
attr::Attrs,
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
item_scope::{ImportId, ImportOrExternCrate, ImportOrGlob, ImportType, PerNsGlobImports},
|
item_scope::{GlobId, ImportId, ImportOrExternCrate, PerNsGlobImports},
|
||||||
item_tree::{
|
item_tree::{
|
||||||
self, AttrOwner, FieldsShape, FileItemTreeId, ImportKind, ItemTree, ItemTreeId,
|
self, AttrOwner, FieldsShape, FileItemTreeId, ImportKind, ItemTree, ItemTreeId,
|
||||||
ItemTreeNode, Macro2, MacroCall, MacroRules, Mod, ModItem, ModKind, TreeId, UseTreeKind,
|
ItemTreeNode, Macro2, MacroCall, MacroRules, Mod, ModItem, ModKind, TreeId, UseTreeKind,
|
||||||
@ -208,7 +208,7 @@ struct DefCollector<'a> {
|
|||||||
def_map: DefMap,
|
def_map: DefMap,
|
||||||
// The dependencies of the current crate, including optional deps like `test`.
|
// The dependencies of the current crate, including optional deps like `test`.
|
||||||
deps: FxHashMap<Name, Dependency>,
|
deps: FxHashMap<Name, Dependency>,
|
||||||
glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, Visibility, UseId)>>,
|
glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, Visibility, GlobId)>>,
|
||||||
unresolved_imports: Vec<ImportDirective>,
|
unresolved_imports: Vec<ImportDirective>,
|
||||||
indeterminate_imports: Vec<(ImportDirective, PerNs)>,
|
indeterminate_imports: Vec<(ImportDirective, PerNs)>,
|
||||||
unresolved_macros: Vec<MacroDirective>,
|
unresolved_macros: Vec<MacroDirective>,
|
||||||
@ -524,14 +524,7 @@ impl DefCollector<'_> {
|
|||||||
|
|
||||||
match per_ns.types {
|
match per_ns.types {
|
||||||
Some(Item { def: ModuleDefId::ModuleId(m), import, .. }) => {
|
Some(Item { def: ModuleDefId::ModuleId(m), import, .. }) => {
|
||||||
// FIXME: This should specifically look for a glob import somehow and record that here
|
self.def_map.prelude = Some((m, import.and_then(ImportOrExternCrate::use_)));
|
||||||
self.def_map.prelude = Some((
|
|
||||||
m,
|
|
||||||
import
|
|
||||||
.and_then(ImportOrExternCrate::into_import)
|
|
||||||
.and_then(ImportOrGlob::into_import)
|
|
||||||
.map(|it| it.import),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
types => {
|
types => {
|
||||||
tracing::debug!(
|
tracing::debug!(
|
||||||
@ -848,13 +841,14 @@ impl DefCollector<'_> {
|
|||||||
def.values = None;
|
def.values = None;
|
||||||
def.macros = None;
|
def.macros = None;
|
||||||
}
|
}
|
||||||
let imp = ImportType::Import(ImportId { import: id, idx: use_tree });
|
let imp = ImportOrExternCrate::Import(ImportId { use_: id, idx: use_tree });
|
||||||
tracing::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def);
|
tracing::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def);
|
||||||
|
|
||||||
self.update(module_id, &[(name.cloned(), def)], vis, Some(imp));
|
self.update(module_id, &[(name.cloned(), def)], vis, Some(imp));
|
||||||
}
|
}
|
||||||
ImportSource { kind: ImportKind::Glob, id, is_prelude, .. } => {
|
ImportSource { kind: ImportKind::Glob, id, is_prelude, use_tree } => {
|
||||||
tracing::debug!("glob import: {:?}", import);
|
tracing::debug!("glob import: {:?}", import);
|
||||||
|
let glob = GlobId { use_: id, idx: use_tree };
|
||||||
match def.take_types() {
|
match def.take_types() {
|
||||||
Some(ModuleDefId::ModuleId(m)) => {
|
Some(ModuleDefId::ModuleId(m)) => {
|
||||||
if is_prelude {
|
if is_prelude {
|
||||||
@ -878,7 +872,12 @@ impl DefCollector<'_> {
|
|||||||
.filter(|(_, res)| !res.is_none())
|
.filter(|(_, res)| !res.is_none())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
self.update(module_id, &items, vis, Some(ImportType::Glob(id)));
|
self.update(
|
||||||
|
module_id,
|
||||||
|
&items,
|
||||||
|
vis,
|
||||||
|
Some(ImportOrExternCrate::Glob(glob)),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
// glob import from same crate => we do an initial
|
// glob import from same crate => we do an initial
|
||||||
// import, and then need to propagate any further
|
// import, and then need to propagate any further
|
||||||
@ -910,11 +909,16 @@ impl DefCollector<'_> {
|
|||||||
.filter(|(_, res)| !res.is_none())
|
.filter(|(_, res)| !res.is_none())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
self.update(module_id, &items, vis, Some(ImportType::Glob(id)));
|
self.update(
|
||||||
|
module_id,
|
||||||
|
&items,
|
||||||
|
vis,
|
||||||
|
Some(ImportOrExternCrate::Glob(glob)),
|
||||||
|
);
|
||||||
// record the glob import in case we add further items
|
// record the glob import in case we add further items
|
||||||
let glob = self.glob_imports.entry(m.local_id).or_default();
|
let glob_imports = self.glob_imports.entry(m.local_id).or_default();
|
||||||
match glob.iter_mut().find(|(mid, _, _)| *mid == module_id) {
|
match glob_imports.iter_mut().find(|(mid, _, _)| *mid == module_id) {
|
||||||
None => glob.push((module_id, vis, id)),
|
None => glob_imports.push((module_id, vis, glob)),
|
||||||
Some((_, old_vis, _)) => {
|
Some((_, old_vis, _)) => {
|
||||||
if let Some(new_vis) = old_vis.max(vis, &self.def_map) {
|
if let Some(new_vis) = old_vis.max(vis, &self.def_map) {
|
||||||
*old_vis = new_vis;
|
*old_vis = new_vis;
|
||||||
@ -947,7 +951,12 @@ impl DefCollector<'_> {
|
|||||||
(Some(name), res)
|
(Some(name), res)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
self.update(module_id, &resolutions, vis, Some(ImportType::Glob(id)));
|
self.update(
|
||||||
|
module_id,
|
||||||
|
&resolutions,
|
||||||
|
vis,
|
||||||
|
Some(ImportOrExternCrate::Glob(glob)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Some(d) => {
|
Some(d) => {
|
||||||
tracing::debug!("glob import {:?} from non-module/enum {:?}", import, d);
|
tracing::debug!("glob import {:?} from non-module/enum {:?}", import, d);
|
||||||
@ -967,7 +976,7 @@ impl DefCollector<'_> {
|
|||||||
resolutions: &[(Option<Name>, PerNs)],
|
resolutions: &[(Option<Name>, PerNs)],
|
||||||
// Visibility this import will have
|
// Visibility this import will have
|
||||||
vis: Visibility,
|
vis: Visibility,
|
||||||
import: Option<ImportType>,
|
import: Option<ImportOrExternCrate>,
|
||||||
) {
|
) {
|
||||||
self.db.unwind_if_cancelled();
|
self.db.unwind_if_cancelled();
|
||||||
self.update_recursive(module_id, resolutions, vis, import, 0)
|
self.update_recursive(module_id, resolutions, vis, import, 0)
|
||||||
@ -981,7 +990,7 @@ impl DefCollector<'_> {
|
|||||||
// All resolutions are imported with this visibility; the visibilities in
|
// All resolutions are imported with this visibility; the visibilities in
|
||||||
// the `PerNs` values are ignored and overwritten
|
// the `PerNs` values are ignored and overwritten
|
||||||
vis: Visibility,
|
vis: Visibility,
|
||||||
import: Option<ImportType>,
|
import: Option<ImportOrExternCrate>,
|
||||||
depth: usize,
|
depth: usize,
|
||||||
) {
|
) {
|
||||||
if GLOB_RECURSION_LIMIT.check(depth).is_err() {
|
if GLOB_RECURSION_LIMIT.check(depth).is_err() {
|
||||||
@ -997,8 +1006,10 @@ impl DefCollector<'_> {
|
|||||||
self.push_res_and_update_glob_vis(module_id, name, *res, vis, import);
|
self.push_res_and_update_glob_vis(module_id, name, *res, vis, import);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let tr = match res.take_types() {
|
let (tr, import) = match res.take_types_full() {
|
||||||
Some(ModuleDefId::TraitId(tr)) => tr,
|
Some(Item { def: ModuleDefId::TraitId(tr), vis: _, import }) => {
|
||||||
|
(tr, import)
|
||||||
|
}
|
||||||
Some(other) => {
|
Some(other) => {
|
||||||
tracing::debug!("non-trait `_` import of {:?}", other);
|
tracing::debug!("non-trait `_` import of {:?}", other);
|
||||||
continue;
|
continue;
|
||||||
@ -1024,7 +1035,11 @@ impl DefCollector<'_> {
|
|||||||
|
|
||||||
if should_update {
|
if should_update {
|
||||||
changed = true;
|
changed = true;
|
||||||
self.def_map.modules[module_id].scope.push_unnamed_trait(tr, vis);
|
self.def_map.modules[module_id].scope.push_unnamed_trait(
|
||||||
|
tr,
|
||||||
|
vis,
|
||||||
|
import.and_then(ImportOrExternCrate::import),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1046,13 +1061,13 @@ impl DefCollector<'_> {
|
|||||||
.cloned()
|
.cloned()
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
for (glob_importing_module, glob_import_vis, use_) in glob_imports {
|
for (glob_importing_module, glob_import_vis, glob) in glob_imports {
|
||||||
let vis = glob_import_vis.min(vis, &self.def_map).unwrap_or(glob_import_vis);
|
let vis = glob_import_vis.min(vis, &self.def_map).unwrap_or(glob_import_vis);
|
||||||
self.update_recursive(
|
self.update_recursive(
|
||||||
glob_importing_module,
|
glob_importing_module,
|
||||||
resolutions,
|
resolutions,
|
||||||
vis,
|
vis,
|
||||||
Some(ImportType::Glob(use_)),
|
Some(ImportOrExternCrate::Glob(glob)),
|
||||||
depth + 1,
|
depth + 1,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1064,7 +1079,7 @@ impl DefCollector<'_> {
|
|||||||
name: &Name,
|
name: &Name,
|
||||||
mut defs: PerNs,
|
mut defs: PerNs,
|
||||||
vis: Visibility,
|
vis: Visibility,
|
||||||
def_import_type: Option<ImportType>,
|
def_import_type: Option<ImportOrExternCrate>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
// `extern crate crate_name` things can be re-exported as `pub use crate_name`.
|
// `extern crate crate_name` things can be re-exported as `pub use crate_name`.
|
||||||
// But they cannot be re-exported as `pub use self::crate_name`, `pub use crate::crate_name`
|
// But they cannot be re-exported as `pub use self::crate_name`, `pub use crate::crate_name`
|
||||||
@ -1077,10 +1092,10 @@ impl DefCollector<'_> {
|
|||||||
let Some(ImportOrExternCrate::ExternCrate(_)) = def.import else {
|
let Some(ImportOrExternCrate::ExternCrate(_)) = def.import else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
let Some(ImportType::Import(id)) = def_import_type else {
|
let Some(ImportOrExternCrate::Import(id)) = def_import_type else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
let use_id = id.import.lookup(self.db).id;
|
let use_id = id.use_.lookup(self.db).id;
|
||||||
let item_tree = use_id.item_tree(self.db);
|
let item_tree = use_id.item_tree(self.db);
|
||||||
let use_kind = item_tree[use_id.value].use_tree.kind();
|
let use_kind = item_tree[use_id.value].use_tree.kind();
|
||||||
let UseTreeKind::Single { path, .. } = use_kind else {
|
let UseTreeKind::Single { path, .. } = use_kind else {
|
||||||
@ -1103,7 +1118,7 @@ impl DefCollector<'_> {
|
|||||||
|
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
|
|
||||||
if let Some(ImportType::Glob(_)) = def_import_type {
|
if let Some(ImportOrExternCrate::Glob(_)) = def_import_type {
|
||||||
let prev_defs = self.def_map[module_id].scope.get(name);
|
let prev_defs = self.def_map[module_id].scope.get(name);
|
||||||
|
|
||||||
// Multiple globs may import the same item and they may override visibility from
|
// Multiple globs may import the same item and they may override visibility from
|
||||||
@ -1730,7 +1745,7 @@ impl ModCollector<'_, '_> {
|
|||||||
),
|
),
|
||||||
)],
|
)],
|
||||||
vis,
|
vis,
|
||||||
Some(ImportType::ExternCrate(id)),
|
Some(ImportOrExternCrate::ExternCrate(id)),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if let Some(name) = name {
|
if let Some(name) = name {
|
||||||
|
@ -78,7 +78,7 @@ impl PerNs {
|
|||||||
values: Some(Item {
|
values: Some(Item {
|
||||||
def: values,
|
def: values,
|
||||||
vis,
|
vis,
|
||||||
import: import.and_then(ImportOrExternCrate::into_import),
|
import: import.and_then(ImportOrExternCrate::import_or_glob),
|
||||||
}),
|
}),
|
||||||
macros: None,
|
macros: None,
|
||||||
}
|
}
|
||||||
|
@ -160,8 +160,8 @@ impl<'a> SymbolCollector<'a> {
|
|||||||
|
|
||||||
let mut push_import = |this: &mut Self, i: ImportId, name: &Name, def: ModuleDefId| {
|
let mut push_import = |this: &mut Self, i: ImportId, name: &Name, def: ModuleDefId| {
|
||||||
let source = import_child_source_cache
|
let source = import_child_source_cache
|
||||||
.entry(i.import)
|
.entry(i.use_)
|
||||||
.or_insert_with(|| i.import.child_source(this.db.upcast()));
|
.or_insert_with(|| i.use_.child_source(this.db.upcast()));
|
||||||
let Some(use_tree_src) = source.value.get(i.idx) else { return };
|
let Some(use_tree_src) = source.value.get(i.idx) else { return };
|
||||||
let Some(name_ptr) = use_tree_src
|
let Some(name_ptr) = use_tree_src
|
||||||
.rename()
|
.rename()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user