Skip to content

Commit 45272bb

Browse files
committed
resolve: re-export ambiguity in extern crate as warning
1 parent a399117 commit 45272bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+671
-84
lines changed

compiler/rustc_errors/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,9 @@ pub fn report_ambiguity_error<'a, G: EmissionGuarantee>(
16951695
for help_msg in ambiguity.b1_help_msgs {
16961696
db.help(help_msg);
16971697
}
1698+
if ambiguity.extern_crate {
1699+
return;
1700+
}
16981701
db.span_note(ambiguity.b2_span, ambiguity.b2_note_msg);
16991702
for help_msg in ambiguity.b2_help_msgs {
17001703
db.help(help_msg);

compiler/rustc_lint_defs/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,8 @@ impl StableCompare for LintId {
553553

554554
#[derive(Debug)]
555555
pub struct AmbiguityErrorDiag {
556+
/// Does this ambiguity binding come from a different crate?
557+
pub extern_crate: bool,
556558
pub msg: String,
557559
pub span: Span,
558560
pub label_span: Span,

compiler/rustc_metadata/src/rmeta/decoder.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,21 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
12501250
})
12511251
}
12521252

1253+
fn get_ambiguity_module_children(
1254+
self,
1255+
id: DefIndex,
1256+
sess: &'a Session,
1257+
) -> impl Iterator<Item = AmbiguityModChild> + 'a {
1258+
iter::from_coroutine(move || {
1259+
let children = self.root.tables.ambiguity_module_children.get(self, id);
1260+
if !children.is_default() {
1261+
for child in children.decode((self, sess)) {
1262+
yield child;
1263+
}
1264+
}
1265+
})
1266+
}
1267+
12531268
fn is_ctfe_mir_available(self, id: DefIndex) -> bool {
12541269
self.root.tables.mir_for_ctfe.get(self, id).is_some()
12551270
}

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_hir::def::{CtorKind, DefKind, Res};
1111
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE};
1212
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
1313
use rustc_middle::arena::ArenaAllocatable;
14-
use rustc_middle::metadata::ModChild;
14+
use rustc_middle::metadata::{AmbiguityModChild, ModChild};
1515
use rustc_middle::middle::exported_symbols::ExportedSymbol;
1616
use rustc_middle::middle::stability::DeprecationEntry;
1717
use rustc_middle::query::ExternProviders;
@@ -581,6 +581,16 @@ impl CStore {
581581
self.get_crate_data_mut(cnum).dependencies = dependencies;
582582
}
583583
}
584+
585+
pub fn ambiguity_module_children_untracked(
586+
&self,
587+
def_id: DefId,
588+
sess: &Session,
589+
) -> Vec<AmbiguityModChild> {
590+
self.get_crate_data(def_id.krate)
591+
.get_ambiguity_module_children(def_id.index, sess)
592+
.collect()
593+
}
584594
}
585595

586596
impl CrateStore for CStore {

compiler/rustc_metadata/src/rmeta/encoder.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
15681568

15691569
record_defaulted_array!(self.tables.module_children_reexports[def_id] <-
15701570
module_children.iter().filter(|child| !child.reexport_chain.is_empty()));
1571+
1572+
record_defaulted_array!(self.tables.ambiguity_module_children[def_id] <- tcx.ambiguity_module_children_local(local_def_id));
15711573
}
15721574
}
15731575

compiler/rustc_metadata/src/rmeta/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_hir::definitions::DefKey;
1717
use rustc_hir::lang_items::LangItem;
1818
use rustc_index::bit_set::BitSet;
1919
use rustc_index::IndexVec;
20-
use rustc_middle::metadata::ModChild;
20+
use rustc_middle::metadata::{AmbiguityModChild, ModChild};
2121
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
2222
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo};
2323
use rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault;
@@ -398,6 +398,7 @@ define_tables! {
398398
// individually instead of `DefId`s.
399399
module_children_reexports: Table<DefIndex, LazyArray<ModChild>>,
400400
cross_crate_inlinable: Table<DefIndex, bool>,
401+
ambiguity_module_children: Table<DefIndex, LazyArray<AmbiguityModChild>>,
401402

402403
- optional:
403404
attributes: Table<DefIndex, LazyArray<ast::Attribute>>,

compiler/rustc_middle/src/metadata.rs

+3
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,6 @@ pub struct ModChild {
4444
/// Empty if the module child is a proper item.
4545
pub reexport_chain: SmallVec<[Reexport; 2]>,
4646
}
47+
48+
/// Same as `ModChild`, however, it includes ambiguity error.
49+
pub type AmbiguityModChild = ModChild;

compiler/rustc_middle/src/ty/context.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::arena::Arena;
88
use crate::dep_graph::{DepGraph, DepKindStruct};
99
use crate::infer::canonical::{CanonicalParamEnvCache, CanonicalVarInfo, CanonicalVarInfos};
1010
use crate::lint::struct_lint_level;
11-
use crate::metadata::ModChild;
11+
use crate::metadata::{AmbiguityModChild, ModChild};
1212
use crate::middle::codegen_fn_attrs::CodegenFnAttrs;
1313
use crate::middle::resolve_bound_vars;
1414
use crate::middle::stability;
@@ -2286,6 +2286,10 @@ impl<'tcx> TyCtxt<'tcx> {
22862286
pub fn module_children_local(self, def_id: LocalDefId) -> &'tcx [ModChild] {
22872287
self.resolutions(()).module_children.get(&def_id).map_or(&[], |v| &v[..])
22882288
}
2289+
2290+
pub fn ambiguity_module_children_local(self, def_id: LocalDefId) -> &'tcx [AmbiguityModChild] {
2291+
self.resolutions(()).ambiguity_module_children.get(&def_id).map_or(&[], |v| &v[..])
2292+
}
22892293
}
22902294

22912295
/// Parameter attributes that can only be determined by examining the body of a function instead

compiler/rustc_middle/src/ty/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub use self::BorrowKind::*;
1818
pub use self::IntVarValue::*;
1919
pub use self::Variance::*;
2020
use crate::error::{OpaqueHiddenTypeMismatch, TypeMismatchReason};
21-
use crate::metadata::ModChild;
21+
use crate::metadata::{AmbiguityModChild, ModChild};
2222
use crate::middle::privacy::EffectiveVisibilities;
2323
use crate::mir::{Body, CoroutineLayout};
2424
use crate::query::Providers;
@@ -160,6 +160,7 @@ pub struct ResolverGlobalCtxt {
160160
pub extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
161161
pub maybe_unused_trait_imports: FxIndexSet<LocalDefId>,
162162
pub module_children: LocalDefIdMap<Vec<ModChild>>,
163+
pub ambiguity_module_children: LocalDefIdMap<Vec<AmbiguityModChild>>,
163164
pub glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
164165
pub main_def: Option<MainDefinition>,
165166
pub trait_impls: FxIndexMap<DefId, Vec<LocalDefId>>,

0 commit comments

Comments
 (0)