Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions compiler/rustc_codegen_gcc/build_system/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,6 @@ fn valid_ui_error_pattern_test(file: &str) -> bool {
"type-alias-impl-trait/auxiliary/cross_crate_ice.rs",
"type-alias-impl-trait/auxiliary/cross_crate_ice2.rs",
"macros/rfc-2011-nicer-assert-messages/auxiliary/common.rs",
"imports/ambiguous-1.rs",
"imports/ambiguous-4-extern.rs",
"entry-point/auxiliary/bad_main_functions.rs",
]
.iter()
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4577,7 +4577,7 @@ declare_lint! {
///
/// ### Example
///
/// ```rust,compile_fail
/// ```rust,ignore (needs extern crate)
/// #![deny(ambiguous_glob_imports)]
/// pub fn foo() -> u32 {
/// use sub::*;
Expand All @@ -4593,8 +4593,6 @@ declare_lint! {
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Previous versions of Rust compile it successfully because it
Expand Down
9 changes: 4 additions & 5 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
decl: Decl<'ra>,
) {
if let Err(old_decl) =
self.try_plant_decl_into_local_module(ident, orig_ident_span, ns, decl, false)
self.try_plant_decl_into_local_module(ident, orig_ident_span, ns, decl)
{
self.report_conflict(ident, ns, old_decl, decl);
}
Expand Down Expand Up @@ -88,13 +88,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
vis: Visibility<DefId>,
span: Span,
expansion: LocalExpnId,
ambiguity: Option<Decl<'ra>>,
ambiguity: Option<(Decl<'ra>, bool)>,
) {
let decl = self.arenas.alloc_decl(DeclData {
kind: DeclKind::Def(res),
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),
span,
expansion,
Expand Down Expand Up @@ -292,7 +290,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
let ModChild { ident: _, res, vis, ref reexport_chain } = *ambig_child;
let span = child_span(self, reexport_chain, res);
let res = res.expect_non_local();
self.arenas.new_def_decl(res, vis, span, expansion, Some(parent))
// External ambiguities always report the `AMBIGUOUS_GLOB_IMPORTS` lint at the moment.
(self.arenas.new_def_decl(res, vis, span, expansion, Some(parent)), true)
});

// Record primary definitions.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
.emit()
}

fn def_path_str(&self, mut def_id: DefId) -> String {
pub(crate) fn def_path_str(&self, mut def_id: DefId) -> String {
// We can't use `def_path_str` in resolve.
let mut path = vec![def_id];
while let Some(parent) = self.tcx.opt_parent(def_id) {
Expand Down
201 changes: 102 additions & 99 deletions compiler/rustc_resolve/src/imports.rs

Large diffs are not rendered by default.

37 changes: 5 additions & 32 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,10 +844,7 @@ impl<'ra> fmt::Debug for Module<'ra> {
#[derive(Clone, Debug)]
struct DeclData<'ra> {
kind: DeclKind<'ra>,
ambiguity: CmCell<Option<Decl<'ra>>>,
/// Produce a warning instead of an error when reporting ambiguities inside this binding.
/// May apply to indirect ambiguities under imports, so `ambiguity.is_some()` is not required.
warn_ambiguity: CmCell<bool>,
ambiguity: CmCell<Option<(Decl<'ra>, bool /*warning*/)>>,
expansion: LocalExpnId,
span: Span,
vis: CmCell<Visibility<DefId>>,
Expand Down Expand Up @@ -989,7 +986,7 @@ impl<'ra> DeclData<'ra> {

fn descent_to_ambiguity(self: Decl<'ra>) -> Option<(Decl<'ra>, Decl<'ra>)> {
match self.ambiguity.get() {
Some(ambig_binding) => Some((self, ambig_binding)),
Some((ambig_binding, _)) => Some((self, ambig_binding)),
None => match self.kind {
DeclKind::Import { source_decl, .. } => source_decl.descent_to_ambiguity(),
_ => None,
Expand All @@ -1005,14 +1002,6 @@ impl<'ra> DeclData<'ra> {
}
}

fn warn_ambiguity_recursive(&self) -> bool {
self.warn_ambiguity.get()
|| match self.kind {
DeclKind::Import { source_decl, .. } => source_decl.warn_ambiguity_recursive(),
_ => false,
}
}

fn is_possibly_imported_variant(&self) -> bool {
match self.kind {
DeclKind::Import { source_decl, .. } => source_decl.is_possibly_imported_variant(),
Expand Down Expand Up @@ -1405,7 +1394,6 @@ impl<'ra> ResolverArenas<'ra> {
self.alloc_decl(DeclData {
kind: DeclKind::Def(res),
ambiguity: CmCell::new(None),
warn_ambiguity: CmCell::new(false),
vis: CmCell::new(vis),
span,
expansion,
Expand Down Expand Up @@ -2093,17 +2081,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}

fn record_use(&mut self, ident: Ident, used_decl: Decl<'ra>, used: Used) {
self.record_use_inner(ident, used_decl, used, used_decl.warn_ambiguity.get());
}

fn record_use_inner(
&mut self,
ident: Ident,
used_decl: Decl<'ra>,
used: Used,
warn_ambiguity: bool,
) {
if let Some(b2) = used_decl.ambiguity.get() {
if let Some((b2, warning)) = used_decl.ambiguity.get() {
let ambiguity_error = AmbiguityError {
kind: AmbiguityKind::GlobVsGlob,
ambig_vis: None,
Expand All @@ -2112,7 +2090,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
b2,
scope1: Scope::ModuleGlobs(used_decl.parent_module.unwrap(), None),
scope2: Scope::ModuleGlobs(b2.parent_module.unwrap(), None),
warning: if warn_ambiguity { Some(AmbiguityWarning::GlobImport) } else { None },
warning: if warning { Some(AmbiguityWarning::GlobImport) } else { None },
};
if !self.matches_previous_ambiguity_error(&ambiguity_error) {
// avoid duplicated span information to be emit out
Expand Down Expand Up @@ -2162,12 +2140,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
self.used_imports.insert(id);
}
self.add_to_glob_map(import, ident.name);
self.record_use_inner(
ident,
source_decl,
Used::Other,
warn_ambiguity || source_decl.warn_ambiguity.get(),
);
self.record_use(ident, source_decl, Used::Other);
}
}

Expand Down
6 changes: 1 addition & 5 deletions tests/ui/imports/ambiguous-1.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//@ check-pass
// https://github.com/rust-lang/rust/pull/112743#issuecomment-1601986883

#![warn(ambiguous_glob_imports)]

macro_rules! m {
() => {
pub fn id() {}
Expand All @@ -27,6 +24,5 @@ pub use openssl::*;

fn main() {
id();
//~^ WARNING `id` is ambiguous
//~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//~^ ERROR `id` is ambiguous
}
60 changes: 13 additions & 47 deletions tests/ui/imports/ambiguous-1.stderr
Original file line number Diff line number Diff line change
@@ -1,68 +1,34 @@
warning: ambiguous glob re-exports
--> $DIR/ambiguous-1.rs:13:13
|
LL | pub use self::evp::*;
| ^^^^^^^^^^^^ the name `id` in the value namespace is first re-exported here
LL |
LL | pub use self::handwritten::*;
| -------------------- but the name `id` in the value namespace is also re-exported here
|
= note: `#[warn(ambiguous_glob_reexports)]` on by default

warning: `id` is ambiguous
--> $DIR/ambiguous-1.rs:29:5
error[E0659]: `id` is ambiguous
--> $DIR/ambiguous-1.rs:26:5
|
LL | id();
| ^^ ambiguous name
|
= note: ambiguous because of multiple glob imports of a name in the same module
note: `id` could refer to the function imported here
--> $DIR/ambiguous-1.rs:13:13
--> $DIR/ambiguous-1.rs:10:13
|
LL | pub use self::evp::*;
| ^^^^^^^^^^^^
= help: consider adding an explicit import of `id` to disambiguate
note: `id` could also refer to the function imported here
--> $DIR/ambiguous-1.rs:15:13
--> $DIR/ambiguous-1.rs:12:13
|
LL | pub use self::handwritten::*;
| ^^^^^^^^^^^^^^^^^^^^
= help: consider adding an explicit import of `id` 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 #114095 <https://github.com/rust-lang/rust/issues/114095>
note: the lint level is defined here
--> $DIR/ambiguous-1.rs:4:9
|
LL | #![warn(ambiguous_glob_imports)]
| ^^^^^^^^^^^^^^^^^^^^^^

warning: 2 warnings emitted

Future incompatibility report: Future breakage diagnostic:
warning: `id` is ambiguous
--> $DIR/ambiguous-1.rs:29:5
|
LL | id();
| ^^ ambiguous name
|
= note: ambiguous because of multiple glob imports of a name in the same module
note: `id` could refer to the function imported here
--> $DIR/ambiguous-1.rs:13:13
warning: ambiguous glob re-exports
--> $DIR/ambiguous-1.rs:10:13
|
LL | pub use self::evp::*;
| ^^^^^^^^^^^^
= help: consider adding an explicit import of `id` to disambiguate
note: `id` could also refer to the function imported here
--> $DIR/ambiguous-1.rs:15:13
|
| ^^^^^^^^^^^^ the name `id` in the value namespace is first re-exported here
LL |
LL | pub use self::handwritten::*;
| ^^^^^^^^^^^^^^^^^^^^
= help: consider adding an explicit import of `id` 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 #114095 <https://github.com/rust-lang/rust/issues/114095>
note: the lint level is defined here
--> $DIR/ambiguous-1.rs:4:9
| -------------------- but the name `id` in the value namespace is also re-exported here
|
LL | #![warn(ambiguous_glob_imports)]
| ^^^^^^^^^^^^^^^^^^^^^^
= note: `#[warn(ambiguous_glob_reexports)]` on by default

error: aborting due to 1 previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0659`.
1 change: 0 additions & 1 deletion tests/ui/imports/ambiguous-10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ use crate::a::*;
use crate::b::*;
fn c(_: Token) {}
//~^ ERROR `Token` is ambiguous
//~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
fn main() { }
30 changes: 2 additions & 28 deletions tests/ui/imports/ambiguous-10.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: `Token` is ambiguous
error[E0659]: `Token` is ambiguous
--> $DIR/ambiguous-10.rs:15:9
|
LL | fn c(_: Token) {}
Expand All @@ -17,33 +17,7 @@ note: `Token` could also refer to the enum imported here
LL | use crate::b::*;
| ^^^^^^^^^^^
= help: consider adding an explicit import of `Token` 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 #114095 <https://github.com/rust-lang/rust/issues/114095>
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default

error: aborting due to 1 previous error

Future incompatibility report: Future breakage diagnostic:
error: `Token` is ambiguous
--> $DIR/ambiguous-10.rs:15:9
|
LL | fn c(_: Token) {}
| ^^^^^ ambiguous name
|
= note: ambiguous because of multiple glob imports of a name in the same module
note: `Token` could refer to the enum imported here
--> $DIR/ambiguous-10.rs:13:5
|
LL | use crate::a::*;
| ^^^^^^^^^^^
= help: consider adding an explicit import of `Token` to disambiguate
note: `Token` could also refer to the enum imported here
--> $DIR/ambiguous-10.rs:14:5
|
LL | use crate::b::*;
| ^^^^^^^^^^^
= help: consider adding an explicit import of `Token` 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 #114095 <https://github.com/rust-lang/rust/issues/114095>
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default

For more information about this error, try `rustc --explain E0659`.
1 change: 0 additions & 1 deletion tests/ui/imports/ambiguous-12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ use crate::public::*;
fn main() {
b();
//~^ ERROR `b` is ambiguous
//~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
}
30 changes: 2 additions & 28 deletions tests/ui/imports/ambiguous-12.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: `b` is ambiguous
error[E0659]: `b` is ambiguous
--> $DIR/ambiguous-12.rs:21:5
|
LL | b();
Expand All @@ -17,33 +17,7 @@ note: `b` could also refer to the function imported here
LL | use crate::public::*;
| ^^^^^^^^^^^^^^^^
= help: consider adding an explicit import of `b` 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 #114095 <https://github.com/rust-lang/rust/issues/114095>
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default

error: aborting due to 1 previous error

Future incompatibility report: Future breakage diagnostic:
error: `b` is ambiguous
--> $DIR/ambiguous-12.rs:21:5
|
LL | b();
| ^ ambiguous name
|
= note: ambiguous because of multiple glob imports of a name in the same module
note: `b` could refer to the function imported here
--> $DIR/ambiguous-12.rs:17:5
|
LL | use crate::ciphertext::*;
| ^^^^^^^^^^^^^^^^^^^^
= help: consider adding an explicit import of `b` to disambiguate
note: `b` could also refer to the function imported here
--> $DIR/ambiguous-12.rs:18:5
|
LL | use crate::public::*;
| ^^^^^^^^^^^^^^^^
= help: consider adding an explicit import of `b` 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 #114095 <https://github.com/rust-lang/rust/issues/114095>
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default

For more information about this error, try `rustc --explain E0659`.
1 change: 0 additions & 1 deletion tests/ui/imports/ambiguous-13.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ use crate::content::*;

fn a(_: Rect) {}
//~^ ERROR `Rect` is ambiguous
//~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
fn main() { }
30 changes: 2 additions & 28 deletions tests/ui/imports/ambiguous-13.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: `Rect` is ambiguous
error[E0659]: `Rect` is ambiguous
--> $DIR/ambiguous-13.rs:18:9
|
LL | fn a(_: Rect) {}
Expand All @@ -17,33 +17,7 @@ note: `Rect` could also refer to the struct imported here
LL | use crate::content::*;
| ^^^^^^^^^^^^^^^^^
= help: consider adding an explicit import of `Rect` 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 #114095 <https://github.com/rust-lang/rust/issues/114095>
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default

error: aborting due to 1 previous error

Future incompatibility report: Future breakage diagnostic:
error: `Rect` is ambiguous
--> $DIR/ambiguous-13.rs:18:9
|
LL | fn a(_: Rect) {}
| ^^^^ ambiguous name
|
= note: ambiguous because of multiple glob imports of a name in the same module
note: `Rect` could refer to the struct imported here
--> $DIR/ambiguous-13.rs:15:5
|
LL | use crate::object::*;
| ^^^^^^^^^^^^^^^^
= help: consider adding an explicit import of `Rect` to disambiguate
note: `Rect` could also refer to the struct imported here
--> $DIR/ambiguous-13.rs:16:5
|
LL | use crate::content::*;
| ^^^^^^^^^^^^^^^^^
= help: consider adding an explicit import of `Rect` 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 #114095 <https://github.com/rust-lang/rust/issues/114095>
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default

For more information about this error, try `rustc --explain E0659`.
Loading
Loading