mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +00:00
Turn ImportSource into a struct
This commit is contained in:
parent
f7ca085690
commit
a898493b82
1 changed files with 54 additions and 46 deletions
|
@ -127,8 +127,11 @@ impl PartialResolvedImport {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
enum ImportSource {
|
||||
Use { use_tree: Idx<ast::UseTree>, id: UseId, is_prelude: bool, kind: ImportKind },
|
||||
struct ImportSource {
|
||||
use_tree: Idx<ast::UseTree>,
|
||||
id: UseId,
|
||||
is_prelude: bool,
|
||||
kind: ImportKind,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
|
@ -154,7 +157,7 @@ impl Import {
|
|||
path,
|
||||
alias,
|
||||
visibility: visibility.clone(),
|
||||
source: ImportSource::Use { use_tree: idx, id, is_prelude, kind },
|
||||
source: ImportSource { use_tree: idx, id, is_prelude, kind },
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -780,8 +783,6 @@ impl DefCollector<'_> {
|
|||
let _p = tracing::info_span!("resolve_import", import_path = %import.path.display(self.db.upcast(), Edition::LATEST))
|
||||
.entered();
|
||||
tracing::debug!("resolving import: {:?} ({:?})", import, self.def_map.data.edition);
|
||||
match import.source {
|
||||
ImportSource::Use { .. } => {
|
||||
let res = self.def_map.resolve_path_fp_with_macro(
|
||||
self.db,
|
||||
ResolveMode::Import,
|
||||
|
@ -809,8 +810,6 @@ impl DefCollector<'_> {
|
|||
PartialResolvedImport::Indeterminate(def)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn record_resolved_import(&mut self, directive: &ImportDirective) {
|
||||
let _p = tracing::info_span!("record_resolved_import").entered();
|
||||
|
@ -824,7 +823,12 @@ impl DefCollector<'_> {
|
|||
.unwrap_or(Visibility::Public);
|
||||
|
||||
match import.source {
|
||||
ImportSource::Use { kind: ImportKind::Plain | ImportKind::TypeOnly, .. } => {
|
||||
ImportSource {
|
||||
kind: kind @ (ImportKind::Plain | ImportKind::TypeOnly),
|
||||
id,
|
||||
use_tree,
|
||||
..
|
||||
} => {
|
||||
let name = match &import.alias {
|
||||
Some(ImportAlias::Alias(name)) => Some(name),
|
||||
Some(ImportAlias::Underscore) => None,
|
||||
|
@ -837,24 +841,20 @@ impl DefCollector<'_> {
|
|||
},
|
||||
};
|
||||
|
||||
let imp = match import.source {
|
||||
ImportSource::Use { kind, id, use_tree, .. } => {
|
||||
if kind == ImportKind::TypeOnly {
|
||||
def.values = None;
|
||||
def.macros = None;
|
||||
}
|
||||
ImportType::Import(ImportId { import: id, idx: use_tree })
|
||||
}
|
||||
};
|
||||
let imp = ImportType::Import(ImportId { import: id, idx: use_tree });
|
||||
tracing::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def);
|
||||
|
||||
self.update(module_id, &[(name.cloned(), def)], vis, Some(imp));
|
||||
}
|
||||
ImportSource::Use { kind: ImportKind::Glob, id, .. } => {
|
||||
ImportSource { kind: ImportKind::Glob, id, is_prelude, .. } => {
|
||||
tracing::debug!("glob import: {:?}", import);
|
||||
match def.take_types() {
|
||||
Some(ModuleDefId::ModuleId(m)) => {
|
||||
if let ImportSource::Use { id, is_prelude: true, .. } = import.source {
|
||||
if is_prelude {
|
||||
// Note: This dodgily overrides the injected prelude. The rustc
|
||||
// implementation seems to work the same though.
|
||||
cov_mark::hit!(std_prelude);
|
||||
|
@ -1509,18 +1509,26 @@ impl DefCollector<'_> {
|
|||
}
|
||||
|
||||
// Emit diagnostics for all remaining unresolved imports.
|
||||
for directive in &self.unresolved_imports {
|
||||
let ImportSource::Use { use_tree, id, is_prelude: _, kind: _ } =
|
||||
directive.import.source;
|
||||
for import in &self.unresolved_imports {
|
||||
let &ImportDirective {
|
||||
module_id,
|
||||
import:
|
||||
Import {
|
||||
ref path,
|
||||
source: ImportSource { use_tree, id, is_prelude: _, kind: _ },
|
||||
..
|
||||
},
|
||||
..
|
||||
} = import;
|
||||
if matches!(
|
||||
(directive.import.path.segments().first(), &directive.import.path.kind),
|
||||
(path.segments().first(), &path.kind),
|
||||
(Some(krate), PathKind::Plain | PathKind::Abs) if self.unresolved_extern_crates.contains(krate)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
let item_tree_id = id.lookup(self.db).id;
|
||||
self.def_map.diagnostics.push(DefDiagnostic::unresolved_import(
|
||||
directive.module_id,
|
||||
module_id,
|
||||
item_tree_id,
|
||||
use_tree,
|
||||
));
|
||||
|
|
Loading…
Reference in a new issue