From 12fb620cf362223e20e2b6cff6d5a831d742e60e Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 17 Feb 2026 20:01:21 +0300 Subject: [PATCH 1/2] resolve: Extend `ambiguous_import_visibilities` deprecation lint to glob-vs-glob ambiguities --- compiler/rustc_middle/src/middle/privacy.rs | 22 ++- .../rustc_resolve/src/build_reduced_graph.rs | 4 +- .../src/effective_visibilities.rs | 4 + compiler/rustc_resolve/src/ident.rs | 31 ++++ compiler/rustc_resolve/src/imports.rs | 31 ++-- compiler/rustc_resolve/src/lib.rs | 20 ++- .../ambiguous-import-visibility-globglob.rs | 49 +++++++ ...mbiguous-import-visibility-globglob.stderr | 135 ++++++++++++++++++ tests/ui/imports/overwrite-vis-unused.rs | 4 +- tests/ui/imports/overwrite-vis-unused.stderr | 15 -- 10 files changed, 276 insertions(+), 39 deletions(-) create mode 100644 tests/ui/imports/ambiguous-import-visibility-globglob.rs create mode 100644 tests/ui/imports/ambiguous-import-visibility-globglob.stderr delete mode 100644 tests/ui/imports/overwrite-vis-unused.stderr diff --git a/compiler/rustc_middle/src/middle/privacy.rs b/compiler/rustc_middle/src/middle/privacy.rs index 0be4c8243d632..eb8b1845afc67 100644 --- a/compiler/rustc_middle/src/middle/privacy.rs +++ b/compiler/rustc_middle/src/middle/privacy.rs @@ -7,6 +7,7 @@ use std::hash::Hash; use rustc_data_structures::fx::{FxIndexMap, IndexEntry}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_hir::def::DefKind; +use rustc_hir::{ItemKind, Node, UseKind}; use rustc_macros::HashStable; use rustc_span::def_id::{CRATE_DEF_ID, LocalDefId}; @@ -184,13 +185,20 @@ impl EffectiveVisibilities { if !is_impl && tcx.trait_impl_of_assoc(def_id.to_def_id()).is_none() { let nominal_vis = tcx.visibility(def_id); if !nominal_vis.is_at_least(ev.reachable, tcx) { - span_bug!( - span, - "{:?}: reachable {:?} > nominal {:?}", - def_id, - ev.reachable, - nominal_vis, - ); + if let Node::Item(item) = tcx.hir_node_by_def_id(def_id) + && let ItemKind::Use(_, UseKind::Glob) = item.kind + { + // Glob import visibilities can be increasee by other + // more public glob imports in cases of ambiguity. + } else { + span_bug!( + span, + "{:?}: reachable {:?} > nominal {:?}", + def_id, + ev.reachable, + nominal_vis, + ); + } } } } diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index d9d42cfefcd81..c26bfde94db9a 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -95,7 +95,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { ambiguity: CmCell::new(ambiguity), // External ambiguities always report the `AMBIGUOUS_GLOB_IMPORTS` lint at the moment. warn_ambiguity: CmCell::new(true), - vis: CmCell::new(vis), + initial_vis: vis, + ambiguity_vis_max: CmCell::new(None), + ambiguity_vis_min: CmCell::new(None), span, expansion, parent_module: Some(parent), diff --git a/compiler/rustc_resolve/src/effective_visibilities.rs b/compiler/rustc_resolve/src/effective_visibilities.rs index 55518276a4f0f..d0efbf62cc9a8 100644 --- a/compiler/rustc_resolve/src/effective_visibilities.rs +++ b/compiler/rustc_resolve/src/effective_visibilities.rs @@ -182,6 +182,10 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> { parent_id.level(), tcx, ); + if let Some(max_vis_decl) = decl.ambiguity_vis_max.get() { + // Avoid the most visible import in an ambiguous glob set being reported as unused. + self.update_import(max_vis_decl, parent_id); + } } fn update_def( diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 7cfd5b5f861a4..c4b89c1403657 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -5,6 +5,7 @@ use Namespace::*; use rustc_ast::{self as ast, NodeId}; use rustc_errors::ErrorGuaranteed; use rustc_hir::def::{DefKind, MacroKinds, Namespace, NonMacroAttrKind, PartialRes, PerNS}; +use rustc_hir::def_id::DefId; use rustc_middle::ty::Visibility; use rustc_middle::{bug, span_bug}; use rustc_session::lint::builtin::PROC_MACRO_DERIVE_RESOLUTION_FALLBACK; @@ -492,6 +493,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } Some(Finalize { import_vis, .. }) => import_vis, }; + this.get_mut().maybe_push_glob_vs_glob_vis_ambiguity( + ident, + orig_ident_span, + decl, + import_vis, + ); if let Some(&(innermost_decl, _)) = innermost_results.first() { // Found another solution, if the first one was "weak", report an error. @@ -774,6 +781,30 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { ret.map_err(ControlFlow::Continue) } + fn maybe_push_glob_vs_glob_vis_ambiguity( + &mut self, + ident: IdentKey, + orig_ident_span: Span, + decl: Decl<'ra>, + import_vis: Option, + ) { + let Some(import_vis) = import_vis else { return }; + let min = |vis: Visibility| vis.min(import_vis.to_def_id(), self.tcx).expect_local(); + let (min1, min2) = (min(decl.vis()), min(decl.min_vis())); + if min1 != min2 { + self.ambiguity_errors.push(AmbiguityError { + kind: AmbiguityKind::GlobVsGlob, + ambig_vis: Some((min1, min2)), + ident: ident.orig(orig_ident_span), + b1: decl.ambiguity_vis_max.get().unwrap_or(decl), + b2: decl.ambiguity_vis_min.get().unwrap_or(decl), + scope1: Scope::ModuleGlobs(decl.parent_module.unwrap(), None), + scope2: Scope::ModuleGlobs(decl.parent_module.unwrap(), None), + warning: Some(AmbiguityWarning::GlobImport), + }); + } + } + fn maybe_push_ambiguity( &mut self, ident: IdentKey, diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 7696b4b220d6c..fa0cc9d9300e5 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -346,7 +346,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { ambiguity: CmCell::new(None), warn_ambiguity: CmCell::new(false), span: import.span, - vis: CmCell::new(vis), + initial_vis: vis, + ambiguity_vis_max: CmCell::new(None), + ambiguity_vis_min: CmCell::new(None), expansion: import.parent_scope.expansion, parent_module: Some(import.parent_scope.module), }) @@ -371,8 +373,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { // - A glob decl is overwritten by its clone after setting ambiguity in it. // FIXME: avoid this by removing `warn_ambiguity`, or by triggering glob re-fetch // with the same decl in some way. - // - A glob decl is overwritten by a glob decl with larger visibility. - // FIXME: avoid this by updating this visibility in place. // - A glob decl is overwritten by a glob decl re-fetching an // overwritten decl from other module (the recursive case). // Here we are detecting all such re-fetches and overwrite old decls @@ -386,8 +386,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { // FIXME: reenable the asserts when `warn_ambiguity` is removed (#149195). // assert_ne!(old_deep_decl, deep_decl); // assert!(old_deep_decl.is_glob_import()); - // FIXME: reenable the assert when visibility is updated in place. - // assert!(!deep_decl.is_glob_import()); + assert!(!deep_decl.is_glob_import()); if old_glob_decl.ambiguity.get().is_some() && glob_decl.ambiguity.get().is_none() { // Do not lose glob ambiguities when re-fetching the glob. glob_decl.ambiguity.set_unchecked(old_glob_decl.ambiguity.get()); @@ -407,11 +406,20 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { // FIXME: remove this when `warn_ambiguity` is removed (#149195). self.arenas.alloc_decl((*old_glob_decl).clone()) } - } else if !old_glob_decl.vis().is_at_least(glob_decl.vis(), self.tcx) { - // We are glob-importing the same item but with greater visibility. - // FIXME: Update visibility in place, but without regressions - // (#152004, #151124, #152347). - glob_decl + } else if let old_vis = old_glob_decl.vis() + && let vis = glob_decl.vis() + && old_vis != vis + { + // We are glob-importing the same item but with a different visibility. + if vis.is_at_least(old_vis, self.tcx) { + old_glob_decl.ambiguity_vis_max.set_unchecked(Some(glob_decl)); + } else if let old_min_vis = old_glob_decl.min_vis() + && old_min_vis != vis + && old_min_vis.is_at_least(vis, self.tcx) + { + old_glob_decl.ambiguity_vis_min.set_unchecked(Some(glob_decl)); + } + old_glob_decl } else if glob_decl.is_ambiguity_recursive() && !old_glob_decl.is_ambiguity_recursive() { // Overwriting a non-ambiguous glob import with an ambiguous glob import. old_glob_decl.ambiguity.set_unchecked(Some(glob_decl)); @@ -510,11 +518,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { .resolution_or_default(module, key, orig_ident_span) .borrow_mut_unchecked(); let old_decl = resolution.binding(); + let old_vis = old_decl.map(|d| d.vis()); let t = f(self, resolution); if let Some(binding) = resolution.binding() - && old_decl != Some(binding) + && (old_decl != Some(binding) || old_vis != Some(binding.vis())) { (binding, t, warn_ambiguity || old_decl.is_some()) } else { diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 27d41825331b7..109a3d2778b96 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -850,7 +850,13 @@ struct DeclData<'ra> { warn_ambiguity: CmCell, expansion: LocalExpnId, span: Span, - vis: CmCell>, + initial_vis: Visibility, + /// If the declaration refers to an ambiguous glob set, then this is the most visible binding + /// from the set, if its visibility is different from `initial_vis`. + ambiguity_vis_max: CmCell>>, + /// If the declaration refers to an ambiguous glob set, then this is the least visible binding + /// from the set, if its visibility is different from `initial_vis`. + ambiguity_vis_min: CmCell>>, parent_module: Option>, } @@ -970,7 +976,13 @@ struct AmbiguityError<'ra> { impl<'ra> DeclData<'ra> { fn vis(&self) -> Visibility { - self.vis.get() + // Select the maximum visibility if there are multiple ambiguous glob imports. + self.ambiguity_vis_max.get().map(|d| d.vis()).unwrap_or_else(|| self.initial_vis) + } + + fn min_vis(&self) -> Visibility { + // Select the minimum visibility if there are multiple ambiguous glob imports. + self.ambiguity_vis_min.get().map(|d| d.vis()).unwrap_or_else(|| self.initial_vis) } fn res(&self) -> Res { @@ -1415,7 +1427,9 @@ impl<'ra> ResolverArenas<'ra> { kind: DeclKind::Def(res), ambiguity: CmCell::new(None), warn_ambiguity: CmCell::new(false), - vis: CmCell::new(vis), + initial_vis: vis, + ambiguity_vis_max: CmCell::new(None), + ambiguity_vis_min: CmCell::new(None), span, expansion, parent_module, diff --git a/tests/ui/imports/ambiguous-import-visibility-globglob.rs b/tests/ui/imports/ambiguous-import-visibility-globglob.rs new file mode 100644 index 0000000000000..5c8b6f4766835 --- /dev/null +++ b/tests/ui/imports/ambiguous-import-visibility-globglob.rs @@ -0,0 +1,49 @@ +//@ check-pass + +mod m { + pub struct S {} +} + +mod min_vis_first { + use crate::m::*; + pub(crate) use crate::m::*; + pub use crate::m::*; + + pub use self::S as S1; + //~^ WARN ambiguous import visibility + //~| WARN this was previously accepted + pub(crate) use self::S as S2; + //~^ WARN ambiguous import visibility + //~| WARN this was previously accepted + use self::S as S3; // OK +} + +mod mid_vis_first { + pub(crate) use crate::m::*; + use crate::m::*; + pub use crate::m::*; + + pub use self::S as S1; + //~^ WARN ambiguous import visibility + //~| WARN this was previously accepted + pub(crate) use self::S as S2; + //~^ WARN ambiguous import visibility + //~| WARN this was previously accepted + use self::S as S3; // OK +} + +mod max_vis_first { + pub use crate::m::*; + use crate::m::*; + pub(crate) use crate::m::*; + + pub use self::S as S1; + //~^ WARN ambiguous import visibility + //~| WARN this was previously accepted + pub(crate) use self::S as S2; + //~^ WARN ambiguous import visibility + //~| WARN this was previously accepted + use self::S as S3; // OK +} + +fn main() {} diff --git a/tests/ui/imports/ambiguous-import-visibility-globglob.stderr b/tests/ui/imports/ambiguous-import-visibility-globglob.stderr new file mode 100644 index 0000000000000..d15282cc436cd --- /dev/null +++ b/tests/ui/imports/ambiguous-import-visibility-globglob.stderr @@ -0,0 +1,135 @@ +warning: ambiguous import visibility: pub or pub(in crate::min_vis_first) + --> $DIR/ambiguous-import-visibility-globglob.rs:12:19 + | +LL | pub use self::S as S1; + | ^ + | + = note: ambiguous because of multiple glob imports of a name in the same module +note: `S` could refer to the struct imported here + --> $DIR/ambiguous-import-visibility-globglob.rs:10:13 + | +LL | pub use crate::m::*; + | ^^^^^^^^^^^ + = help: consider adding an explicit import of `S` to disambiguate +note: `S` could also refer to the struct imported here + --> $DIR/ambiguous-import-visibility-globglob.rs:8:9 + | +LL | use crate::m::*; + | ^^^^^^^^^^^ + = help: consider adding an explicit import of `S` to disambiguate + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #149145 + = note: `#[warn(ambiguous_import_visibilities)]` (part of `#[warn(future_incompatible)]`) on by default + +warning: ambiguous import visibility: pub(crate) or pub(in crate::min_vis_first) + --> $DIR/ambiguous-import-visibility-globglob.rs:15:26 + | +LL | pub(crate) use self::S as S2; + | ^ + | + = note: ambiguous because of multiple glob imports of a name in the same module +note: `S` could refer to the struct imported here + --> $DIR/ambiguous-import-visibility-globglob.rs:10:13 + | +LL | pub use crate::m::*; + | ^^^^^^^^^^^ + = help: consider adding an explicit import of `S` to disambiguate +note: `S` could also refer to the struct imported here + --> $DIR/ambiguous-import-visibility-globglob.rs:8:9 + | +LL | use crate::m::*; + | ^^^^^^^^^^^ + = help: consider adding an explicit import of `S` to disambiguate + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #149145 + +warning: ambiguous import visibility: pub or pub(in crate::mid_vis_first) + --> $DIR/ambiguous-import-visibility-globglob.rs:26:19 + | +LL | pub use self::S as S1; + | ^ + | + = note: ambiguous because of multiple glob imports of a name in the same module +note: `S` could refer to the struct imported here + --> $DIR/ambiguous-import-visibility-globglob.rs:24:13 + | +LL | pub use crate::m::*; + | ^^^^^^^^^^^ + = help: consider adding an explicit import of `S` to disambiguate +note: `S` could also refer to the struct imported here + --> $DIR/ambiguous-import-visibility-globglob.rs:23:9 + | +LL | use crate::m::*; + | ^^^^^^^^^^^ + = help: consider adding an explicit import of `S` to disambiguate + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #149145 + +warning: ambiguous import visibility: pub(crate) or pub(in crate::mid_vis_first) + --> $DIR/ambiguous-import-visibility-globglob.rs:29:26 + | +LL | pub(crate) use self::S as S2; + | ^ + | + = note: ambiguous because of multiple glob imports of a name in the same module +note: `S` could refer to the struct imported here + --> $DIR/ambiguous-import-visibility-globglob.rs:24:13 + | +LL | pub use crate::m::*; + | ^^^^^^^^^^^ + = help: consider adding an explicit import of `S` to disambiguate +note: `S` could also refer to the struct imported here + --> $DIR/ambiguous-import-visibility-globglob.rs:23:9 + | +LL | use crate::m::*; + | ^^^^^^^^^^^ + = help: consider adding an explicit import of `S` to disambiguate + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #149145 + +warning: ambiguous import visibility: pub or pub(in crate::max_vis_first) + --> $DIR/ambiguous-import-visibility-globglob.rs:40:19 + | +LL | pub use self::S as S1; + | ^ + | + = note: ambiguous because of multiple glob imports of a name in the same module +note: `S` could refer to the struct imported here + --> $DIR/ambiguous-import-visibility-globglob.rs:36:13 + | +LL | pub use crate::m::*; + | ^^^^^^^^^^^ + = help: consider adding an explicit import of `S` to disambiguate +note: `S` could also refer to the struct imported here + --> $DIR/ambiguous-import-visibility-globglob.rs:37:9 + | +LL | use crate::m::*; + | ^^^^^^^^^^^ + = help: consider adding an explicit import of `S` to disambiguate + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #149145 + +warning: ambiguous import visibility: pub(crate) or pub(in crate::max_vis_first) + --> $DIR/ambiguous-import-visibility-globglob.rs:43:26 + | +LL | pub(crate) use self::S as S2; + | ^ + | + = note: ambiguous because of multiple glob imports of a name in the same module +note: `S` could refer to the struct imported here + --> $DIR/ambiguous-import-visibility-globglob.rs:36:13 + | +LL | pub use crate::m::*; + | ^^^^^^^^^^^ + = help: consider adding an explicit import of `S` to disambiguate +note: `S` could also refer to the struct imported here + --> $DIR/ambiguous-import-visibility-globglob.rs:37:9 + | +LL | use crate::m::*; + | ^^^^^^^^^^^ + = help: consider adding an explicit import of `S` to disambiguate + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #149145 + +warning: 6 warnings emitted + diff --git a/tests/ui/imports/overwrite-vis-unused.rs b/tests/ui/imports/overwrite-vis-unused.rs index 0217fb6250837..6361c71f6639e 100644 --- a/tests/ui/imports/overwrite-vis-unused.rs +++ b/tests/ui/imports/overwrite-vis-unused.rs @@ -1,12 +1,12 @@ // Regression test for issues #152004 and #151124. - +//@ check-pass #![deny(unused)] mod m { pub struct S {} } -use m::*; //~ ERROR unused import: `m::*` +use m::*; pub use m::*; fn main() {} diff --git a/tests/ui/imports/overwrite-vis-unused.stderr b/tests/ui/imports/overwrite-vis-unused.stderr deleted file mode 100644 index a38aa4d5f070a..0000000000000 --- a/tests/ui/imports/overwrite-vis-unused.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error: unused import: `m::*` - --> $DIR/overwrite-vis-unused.rs:9:5 - | -LL | use m::*; - | ^^^^ - | -note: the lint level is defined here - --> $DIR/overwrite-vis-unused.rs:3:9 - | -LL | #![deny(unused)] - | ^^^^^^ - = note: `#[deny(unused_imports)]` implied by `#[deny(unused)]` - -error: aborting due to 1 previous error - From 8c30e81d6ba2122044b19b3282ad30400dc34b83 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 20 Mar 2026 20:40:37 +0300 Subject: [PATCH 2/2] [WIP] Tweaks for crater --- compiler/rustc_lint_defs/src/builtin.rs | 2 +- compiler/rustc_resolve/src/ident.rs | 22 ++++---- .../ambiguous-import-visibility-globglob.rs | 14 +++-- ...mbiguous-import-visibility-globglob.stderr | 52 +++++++++---------- .../ambiguous-import-visibility-macro.rs | 4 +- .../ambiguous-import-visibility-macro.stderr | 29 ----------- .../ambiguous-import-visibility-module.rs | 3 +- .../ambiguous-import-visibility-module.stderr | 29 ----------- .../ui/imports/ambiguous-import-visibility.rs | 4 +- .../ambiguous-import-visibility.stderr | 25 --------- 10 files changed, 50 insertions(+), 134 deletions(-) delete mode 100644 tests/ui/imports/ambiguous-import-visibility-macro.stderr delete mode 100644 tests/ui/imports/ambiguous-import-visibility-module.stderr delete mode 100644 tests/ui/imports/ambiguous-import-visibility.stderr diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 22843f664b59c..999cc419e2bc9 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -4745,7 +4745,7 @@ declare_lint! { /// /// [future-incompatible]: ../index.md#future-incompatible-lints pub AMBIGUOUS_IMPORT_VISIBILITIES, - Warn, + Deny, "detects certain glob imports that require reporting an ambiguity error", @future_incompatible = FutureIncompatibleInfo { reason: fcw!(FutureReleaseError #149145), diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index c4b89c1403657..8687cfad168b9 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -925,16 +925,18 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { None }; - self.ambiguity_errors.push(AmbiguityError { - kind, - ambig_vis, - ident: ident.orig(orig_ident_span), - b1: innermost_decl, - b2: decl, - scope1: innermost_scope, - scope2: scope, - warning, - }); + if ambig_vis.is_none() { + self.ambiguity_errors.push(AmbiguityError { + kind, + ambig_vis, + ident: ident.orig(orig_ident_span), + b1: innermost_decl, + b2: decl, + scope1: innermost_scope, + scope2: scope, + warning, + }); + } return true; } } diff --git a/tests/ui/imports/ambiguous-import-visibility-globglob.rs b/tests/ui/imports/ambiguous-import-visibility-globglob.rs index 5c8b6f4766835..d976dc48396e0 100644 --- a/tests/ui/imports/ambiguous-import-visibility-globglob.rs +++ b/tests/ui/imports/ambiguous-import-visibility-globglob.rs @@ -1,5 +1,3 @@ -//@ check-pass - mod m { pub struct S {} } @@ -10,10 +8,10 @@ mod min_vis_first { pub use crate::m::*; pub use self::S as S1; - //~^ WARN ambiguous import visibility + //~^ ERROR ambiguous import visibility //~| WARN this was previously accepted pub(crate) use self::S as S2; - //~^ WARN ambiguous import visibility + //~^ ERROR ambiguous import visibility //~| WARN this was previously accepted use self::S as S3; // OK } @@ -24,10 +22,10 @@ mod mid_vis_first { pub use crate::m::*; pub use self::S as S1; - //~^ WARN ambiguous import visibility + //~^ ERROR ambiguous import visibility //~| WARN this was previously accepted pub(crate) use self::S as S2; - //~^ WARN ambiguous import visibility + //~^ ERROR ambiguous import visibility //~| WARN this was previously accepted use self::S as S3; // OK } @@ -38,10 +36,10 @@ mod max_vis_first { pub(crate) use crate::m::*; pub use self::S as S1; - //~^ WARN ambiguous import visibility + //~^ ERROR ambiguous import visibility //~| WARN this was previously accepted pub(crate) use self::S as S2; - //~^ WARN ambiguous import visibility + //~^ ERROR ambiguous import visibility //~| WARN this was previously accepted use self::S as S3; // OK } diff --git a/tests/ui/imports/ambiguous-import-visibility-globglob.stderr b/tests/ui/imports/ambiguous-import-visibility-globglob.stderr index d15282cc436cd..6874d5e4c54bb 100644 --- a/tests/ui/imports/ambiguous-import-visibility-globglob.stderr +++ b/tests/ui/imports/ambiguous-import-visibility-globglob.stderr @@ -1,41 +1,41 @@ -warning: ambiguous import visibility: pub or pub(in crate::min_vis_first) - --> $DIR/ambiguous-import-visibility-globglob.rs:12:19 +error: ambiguous import visibility: pub or pub(in crate::min_vis_first) + --> $DIR/ambiguous-import-visibility-globglob.rs:10:19 | LL | pub use self::S as S1; | ^ | = note: ambiguous because of multiple glob imports of a name in the same module note: `S` could refer to the struct imported here - --> $DIR/ambiguous-import-visibility-globglob.rs:10:13 + --> $DIR/ambiguous-import-visibility-globglob.rs:8:13 | LL | pub use crate::m::*; | ^^^^^^^^^^^ = help: consider adding an explicit import of `S` to disambiguate note: `S` could also refer to the struct imported here - --> $DIR/ambiguous-import-visibility-globglob.rs:8:9 + --> $DIR/ambiguous-import-visibility-globglob.rs:6:9 | LL | use crate::m::*; | ^^^^^^^^^^^ = help: consider adding an explicit import of `S` to disambiguate = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #149145 - = note: `#[warn(ambiguous_import_visibilities)]` (part of `#[warn(future_incompatible)]`) on by default + = note: `#[deny(ambiguous_import_visibilities)]` (part of `#[deny(future_incompatible)]`) on by default -warning: ambiguous import visibility: pub(crate) or pub(in crate::min_vis_first) - --> $DIR/ambiguous-import-visibility-globglob.rs:15:26 +error: ambiguous import visibility: pub(crate) or pub(in crate::min_vis_first) + --> $DIR/ambiguous-import-visibility-globglob.rs:13:26 | LL | pub(crate) use self::S as S2; | ^ | = note: ambiguous because of multiple glob imports of a name in the same module note: `S` could refer to the struct imported here - --> $DIR/ambiguous-import-visibility-globglob.rs:10:13 + --> $DIR/ambiguous-import-visibility-globglob.rs:8:13 | LL | pub use crate::m::*; | ^^^^^^^^^^^ = help: consider adding an explicit import of `S` to disambiguate note: `S` could also refer to the struct imported here - --> $DIR/ambiguous-import-visibility-globglob.rs:8:9 + --> $DIR/ambiguous-import-visibility-globglob.rs:6:9 | LL | use crate::m::*; | ^^^^^^^^^^^ @@ -43,21 +43,21 @@ LL | use crate::m::*; = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #149145 -warning: ambiguous import visibility: pub or pub(in crate::mid_vis_first) - --> $DIR/ambiguous-import-visibility-globglob.rs:26:19 +error: ambiguous import visibility: pub or pub(in crate::mid_vis_first) + --> $DIR/ambiguous-import-visibility-globglob.rs:24:19 | LL | pub use self::S as S1; | ^ | = note: ambiguous because of multiple glob imports of a name in the same module note: `S` could refer to the struct imported here - --> $DIR/ambiguous-import-visibility-globglob.rs:24:13 + --> $DIR/ambiguous-import-visibility-globglob.rs:22:13 | LL | pub use crate::m::*; | ^^^^^^^^^^^ = help: consider adding an explicit import of `S` to disambiguate note: `S` could also refer to the struct imported here - --> $DIR/ambiguous-import-visibility-globglob.rs:23:9 + --> $DIR/ambiguous-import-visibility-globglob.rs:21:9 | LL | use crate::m::*; | ^^^^^^^^^^^ @@ -65,21 +65,21 @@ LL | use crate::m::*; = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #149145 -warning: ambiguous import visibility: pub(crate) or pub(in crate::mid_vis_first) - --> $DIR/ambiguous-import-visibility-globglob.rs:29:26 +error: ambiguous import visibility: pub(crate) or pub(in crate::mid_vis_first) + --> $DIR/ambiguous-import-visibility-globglob.rs:27:26 | LL | pub(crate) use self::S as S2; | ^ | = note: ambiguous because of multiple glob imports of a name in the same module note: `S` could refer to the struct imported here - --> $DIR/ambiguous-import-visibility-globglob.rs:24:13 + --> $DIR/ambiguous-import-visibility-globglob.rs:22:13 | LL | pub use crate::m::*; | ^^^^^^^^^^^ = help: consider adding an explicit import of `S` to disambiguate note: `S` could also refer to the struct imported here - --> $DIR/ambiguous-import-visibility-globglob.rs:23:9 + --> $DIR/ambiguous-import-visibility-globglob.rs:21:9 | LL | use crate::m::*; | ^^^^^^^^^^^ @@ -87,21 +87,21 @@ LL | use crate::m::*; = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #149145 -warning: ambiguous import visibility: pub or pub(in crate::max_vis_first) - --> $DIR/ambiguous-import-visibility-globglob.rs:40:19 +error: ambiguous import visibility: pub or pub(in crate::max_vis_first) + --> $DIR/ambiguous-import-visibility-globglob.rs:38:19 | LL | pub use self::S as S1; | ^ | = note: ambiguous because of multiple glob imports of a name in the same module note: `S` could refer to the struct imported here - --> $DIR/ambiguous-import-visibility-globglob.rs:36:13 + --> $DIR/ambiguous-import-visibility-globglob.rs:34:13 | LL | pub use crate::m::*; | ^^^^^^^^^^^ = help: consider adding an explicit import of `S` to disambiguate note: `S` could also refer to the struct imported here - --> $DIR/ambiguous-import-visibility-globglob.rs:37:9 + --> $DIR/ambiguous-import-visibility-globglob.rs:35:9 | LL | use crate::m::*; | ^^^^^^^^^^^ @@ -109,21 +109,21 @@ LL | use crate::m::*; = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #149145 -warning: ambiguous import visibility: pub(crate) or pub(in crate::max_vis_first) - --> $DIR/ambiguous-import-visibility-globglob.rs:43:26 +error: ambiguous import visibility: pub(crate) or pub(in crate::max_vis_first) + --> $DIR/ambiguous-import-visibility-globglob.rs:41:26 | LL | pub(crate) use self::S as S2; | ^ | = note: ambiguous because of multiple glob imports of a name in the same module note: `S` could refer to the struct imported here - --> $DIR/ambiguous-import-visibility-globglob.rs:36:13 + --> $DIR/ambiguous-import-visibility-globglob.rs:34:13 | LL | pub use crate::m::*; | ^^^^^^^^^^^ = help: consider adding an explicit import of `S` to disambiguate note: `S` could also refer to the struct imported here - --> $DIR/ambiguous-import-visibility-globglob.rs:37:9 + --> $DIR/ambiguous-import-visibility-globglob.rs:35:9 | LL | use crate::m::*; | ^^^^^^^^^^^ @@ -131,5 +131,5 @@ LL | use crate::m::*; = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #149145 -warning: 6 warnings emitted +error: aborting due to 6 previous errors diff --git a/tests/ui/imports/ambiguous-import-visibility-macro.rs b/tests/ui/imports/ambiguous-import-visibility-macro.rs index e1861cc5d4e0a..6a95dca2f63dc 100644 --- a/tests/ui/imports/ambiguous-import-visibility-macro.rs +++ b/tests/ui/imports/ambiguous-import-visibility-macro.rs @@ -14,6 +14,6 @@ globbing! {} // this imports the same `RustEmbed` macro with `pub` visibility pub trait RustEmbed {} -pub use RustEmbed as Embed; //~ WARN ambiguous import visibility - //~| WARN this was previously accepted +pub use RustEmbed as Embed; + fn main() {} diff --git a/tests/ui/imports/ambiguous-import-visibility-macro.stderr b/tests/ui/imports/ambiguous-import-visibility-macro.stderr deleted file mode 100644 index 6f5f1c4dd3ec6..0000000000000 --- a/tests/ui/imports/ambiguous-import-visibility-macro.stderr +++ /dev/null @@ -1,29 +0,0 @@ -warning: ambiguous import visibility: pub(crate) or pub - --> $DIR/ambiguous-import-visibility-macro.rs:17:9 - | -LL | pub use RustEmbed as Embed; - | ^^^^^^^^^ - | - = note: ambiguous because of a conflict between a name from a glob import and an outer scope during import or macro resolution -note: `RustEmbed` could refer to the derive macro imported here - --> $DIR/ambiguous-import-visibility-macro.rs:7:17 - | -LL | pub use same_res_ambigious_extern_macro::*; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | globbing! {} // this imports the same `RustEmbed` macro with `pub` visibility - | ------------ in this macro invocation - = help: consider adding an explicit import of `RustEmbed` to disambiguate - = help: or use `crate::RustEmbed` to refer to this derive macro unambiguously -note: `RustEmbed` could also refer to the derive macro imported here - --> $DIR/ambiguous-import-visibility-macro.rs:11:1 - | -LL | #[macro_use] // this imports the `RustEmbed` macro with `pub(crate)` visibility - | ^^^^^^^^^^^^ - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #149145 - = note: `#[warn(ambiguous_import_visibilities)]` (part of `#[warn(future_incompatible)]`) on by default - = note: this warning originates in the macro `globbing` (in Nightly builds, run with -Z macro-backtrace for more info) - -warning: 1 warning emitted - diff --git a/tests/ui/imports/ambiguous-import-visibility-module.rs b/tests/ui/imports/ambiguous-import-visibility-module.rs index 35c6da8b21a4f..98634a407c5b2 100644 --- a/tests/ui/imports/ambiguous-import-visibility-module.rs +++ b/tests/ui/imports/ambiguous-import-visibility-module.rs @@ -15,8 +15,7 @@ mod reexport { pub use m::*; mac!(); - pub use S as Z; //~ WARN ambiguous import visibility - //~| WARN this was previously accepted + pub use S as Z; } fn main() { diff --git a/tests/ui/imports/ambiguous-import-visibility-module.stderr b/tests/ui/imports/ambiguous-import-visibility-module.stderr deleted file mode 100644 index 1532bcfe7f4e6..0000000000000 --- a/tests/ui/imports/ambiguous-import-visibility-module.stderr +++ /dev/null @@ -1,29 +0,0 @@ -warning: ambiguous import visibility: pub or pub(in crate::reexport) - --> $DIR/ambiguous-import-visibility-module.rs:18:13 - | -LL | pub use S as Z; - | ^ - | - = note: ambiguous because of a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution -note: `S` could refer to the struct imported here - --> $DIR/ambiguous-import-visibility-module.rs:11:17 - | -LL | use m::S; - | ^^^^ -... -LL | mac!(); - | ------ in this macro invocation - = help: use `self::S` to refer to this struct unambiguously -note: `S` could also refer to the struct imported here - --> $DIR/ambiguous-import-visibility-module.rs:15:13 - | -LL | pub use m::*; - | ^^^^ - = help: use `self::S` to refer to this struct unambiguously - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #149145 - = note: `#[warn(ambiguous_import_visibilities)]` (part of `#[warn(future_incompatible)]`) on by default - = note: this warning originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) - -warning: 1 warning emitted - diff --git a/tests/ui/imports/ambiguous-import-visibility.rs b/tests/ui/imports/ambiguous-import-visibility.rs index 4cb8b763fbc9d..77971fc606627 100644 --- a/tests/ui/imports/ambiguous-import-visibility.rs +++ b/tests/ui/imports/ambiguous-import-visibility.rs @@ -9,6 +9,6 @@ pub use same_res_ambigious_extern_macro::*; pub trait RustEmbed {} -pub use RustEmbed as Embed; //~ WARN ambiguous import visibility - //~| WARN this was previously accepted +pub use RustEmbed as Embed; + fn main() {} diff --git a/tests/ui/imports/ambiguous-import-visibility.stderr b/tests/ui/imports/ambiguous-import-visibility.stderr deleted file mode 100644 index c846a5dadd1eb..0000000000000 --- a/tests/ui/imports/ambiguous-import-visibility.stderr +++ /dev/null @@ -1,25 +0,0 @@ -warning: ambiguous import visibility: pub(crate) or pub - --> $DIR/ambiguous-import-visibility.rs:12:9 - | -LL | pub use RustEmbed as Embed; - | ^^^^^^^^^ - | - = note: ambiguous because of a conflict between a name from a glob import and an outer scope during import or macro resolution -note: `RustEmbed` could refer to the derive macro imported here - --> $DIR/ambiguous-import-visibility.rs:8:9 - | -LL | pub use same_res_ambigious_extern_macro::*; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = help: consider adding an explicit import of `RustEmbed` to disambiguate - = help: or use `crate::RustEmbed` to refer to this derive macro unambiguously -note: `RustEmbed` could also refer to the derive macro imported here - --> $DIR/ambiguous-import-visibility.rs:5:1 - | -LL | #[macro_use] // this imports the `RustEmbed` macro with `pub(crate)` visibility - | ^^^^^^^^^^^^ - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #149145 - = note: `#[warn(ambiguous_import_visibilities)]` (part of `#[warn(future_incompatible)]`) on by default - -warning: 1 warning emitted -