Add import info to item scope dumps

This commit is contained in:
Lukas Wirth 2023-08-17 09:33:15 +02:00
parent af8048266c
commit c4e9b5ac64
8 changed files with 364 additions and 215 deletions

View file

@ -38,9 +38,9 @@ fn outer() {
"#, "#,
expect![[r#" expect![[r#"
block scope block scope
CrateStruct: t CrateStruct: ti
PlainStruct: t v PlainStruct: ti vi
SelfStruct: t SelfStruct: ti
Struct: v Struct: v
SuperStruct: _ SuperStruct: _
@ -66,7 +66,7 @@ fn outer() {
"#, "#,
expect![[r#" expect![[r#"
block scope block scope
imported: t v imported: ti vi
name: v name: v
crate crate
@ -92,9 +92,9 @@ fn outer() {
"#, "#,
expect![[r#" expect![[r#"
block scope block scope
inner1: t inner1: ti
inner2: v inner2: v
outer: v outer: vi
block scope block scope
inner: v inner: v
@ -121,7 +121,7 @@ struct Struct {}
"#, "#,
expect![[r#" expect![[r#"
block scope block scope
Struct: t Struct: ti
crate crate
Struct: t Struct: t
@ -153,7 +153,7 @@ fn outer() {
"#, "#,
expect![[r#" expect![[r#"
block scope block scope
ResolveMe: t ResolveMe: ti
block scope block scope
m2: t m2: t
@ -214,7 +214,7 @@ fn f() {
"#, "#,
expect![[r#" expect![[r#"
block scope block scope
ResolveMe: t ResolveMe: ti
block scope block scope
h: v h: v
@ -292,7 +292,7 @@ pub mod cov_mark {
nested: v nested: v
crate crate
cov_mark: t cov_mark: ti
f: v f: v
"#]], "#]],
); );

View file

@ -20,12 +20,6 @@ use crate::{
UseId, UseId,
}; };
#[derive(Copy, Clone, Debug)]
pub(crate) enum ImportType {
Glob,
Named,
}
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct PerNsGlobImports { pub struct PerNsGlobImports {
types: FxHashSet<(LocalModuleId, Name)>, types: FxHashSet<(LocalModuleId, Name)>,
@ -35,6 +29,12 @@ pub struct PerNsGlobImports {
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum ImportOrExternCrate { pub enum ImportOrExternCrate {
Import(ImportId),
ExternCrate(ExternCrateId),
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum ImportType {
Import(ImportId), Import(ImportId),
Glob(UseId), Glob(UseId),
ExternCrate(ExternCrateId), ExternCrate(ExternCrateId),
@ -47,13 +47,6 @@ impl ImportOrExternCrate {
_ => None, _ => None,
} }
} }
pub fn into_glob(self) -> Option<UseId> {
match self {
ImportOrExternCrate::Glob(it) => Some(it),
_ => None,
}
}
} }
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
@ -89,9 +82,9 @@ pub struct ItemScope {
unnamed_trait_imports: FxHashMap<TraitId, (Visibility, Option<ImportId>)>, unnamed_trait_imports: FxHashMap<TraitId, (Visibility, Option<ImportId>)>,
// the resolutions of the imports of this scope // the resolutions of the imports of this scope
use_imports_types: FxHashMap<UseId, ImportOrDef>, use_imports_types: FxHashMap<ImportOrExternCrate, ImportOrDef>,
use_imports_values: FxHashMap<UseId, ImportOrDef>, use_imports_values: FxHashMap<ImportId, ImportOrDef>,
use_imports_macros: FxHashMap<UseId, ImportOrDef>, use_imports_macros: FxHashMap<ImportId, ImportOrDef>,
use_decls: Vec<UseId>, use_decls: Vec<UseId>,
extern_crate_decls: Vec<ExternCrateId>, extern_crate_decls: Vec<ExternCrateId>,
@ -347,51 +340,185 @@ impl ItemScope {
glob_imports: &mut PerNsGlobImports, glob_imports: &mut PerNsGlobImports,
lookup: (LocalModuleId, Name), lookup: (LocalModuleId, Name),
def: PerNs, def: PerNs,
def_import_type: ImportType, import: Option<ImportType>,
) -> bool { ) -> bool {
let mut changed = false; let mut changed = false;
macro_rules! check_changed { if let Some(mut fld) = def.types {
( let existing = self.types.entry(lookup.1.clone());
$changed:ident,
( $this:ident / $def:ident ) . $field:ident,
$glob_imports:ident [ $lookup:ident ],
$def_import_type:ident
) => {{
if let Some(fld) = $def.$field {
let existing = $this.$field.entry($lookup.1.clone());
match existing { match existing {
Entry::Vacant(entry) => { Entry::Vacant(entry) => {
match $def_import_type { match import {
ImportType::Glob => { Some(ImportType::Glob(_)) => {
$glob_imports.$field.insert($lookup.clone()); glob_imports.types.insert(lookup.clone());
} }
ImportType::Named => { _ => _ = glob_imports.types.remove(&lookup),
$glob_imports.$field.remove(&$lookup);
} }
let import = match import {
Some(ImportType::ExternCrate(extern_crate)) => {
Some(ImportOrExternCrate::ExternCrate(extern_crate))
}
Some(ImportType::Import(import)) => {
Some(ImportOrExternCrate::Import(import))
}
None | Some(ImportType::Glob(_)) => None,
};
let prev = std::mem::replace(&mut fld.2, import);
if let Some(ImportOrExternCrate::Import(import)) = import {
self.use_imports_values.insert(
import,
match prev {
Some(ImportOrExternCrate::Import(import)) => {
ImportOrDef::Import(import)
}
Some(ImportOrExternCrate::ExternCrate(import)) => {
ImportOrDef::ExternCrate(import)
}
None => ImportOrDef::Def(fld.0),
},
);
} }
entry.insert(fld); entry.insert(fld);
$changed = true; changed = true;
}
Entry::Occupied(mut entry) if !matches!(import, Some(ImportType::Glob(..))) => {
if glob_imports.types.remove(&lookup) {
let import = match import {
Some(ImportType::ExternCrate(extern_crate)) => {
Some(ImportOrExternCrate::ExternCrate(extern_crate))
}
Some(ImportType::Import(import)) => {
Some(ImportOrExternCrate::Import(import))
}
None | Some(ImportType::Glob(_)) => None,
};
let prev = std::mem::replace(&mut fld.2, import);
if let Some(ImportOrExternCrate::Import(import)) = import {
self.use_imports_values.insert(
import,
match prev {
Some(ImportOrExternCrate::Import(import)) => {
ImportOrDef::Import(import)
}
Some(ImportOrExternCrate::ExternCrate(import)) => {
ImportOrDef::ExternCrate(import)
}
None => ImportOrDef::Def(fld.0),
},
);
} }
Entry::Occupied(mut entry)
if matches!($def_import_type, ImportType::Named) =>
{
if $glob_imports.$field.remove(&$lookup) {
cov_mark::hit!(import_shadowed); cov_mark::hit!(import_shadowed);
entry.insert(fld); entry.insert(fld);
$changed = true; changed = true;
} }
} }
_ => {} _ => {}
} }
} }
}};
if let Some(mut fld) = def.values {
let existing = self.values.entry(lookup.1.clone());
match existing {
Entry::Vacant(entry) => {
match import {
Some(ImportType::Glob(_)) => {
glob_imports.values.insert(lookup.clone());
}
_ => _ = glob_imports.values.remove(&lookup),
}
let import = match import {
Some(ImportType::Import(import)) => Some(import),
_ => None,
};
let prev = std::mem::replace(&mut fld.2, import);
if let Some(import) = import {
self.use_imports_values.insert(
import,
match prev {
Some(import) => ImportOrDef::Import(import),
None => ImportOrDef::Def(fld.0),
},
);
}
entry.insert(fld);
changed = true;
}
Entry::Occupied(mut entry) if !matches!(import, Some(ImportType::Glob(..))) => {
if glob_imports.values.remove(&lookup) {
cov_mark::hit!(import_shadowed);
let import = match import {
Some(ImportType::Import(import)) => Some(import),
_ => None,
};
let prev = std::mem::replace(&mut fld.2, import);
if let Some(import) = import {
self.use_imports_values.insert(
import,
match prev {
Some(import) => ImportOrDef::Import(import),
None => ImportOrDef::Def(fld.0),
},
);
}
entry.insert(fld);
changed = true;
}
}
_ => {}
}
} }
check_changed!(changed, (self / def).types, glob_imports[lookup], def_import_type); if let Some(mut fld) = def.macros {
check_changed!(changed, (self / def).values, glob_imports[lookup], def_import_type); let existing = self.macros.entry(lookup.1.clone());
check_changed!(changed, (self / def).macros, glob_imports[lookup], def_import_type); match existing {
Entry::Vacant(entry) => {
match import {
Some(ImportType::Glob(_)) => {
glob_imports.macros.insert(lookup.clone());
}
_ => _ = glob_imports.macros.remove(&lookup),
}
let import = match import {
Some(ImportType::Import(import)) => Some(import),
_ => None,
};
let prev = std::mem::replace(&mut fld.2, import);
if let Some(import) = import {
self.use_imports_macros.insert(
import,
match prev {
Some(import) => ImportOrDef::Import(import),
None => ImportOrDef::Def(fld.0.into()),
},
);
}
entry.insert(fld);
changed = true;
}
Entry::Occupied(mut entry) if !matches!(import, Some(ImportType::Glob(..))) => {
if glob_imports.macros.remove(&lookup) {
cov_mark::hit!(import_shadowed);
let import = match import {
Some(ImportType::Import(import)) => Some(import),
_ => None,
};
let prev = std::mem::replace(&mut fld.2, import);
if let Some(import) = import {
self.use_imports_macros.insert(
import,
match prev {
Some(import) => ImportOrDef::Import(import),
None => ImportOrDef::Def(fld.0.into()),
},
);
}
entry.insert(fld);
changed = true;
}
}
_ => {}
}
}
if def.is_none() && self.unresolved.insert(lookup.1) { if def.is_none() && self.unresolved.insert(lookup.1) {
changed = true; changed = true;
@ -430,14 +557,25 @@ impl ItemScope {
name.map_or("_".to_string(), |name| name.display(db).to_string()) name.map_or("_".to_string(), |name| name.display(db).to_string())
); );
if def.types.is_some() { if let Some((.., i)) = def.types {
buf.push_str(" t"); buf.push_str(" t");
match i {
Some(ImportOrExternCrate::Import(_)) => buf.push('i'),
Some(ImportOrExternCrate::ExternCrate(_)) => buf.push('e'),
None => (),
} }
if def.values.is_some() { }
if let Some((.., i)) = def.values {
buf.push_str(" v"); buf.push_str(" v");
if i.is_some() {
buf.push('i');
} }
if def.macros.is_some() { }
if let Some((.., i)) = def.macros {
buf.push_str(" m"); buf.push_str(" m");
if i.is_some() {
buf.push('i');
}
} }
if def.is_none() { if def.is_none() {
buf.push_str(" _"); buf.push_str(" _");

View file

@ -33,7 +33,7 @@ use crate::{
attr_macro_as_call_id, attr_macro_as_call_id,
db::DefDatabase, db::DefDatabase,
derive_macro_as_call_id, derive_macro_as_call_id,
item_scope::{ImportOrExternCrate, ImportType, PerNsGlobImports}, item_scope::{ImportId, ImportOrExternCrate, ImportType, PerNsGlobImports},
item_tree::{ item_tree::{
self, ExternCrate, Fields, FileItemTreeId, ImportKind, ItemTree, ItemTreeId, ItemTreeNode, self, ExternCrate, Fields, FileItemTreeId, ImportKind, ItemTree, ItemTreeId, ItemTreeNode,
MacroCall, MacroDef, MacroRules, Mod, ModItem, ModKind, TreeId, MacroCall, MacroDef, MacroRules, Mod, ModItem, ModKind, TreeId,
@ -146,7 +146,7 @@ impl PartialResolvedImport {
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq)]
enum ImportSource { enum ImportSource {
Use { use_tree: Idx<ast::UseTree>, id: UseId, is_prelude: bool }, Use { use_tree: Idx<ast::UseTree>, id: UseId, is_prelude: bool, kind: ImportKind },
ExternCrate { id: ExternCrateId }, ExternCrate { id: ExternCrateId },
} }
@ -155,7 +155,6 @@ struct Import {
path: ModPath, path: ModPath,
alias: Option<ImportAlias>, alias: Option<ImportAlias>,
visibility: RawVisibility, visibility: RawVisibility,
kind: ImportKind,
source: ImportSource, source: ImportSource,
} }
@ -174,8 +173,7 @@ impl Import {
path, path,
alias, alias,
visibility: visibility.clone(), visibility: visibility.clone(),
kind, source: ImportSource::Use { use_tree: idx, id, is_prelude, kind },
source: ImportSource::Use { use_tree: idx, id, is_prelude },
}); });
}); });
} }
@ -191,7 +189,6 @@ impl Import {
path: ModPath::from_segments(PathKind::Plain, iter::once(it.name.clone())), path: ModPath::from_segments(PathKind::Plain, iter::once(it.name.clone())),
alias: it.alias.clone(), alias: it.alias.clone(),
visibility: visibility.clone(), visibility: visibility.clone(),
kind: ImportKind::Plain,
source: ImportSource::ExternCrate { id }, source: ImportSource::ExternCrate { id },
} }
} }
@ -225,7 +222,7 @@ struct DefCollector<'a> {
db: &'a dyn DefDatabase, db: &'a dyn DefDatabase,
def_map: DefMap, def_map: DefMap,
deps: FxHashMap<Name, Dependency>, deps: FxHashMap<Name, Dependency>,
glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, Visibility)>>, glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, Visibility, UseId)>>,
unresolved_imports: Vec<ImportDirective>, unresolved_imports: Vec<ImportDirective>,
indeterminate_imports: Vec<ImportDirective>, indeterminate_imports: Vec<ImportDirective>,
unresolved_macros: Vec<MacroDirective>, unresolved_macros: Vec<MacroDirective>,
@ -547,7 +544,11 @@ impl DefCollector<'_> {
match per_ns.types { match per_ns.types {
Some((ModuleDefId::ModuleId(m), _, import)) => { Some((ModuleDefId::ModuleId(m), _, import)) => {
self.def_map.prelude = Some((m, import.and_then(ImportOrExternCrate::into_glob))); // FIXME: This should specifically look for a glob import somehow and record that here
self.def_map.prelude = Some((
m,
import.and_then(ImportOrExternCrate::into_import).map(|it| it.import),
));
} }
types => { types => {
tracing::debug!( tracing::debug!(
@ -649,7 +650,7 @@ impl DefCollector<'_> {
module_id, module_id,
&[(Some(name), PerNs::macros(macro_.into(), Visibility::Public))], &[(Some(name), PerNs::macros(macro_.into(), Visibility::Public))],
Visibility::Public, Visibility::Public,
ImportType::Named, None,
); );
} }
} }
@ -685,7 +686,7 @@ impl DefCollector<'_> {
module_id, module_id,
&[(Some(name), PerNs::macros(macro_.into(), Visibility::Public))], &[(Some(name), PerNs::macros(macro_.into(), Visibility::Public))],
vis, vis,
ImportType::Named, None,
); );
} }
@ -700,7 +701,7 @@ impl DefCollector<'_> {
module_id, module_id,
&[(Some(name), PerNs::macros(macro_.into(), Visibility::Public))], &[(Some(name), PerNs::macros(macro_.into(), Visibility::Public))],
Visibility::Public, Visibility::Public,
ImportType::Named, None,
); );
} }
@ -720,19 +721,22 @@ impl DefCollector<'_> {
// `#[macro_use]` brings macros into macro_use prelude. Yes, even non-`macro_rules!` // `#[macro_use]` brings macros into macro_use prelude. Yes, even non-`macro_rules!`
// macros. // macros.
let root_scope = &def_map[DefMap::ROOT].scope; let root_scope = &def_map[DefMap::ROOT].scope;
if let Some(names) = names { match names {
Some(names) => {
for name in names { for name in names {
// FIXME: Report diagnostic on 404. // FIXME: Report diagnostic on 404.
if let Some(def) = root_scope.get(&name).take_macros() { if let Some(def) = root_scope.get(&name).take_macros() {
self.def_map.macro_use_prelude.insert(name, (def, extern_crate)); self.def_map.macro_use_prelude.insert(name, (def, extern_crate));
} }
} }
} else { }
None => {
for (name, def) in root_scope.macros() { for (name, def) in root_scope.macros() {
self.def_map.macro_use_prelude.insert(name.clone(), (def, extern_crate)); self.def_map.macro_use_prelude.insert(name.clone(), (def, extern_crate));
} }
} }
} }
}
/// Tries to resolve every currently unresolved import. /// Tries to resolve every currently unresolved import.
fn resolve_imports(&mut self) -> ReachedFixedPoint { fn resolve_imports(&mut self) -> ReachedFixedPoint {
@ -836,8 +840,9 @@ impl DefCollector<'_> {
.resolve_visibility(self.db, module_id, &directive.import.visibility, false) .resolve_visibility(self.db, module_id, &directive.import.visibility, false)
.unwrap_or(Visibility::Public); .unwrap_or(Visibility::Public);
match import.kind { match import.source {
ImportKind::Plain | ImportKind::TypeOnly => { ImportSource::ExternCrate { .. }
| ImportSource::Use { kind: ImportKind::Plain | ImportKind::TypeOnly, .. } => {
let name = match &import.alias { let name = match &import.alias {
Some(ImportAlias::Alias(name)) => Some(name), Some(ImportAlias::Alias(name)) => Some(name),
Some(ImportAlias::Underscore) => None, Some(ImportAlias::Underscore) => None,
@ -850,15 +855,9 @@ impl DefCollector<'_> {
}, },
}; };
if import.kind == ImportKind::TypeOnly { let imp = match import.source {
def.values = None;
def.macros = None;
}
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 let ImportSource::ExternCrate { id, .. } = import.source { ImportSource::ExternCrate { id, .. } => {
if self.def_map.block.is_none() && module_id == DefMap::ROOT { if self.def_map.block.is_none() && module_id == DefMap::ROOT {
if let (Some(ModuleDefId::ModuleId(def)), Some(name)) = if let (Some(ModuleDefId::ModuleId(def)), Some(name)) =
(def.take_types(), name) (def.take_types(), name)
@ -871,11 +870,21 @@ impl DefCollector<'_> {
} }
} }
} }
ImportType::ExternCrate(id)
} }
ImportSource::Use { kind, id, use_tree, .. } => {
if kind == ImportKind::TypeOnly {
def.values = None;
def.macros = None;
}
ImportType::Import(ImportId { import: id, idx: use_tree })
}
};
tracing::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def);
self.update(module_id, &[(name.cloned(), def)], vis, ImportType::Named); self.update(module_id, &[(name.cloned(), def)], vis, Some(imp));
} }
ImportKind::Glob => { ImportSource::Use { kind: ImportKind::Glob, id, .. } => {
tracing::debug!("glob import: {:?}", import); tracing::debug!("glob import: {:?}", import);
match def.take_types() { match def.take_types() {
Some(ModuleDefId::ModuleId(m)) => { Some(ModuleDefId::ModuleId(m)) => {
@ -900,7 +909,7 @@ impl DefCollector<'_> {
.filter(|(_, res)| !res.is_none()) .filter(|(_, res)| !res.is_none())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
self.update(module_id, &items, vis, ImportType::Glob); self.update(module_id, &items, vis, Some(ImportType::Glob(id)));
} 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
@ -932,11 +941,11 @@ impl DefCollector<'_> {
.filter(|(_, res)| !res.is_none()) .filter(|(_, res)| !res.is_none())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
self.update(module_id, &items, vis, ImportType::Glob); self.update(module_id, &items, vis, Some(ImportType::Glob(id)));
// 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 = self.glob_imports.entry(m.local_id).or_default();
if !glob.iter().any(|(mid, _)| *mid == module_id) { if !glob.iter().any(|(mid, _, _)| *mid == module_id) {
glob.push((module_id, vis)); glob.push((module_id, vis, id));
} }
} }
} }
@ -962,7 +971,7 @@ impl DefCollector<'_> {
(Some(name), res) (Some(name), res)
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
self.update(module_id, &resolutions, vis, ImportType::Glob); self.update(module_id, &resolutions, vis, Some(ImportType::Glob(id)));
} }
Some(d) => { Some(d) => {
tracing::debug!("glob import {:?} from non-module/enum {:?}", import, d); tracing::debug!("glob import {:?} from non-module/enum {:?}", import, d);
@ -982,10 +991,10 @@ 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_type: ImportType, import: Option<ImportType>,
) { ) {
self.db.unwind_if_cancelled(); self.db.unwind_if_cancelled();
self.update_recursive(module_id, resolutions, vis, import_type, 0) self.update_recursive(module_id, resolutions, vis, import, 0)
} }
fn update_recursive( fn update_recursive(
@ -996,7 +1005,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_type: ImportType, import: Option<ImportType>,
depth: usize, depth: usize,
) { ) {
if GLOB_RECURSION_LIMIT.check(depth).is_err() { if GLOB_RECURSION_LIMIT.check(depth).is_err() {
@ -1013,7 +1022,7 @@ impl DefCollector<'_> {
&mut self.from_glob_import, &mut self.from_glob_import,
(module_id, name.clone()), (module_id, name.clone()),
res.with_visibility(vis), res.with_visibility(vis),
import_type, import,
); );
} }
None => { None => {
@ -1058,7 +1067,7 @@ impl DefCollector<'_> {
.get(&module_id) .get(&module_id)
.into_iter() .into_iter()
.flatten() .flatten()
.filter(|(glob_importing_module, _)| { .filter(|(glob_importing_module, _, _)| {
// we know all resolutions have the same visibility (`vis`), so we // we know all resolutions have the same visibility (`vis`), so we
// just need to check that once // just need to check that once
vis.is_visible_from_def_map(self.db, &self.def_map, *glob_importing_module) vis.is_visible_from_def_map(self.db, &self.def_map, *glob_importing_module)
@ -1066,12 +1075,12 @@ impl DefCollector<'_> {
.cloned() .cloned()
.collect::<Vec<_>>(); .collect::<Vec<_>>();
for (glob_importing_module, glob_import_vis) in glob_imports { for (glob_importing_module, glob_import_vis, use_) in glob_imports {
self.update_recursive( self.update_recursive(
glob_importing_module, glob_importing_module,
resolutions, resolutions,
glob_import_vis, glob_import_vis,
ImportType::Glob, Some(ImportType::Glob(use_)),
depth + 1, depth + 1,
); );
} }
@ -1474,7 +1483,9 @@ impl DefCollector<'_> {
} }
for directive in &self.unresolved_imports { for directive in &self.unresolved_imports {
if let ImportSource::Use { use_tree, id, is_prelude: _ } = directive.import.source { if let ImportSource::Use { use_tree, id, is_prelude: _, kind: _ } =
directive.import.source
{
if matches!( if matches!(
(directive.import.path.segments().first(), &directive.import.path.kind), (directive.import.path.segments().first(), &directive.import.path.kind),
(Some(krate), PathKind::Plain | PathKind::Abs) if diagnosed_extern_crates.contains(krate) (Some(krate), PathKind::Plain | PathKind::Abs) if diagnosed_extern_crates.contains(krate)
@ -1538,7 +1549,7 @@ impl ModCollector<'_, '_> {
module_id, module_id,
&[(Some(name.clone()), PerNs::from_def(id, vis, has_constructor))], &[(Some(name.clone()), PerNs::from_def(id, vis, has_constructor))],
vis, vis,
ImportType::Named, None,
) )
}; };
let resolve_vis = |def_map: &DefMap, visibility| { let resolve_vis = |def_map: &DefMap, visibility| {
@ -1968,7 +1979,7 @@ impl ModCollector<'_, '_> {
self.module_id, self.module_id,
&[(Some(name), PerNs::from_def(def, vis, false))], &[(Some(name), PerNs::from_def(def, vis, false))],
vis, vis,
ImportType::Named, None,
); );
res res
} }

View file

@ -168,7 +168,7 @@ pub struct Baz;
"#, "#,
expect![[r#" expect![[r#"
crate crate
Foo: t v Foo: ti vi
foo: t foo: t
crate::foo crate::foo
@ -194,8 +194,8 @@ pub enum Quux {};
"#, "#,
expect![[r#" expect![[r#"
crate crate
Baz: t v Baz: ti vi
Quux: t Quux: ti
foo: t foo: t
crate::foo crate::foo
@ -225,11 +225,11 @@ pub struct Baz;
"#, "#,
expect![[r#" expect![[r#"
crate crate
Baz: t v Baz: ti vi
foo: t foo: t
crate::foo crate::foo
Baz: t v Baz: ti vi
bar: t bar: t
crate::foo::bar crate::foo::bar
@ -274,7 +274,7 @@ use self::E::V;
expect![[r#" expect![[r#"
crate crate
E: t E: t
V: t v V: ti vi
"#]], "#]],
); );
} }
@ -307,7 +307,7 @@ pub struct FromLib;
crate::foo crate::foo
Bar: _ Bar: _
FromLib: t v FromLib: ti vi
"#]], "#]],
); );
} }
@ -328,7 +328,7 @@ pub struct Baz;
"#, "#,
expect![[r#" expect![[r#"
crate crate
Baz: t Baz: ti
foo: t foo: t
crate::foo crate::foo
@ -352,7 +352,7 @@ pub struct Baz;
"#, "#,
expect![[r#" expect![[r#"
crate crate
Baz: t v Baz: ti vi
"#]], "#]],
); );
} }
@ -375,13 +375,13 @@ pub struct Arc;
expect![[r#" expect![[r#"
crate crate
alloc: t alloc: t
alloc_crate: t alloc_crate: te
sync: t sync: t
crate::alloc crate::alloc
crate::sync crate::sync
Arc: t v Arc: ti vi
"#]], "#]],
); );
} }
@ -404,13 +404,13 @@ pub struct Arc;
expect![[r#" expect![[r#"
crate crate
alloc: t alloc: t
alloc_crate: t alloc_crate: te
sync: t sync: t
crate::alloc crate::alloc
crate::sync crate::sync
Arc: t v Arc: ti vi
"#]], "#]],
); );
} }
@ -426,7 +426,7 @@ extern crate self as bla;
"#, "#,
expect![[r#" expect![[r#"
crate crate
bla: t bla: te
"#]], "#]],
); );
} }
@ -447,7 +447,7 @@ pub struct Baz;
"#, "#,
expect![[r#" expect![[r#"
crate crate
Baz: t v Baz: ti vi
"#]], "#]],
); );
} }
@ -465,7 +465,7 @@ pub struct Bar;
"#, "#,
expect![[r#" expect![[r#"
crate crate
Bar: t v Bar: ti vi
foo: v foo: v
"#]], "#]],
); );
@ -493,7 +493,7 @@ fn no_std_prelude() {
"#, "#,
expect![[r#" expect![[r#"
crate crate
Rust: t v Rust: ti vi
"#]], "#]],
); );
} }
@ -517,7 +517,7 @@ fn edition_specific_preludes() {
"#, "#,
expect![[r#" expect![[r#"
crate crate
Rust2018: t v Rust2018: ti vi
"#]], "#]],
); );
check( check(
@ -534,7 +534,7 @@ fn edition_specific_preludes() {
"#, "#,
expect![[r#" expect![[r#"
crate crate
Rust2021: t v Rust2021: ti vi
"#]], "#]],
); );
} }
@ -563,8 +563,8 @@ pub mod prelude {
"#, "#,
expect![[r#" expect![[r#"
crate crate
Bar: t v Bar: ti vi
Foo: t v Foo: ti vi
"#]], "#]],
); );
} }
@ -590,7 +590,7 @@ pub mod prelude {
"#, "#,
expect![[r#" expect![[r#"
crate crate
Bar: t v Bar: ti vi
Baz: _ Baz: _
Foo: _ Foo: _
"#]], "#]],
@ -619,8 +619,8 @@ pub mod prelude {
expect![[r#" expect![[r#"
crate crate
Bar: _ Bar: _
Baz: t v Baz: ti vi
Foo: t v Foo: ti vi
"#]], "#]],
); );
} }
@ -643,7 +643,7 @@ mod b {
"#, "#,
expect![[r#" expect![[r#"
crate crate
T: t v T: ti vi
a: t a: t
b: t b: t
@ -816,8 +816,8 @@ fn bar() {}
expect![[r#" expect![[r#"
crate crate
bar: v bar: v
baz: v baz: vi
foo: t foo: ti
"#]], "#]],
); );
} }
@ -836,7 +836,7 @@ use self::m::S::{self};
"#, "#,
expect![[r#" expect![[r#"
crate crate
S: t S: ti
m: t m: t
crate::m crate::m
@ -860,8 +860,8 @@ pub const settings: () = ();
"#, "#,
expect![[r#" expect![[r#"
crate crate
Settings: t v Settings: ti vi
settings: v settings: vi
"#]], "#]],
) )
} }
@ -890,8 +890,8 @@ pub struct Struct;
"#, "#,
expect![[r#" expect![[r#"
crate crate
Struct: t v Struct: ti vi
dep: t dep: te
"#]], "#]],
); );
} }
@ -917,13 +917,13 @@ use some_module::unknown_func;
crate crate
other_module: t other_module: t
some_module: t some_module: t
unknown_func: v unknown_func: vi
crate::other_module crate::other_module
some_submodule: t some_submodule: t
crate::other_module::some_submodule crate::other_module::some_submodule
unknown_func: v unknown_func: vi
crate::some_module crate::some_module
unknown_func: v unknown_func: v

View file

@ -24,7 +24,7 @@ pub struct Baz;
foo: t foo: t
crate::foo crate::foo
Baz: t v Baz: ti vi
Foo: t v Foo: t v
bar: t bar: t
@ -237,9 +237,9 @@ pub mod baz { pub struct Bar; }
"#, "#,
expect![[r#" expect![[r#"
crate crate
Bar: t v Bar: ti vi
bar: t bar: t
baz: t baz: ti
foo: t foo: t
crate::bar crate::bar
@ -276,9 +276,9 @@ pub mod baz { pub struct Bar; }
"#, "#,
expect![[r#" expect![[r#"
crate crate
Bar: t v Bar: ti vi
bar: t bar: t
baz: t baz: ti
foo: t foo: t
crate::bar crate::bar
@ -323,7 +323,7 @@ mod d {
X: t v X: t v
crate::b crate::b
foo: t foo: ti
crate::c crate::c
foo: t foo: t
@ -332,8 +332,8 @@ mod d {
Y: t v Y: t v
crate::d crate::d
Y: t v Y: ti vi
foo: t foo: ti
"#]], "#]],
); );
} }
@ -355,7 +355,7 @@ use event::Event;
"#, "#,
expect![[r#" expect![[r#"
crate crate
Event: t Event: ti
event: t event: t
crate::event crate::event

View file

@ -203,8 +203,8 @@ macro_rules! bar {
expect![[r#" expect![[r#"
crate crate
Foo: t Foo: t
bar: m bar: mi
foo: m foo: mi
"#]], "#]],
); );
} }
@ -251,7 +251,7 @@ mod priv_mod {
Bar: t v Bar: t v
Foo: t v Foo: t v
bar: t bar: t
foo: t foo: te
crate::bar crate::bar
Baz: t v Baz: t v
@ -318,9 +318,9 @@ macro_rules! baz3 { () => { struct OkBaz3; } }
OkBaz1: t v OkBaz1: t v
OkBaz2: t v OkBaz2: t v
OkBaz3: t v OkBaz3: t v
all: t all: te
empty: t empty: te
multiple: t multiple: te
"#]], "#]],
); );
} }
@ -551,8 +551,8 @@ fn baz() {}
"#, "#,
expect![[r#" expect![[r#"
crate crate
bar: t m bar: ti mi
baz: t v m baz: ti v mi
foo: t m foo: t m
"#]], "#]],
); );
@ -583,7 +583,7 @@ mod m {
crate crate
Alias: t v Alias: t v
Direct: t v Direct: t v
foo: t foo: te
"#]], "#]],
); );
} }
@ -628,9 +628,9 @@ mod m {
m: t m: t
crate::m crate::m
alias1: m alias1: mi
alias2: m alias2: mi
alias3: m alias3: mi
not_found: _ not_found: _
"#]], "#]],
); );
@ -682,11 +682,11 @@ pub struct Baz;
"#, "#,
expect![[r#" expect![[r#"
crate crate
Bar: t v Bar: ti vi
Baz: t v Baz: ti vi
Foo: t v Foo: t v
FooSelf: t v FooSelf: ti vi
foo: t foo: te
m: t m: t
crate::m crate::m
@ -725,7 +725,7 @@ pub struct bar;
"#, "#,
expect![[r#" expect![[r#"
crate crate
bar: t v bar: ti vi
"#]], "#]],
); );
} }
@ -1340,7 +1340,7 @@ pub mod prelude {
crate crate
Ok: t v Ok: t v
bar: m bar: m
dep: t dep: te
foo: m foo: m
ok: v ok: v
"#]], "#]],
@ -1372,7 +1372,7 @@ macro_rules! mk_foo {
expect![[r#" expect![[r#"
crate crate
a: t a: t
lib: t lib: te
crate::a crate::a
Ok: t v Ok: t v
@ -1427,8 +1427,8 @@ pub mod prelude {
expect![[r#" expect![[r#"
crate crate
Ok: t v Ok: t v
bar: m bar: mi
foo: m foo: mi
ok: v ok: v
"#]], "#]],
); );

View file

@ -80,18 +80,18 @@ pub trait Iterator;
prelude: t prelude: t
crate::iter crate::iter
Iterator: t Iterator: ti
traits: t traits: t
crate::iter::traits crate::iter::traits
Iterator: t Iterator: ti
iterator: t iterator: t
crate::iter::traits::iterator crate::iter::traits::iterator
Iterator: t Iterator: t
crate::prelude crate::prelude
Iterator: t Iterator: ti
"#]], "#]],
); );
} }
@ -109,7 +109,7 @@ pub struct Bar;
"#, "#,
expect![[r#" expect![[r#"
crate crate
Bar: t v Bar: ti vi
foo: t foo: t
crate::foo crate::foo
@ -139,7 +139,7 @@ pub struct Baz;
"#, "#,
expect![[r#" expect![[r#"
crate crate
Bar: t v Bar: ti vi
r#async: t r#async: t
crate::r#async crate::r#async
@ -176,8 +176,8 @@ pub struct Bar;
"#, "#,
expect![[r#" expect![[r#"
crate crate
Bar: t v Bar: ti vi
Foo: t v Foo: ti vi
r#async: t r#async: t
crate::r#async crate::r#async
@ -207,7 +207,7 @@ pub struct Bar;
"#, "#,
expect![[r#" expect![[r#"
crate crate
Bar: t v Bar: ti vi
foo: t foo: t
crate::foo crate::foo
@ -236,7 +236,7 @@ pub struct Baz;
foo: t foo: t
crate::foo crate::foo
Baz: t v Baz: ti vi
bar: t bar: t
crate::foo::bar crate::foo::bar
@ -265,7 +265,7 @@ pub struct Baz;
foo: t foo: t
crate::foo crate::foo
Baz: t v Baz: ti vi
bar: t bar: t
crate::foo::bar crate::foo::bar
@ -292,7 +292,7 @@ use super::Baz;
foo: t foo: t
crate::foo crate::foo
Baz: t v Baz: ti vi
"#]], "#]],
); );
} }
@ -626,7 +626,7 @@ pub struct Baz;
"#, "#,
expect![[r#" expect![[r#"
crate crate
Baz: t v Baz: ti vi
foo: t foo: t
crate::foo crate::foo
@ -660,7 +660,7 @@ pub struct Baz;
foo: t foo: t
crate::foo crate::foo
Baz: t v Baz: ti vi
bar: t bar: t
crate::foo::bar crate::foo::bar
@ -694,7 +694,7 @@ pub struct Baz;
foo: t foo: t
crate::foo crate::foo
Baz: t v Baz: ti vi
bar: t bar: t
crate::foo::bar crate::foo::bar
@ -728,7 +728,7 @@ pub struct Baz;
foo: t foo: t
crate::foo crate::foo
Baz: t v Baz: ti vi
bar: t bar: t
crate::foo::bar crate::foo::bar
@ -868,7 +868,7 @@ pub mod hash { pub trait Hash {} }
"#, "#,
expect![[r#" expect![[r#"
crate crate
Hash: t Hash: ti
core: t core: t
crate::core crate::core

View file

@ -14,10 +14,10 @@ pub use i32 as int;
expect![[r#" expect![[r#"
crate crate
foo: t foo: t
int: t int: ti
crate::foo crate::foo
int: t int: ti
"#]], "#]],
); );
} }