Skip to content
Merged
7 changes: 0 additions & 7 deletions compiler/rustc_middle/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,9 @@ pub struct ModChild {
pub reexport_chain: SmallVec<[Reexport; 2]>,
}

#[derive(Debug, TyEncodable, TyDecodable, HashStable)]
pub enum AmbigModChildKind {
GlobVsGlob,
GlobVsExpanded,
}

/// Same as `ModChild`, however, it includes ambiguity error.
#[derive(Debug, TyEncodable, TyDecodable, HashStable)]
pub struct AmbigModChild {
pub main: ModChild,
pub second: ModChild,
pub kind: AmbigModChildKind,
}
22 changes: 9 additions & 13 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use rustc_hir::def::{self, *};
use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
use rustc_index::bit_set::DenseBitSet;
use rustc_metadata::creader::LoadedMacro;
use rustc_middle::metadata::{AmbigModChildKind, ModChild, Reexport};
use rustc_middle::metadata::{ModChild, Reexport};
use rustc_middle::ty::{Feed, Visibility};
use rustc_middle::{bug, span_bug};
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind};
Expand All @@ -36,9 +36,9 @@ use crate::imports::{ImportData, ImportKind};
use crate::macros::{MacroRulesBinding, MacroRulesScope, MacroRulesScopeRef};
use crate::ref_mut::CmCell;
use crate::{
AmbiguityKind, BindingKey, ExternPreludeEntry, Finalize, MacroData, Module, ModuleKind,
ModuleOrUniformRoot, NameBinding, NameBindingData, NameBindingKind, ParentScope, PathResult,
ResolutionError, Resolver, Segment, Used, VisResolutionError, errors,
BindingKey, ExternPreludeEntry, Finalize, MacroData, Module, ModuleKind, ModuleOrUniformRoot,
NameBinding, NameBindingData, NameBindingKind, ParentScope, PathResult, ResolutionError,
Resolver, Segment, Used, VisResolutionError, errors,
};

type Res = def::Res<NodeId>;
Expand Down Expand Up @@ -82,7 +82,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
vis: Visibility<DefId>,
span: Span,
expansion: LocalExpnId,
ambiguity: Option<(NameBinding<'ra>, AmbiguityKind)>,
ambiguity: Option<NameBinding<'ra>>,
) {
let binding = self.arenas.alloc_name_binding(NameBindingData {
kind: NameBindingKind::Res(res),
Expand Down Expand Up @@ -254,7 +254,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
&child.main,
parent_scope,
children.len() + i,
Some((&child.second, child.kind)),
Some(&child.second),
)
}
}
Expand All @@ -265,7 +265,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
child: &ModChild,
parent_scope: ParentScope<'ra>,
child_index: usize,
ambig_child: Option<(&ModChild, AmbigModChildKind)>,
ambig_child: Option<&ModChild>,
) {
let parent = parent_scope.module;
let child_span = |this: &Self, reexport_chain: &[Reexport], res: def::Res<_>| {
Expand All @@ -280,15 +280,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
let span = child_span(self, reexport_chain, res);
let res = res.expect_non_local();
let expansion = parent_scope.expansion;
let ambig = ambig_child.map(|(ambig_child, ambig_kind)| {
let ambig = ambig_child.map(|ambig_child| {
let ModChild { ident: _, res, vis, ref reexport_chain } = *ambig_child;
let span = child_span(self, reexport_chain, res);
let res = res.expect_non_local();
let ambig_kind = match ambig_kind {
AmbigModChildKind::GlobVsGlob => AmbiguityKind::GlobVsGlob,
AmbigModChildKind::GlobVsExpanded => AmbiguityKind::GlobVsExpanded,
};
(self.arenas.new_res_binding(res, vis, span, expansion), ambig_kind)
self.arenas.new_res_binding(res, vis, span, expansion)
});

// Record primary definitions.
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,9 +1206,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}
}
}
Scope::Module(module, _) => {
Scope::ModuleNonGlobs(module, _) => {
this.add_module_candidates(module, suggestions, filter_fn, None);
}
Scope::ModuleGlobs(..) => {
// Already handled in `ModuleNonGlobs`.
}
Scope::MacroUsePrelude => {
suggestions.extend(this.macro_use_prelude.iter().filter_map(
|(name, binding)| {
Expand Down Expand Up @@ -2033,7 +2036,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
help_msgs.push(format!("use `::{ident}` to refer to this {thing} unambiguously"))
}

if let Scope::Module(module, _) = scope {
if let Scope::ModuleNonGlobs(module, _) | Scope::ModuleGlobs(module, _) = scope {
if module == self.graph_root {
help_msgs.push(format!(
"use `crate::{ident}` to refer to this {thing} unambiguously"
Expand Down
Loading
Loading