Skip to content

Commit 49775fb

Browse files
Rollup merge of rust-lang#149195 - petrochenkov:globamberr, r=mu001999
resolve: Partially convert `ambiguous_glob_imports` lint into a hard error I'm tired of this logic interfering with any attempts to fix or refactor glob imports. Change description for lang team: rust-lang#149195 (comment). Part of rust-lang#114095.
2 parents 6368fd5 + 15b1398 commit 49775fb

40 files changed

Lines changed: 225 additions & 815 deletions

compiler/rustc_codegen_gcc/build_system/src/test.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,6 @@ fn valid_ui_error_pattern_test(file: &str) -> bool {
886886
"type-alias-impl-trait/auxiliary/cross_crate_ice.rs",
887887
"type-alias-impl-trait/auxiliary/cross_crate_ice2.rs",
888888
"macros/rfc-2011-nicer-assert-messages/auxiliary/common.rs",
889-
"imports/ambiguous-1.rs",
890-
"imports/ambiguous-4-extern.rs",
891889
"entry-point/auxiliary/bad_main_functions.rs",
892890
]
893891
.iter()

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4529,28 +4529,21 @@ declare_lint! {
45294529
///
45304530
/// ### Example
45314531
///
4532-
/// ```rust,compile_fail
4533-
/// #![deny(ambiguous_glob_imports)]
4534-
/// pub fn foo() -> u32 {
4535-
/// use sub::*;
4536-
/// C
4537-
/// }
4538-
///
4539-
/// mod sub {
4540-
/// mod mod1 { pub const C: u32 = 1; }
4541-
/// mod mod2 { pub const C: u32 = 2; }
4532+
/// ```rust,ignore (needs extern crate)
4533+
/// // library crate `my_library`
4534+
/// mod mod1 { pub const C: u32 = 1; }
4535+
/// mod mod2 { pub const C: u32 = 2; }
4536+
/// pub use mod1::*;
4537+
/// pub use mod2::*;
45424538
///
4543-
/// pub use mod1::*;
4544-
/// pub use mod2::*;
4545-
/// }
4539+
/// // another crate using `my_library`
4540+
/// let c = my_library::C; // `C` is ambiguous
45464541
/// ```
45474542
///
4548-
/// {{produces}}
4549-
///
45504543
/// ### Explanation
45514544
///
4552-
/// Previous versions of Rust compile it successfully because it
4553-
/// had lost the ambiguity error when resolve `use sub::mod2::*`.
4545+
/// Previous versions of Rust compile it successfully because
4546+
/// ambiguous glob imports weren't preserved correctly over crate boundaries.
45544547
///
45554548
/// This is a [future-incompatible] lint to transition this to a
45564549
/// hard error in the future.

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
5252
decl: Decl<'ra>,
5353
) {
5454
if let Err(old_decl) =
55-
self.try_plant_decl_into_local_module(ident, orig_ident_span, ns, decl, false)
55+
self.try_plant_decl_into_local_module(ident, orig_ident_span, ns, decl)
5656
{
5757
self.report_conflict(ident, ns, old_decl, decl);
5858
}
@@ -87,13 +87,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
8787
vis: Visibility<DefId>,
8888
span: Span,
8989
expansion: LocalExpnId,
90-
ambiguity: Option<Decl<'ra>>,
90+
ambiguity: Option<(Decl<'ra>, bool)>,
9191
) {
9292
let decl = self.arenas.alloc_decl(DeclData {
9393
kind: DeclKind::Def(res),
9494
ambiguity: CmCell::new(ambiguity),
95-
// External ambiguities always report the `AMBIGUOUS_GLOB_IMPORTS` lint at the moment.
96-
warn_ambiguity: CmCell::new(true),
9795
initial_vis: vis,
9896
ambiguity_vis_max: CmCell::new(None),
9997
ambiguity_vis_min: CmCell::new(None),
@@ -392,7 +390,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
392390
let ModChild { ident: _, res, vis, ref reexport_chain } = *ambig_child;
393391
let span = child_span(self, reexport_chain, res);
394392
let res = res.expect_non_local();
395-
self.arenas.new_def_decl(res, vis, span, expansion, Some(parent.to_module()))
393+
// External ambiguities always report the `AMBIGUOUS_GLOB_IMPORTS` lint at the moment.
394+
(self.arenas.new_def_decl(res, vis, span, expansion, Some(parent.to_module())), true)
396395
});
397396

398397
// Record primary definitions.

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11881188
.emit()
11891189
}
11901190

1191-
fn def_path_str(&self, mut def_id: DefId) -> String {
1191+
pub(crate) fn def_path_str(&self, mut def_id: DefId) -> String {
11921192
// We can't use `def_path_str` in resolve.
11931193
let mut path = vec![def_id];
11941194
while let Some(parent) = self.tcx.opt_parent(def_id) {

0 commit comments

Comments
 (0)