From 51e4fbaed15ca5e2c534cc4a3b4e992116044cdb Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 30 Aug 2021 19:21:22 +0200 Subject: [PATCH 1/2] Fix prelude collision suggestions for glob imported traits. --- compiler/rustc_typeck/src/check/method/prelude2021.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_typeck/src/check/method/prelude2021.rs b/compiler/rustc_typeck/src/check/method/prelude2021.rs index b5bc9d3599acb..e8bafc5f2c66e 100644 --- a/compiler/rustc_typeck/src/check/method/prelude2021.rs +++ b/compiler/rustc_typeck/src/check/method/prelude2021.rs @@ -7,7 +7,7 @@ use rustc_hir as hir; use rustc_middle::ty::subst::InternalSubsts; use rustc_middle::ty::{Adt, Ref, Ty}; use rustc_session::lint::builtin::RUST_2021_PRELUDE_COLLISIONS; -use rustc_span::symbol::kw::Underscore; +use rustc_span::symbol::kw::{Empty, Underscore}; use rustc_span::symbol::{sym, Ident}; use rustc_span::Span; use rustc_trait_selection::infer::InferCtxtExt; @@ -322,7 +322,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .filter_map(|item| if item.ident.name != Underscore { Some(item.ident) } else { None }) .next(); if let Some(any_id) = any_id { - return Some(format!("{}", any_id)); + if any_id.name == Empty { + // Glob import, so just use its name. + return None; + } else { + return Some(format!("{}", any_id)); + } } // All that is left is `_`! We need to use the full path. It doesn't matter which one we pick, From 89a98675aafaebbc62fa9b76383902553124085c Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 30 Aug 2021 19:21:40 +0200 Subject: [PATCH 2/2] Add test for glob imported prelude collision trait. --- .../rust-2021/future-prelude-collision-imported.fixed | 11 +++++++++++ .../ui/rust-2021/future-prelude-collision-imported.rs | 11 +++++++++++ .../future-prelude-collision-imported.stderr | 11 ++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/test/ui/rust-2021/future-prelude-collision-imported.fixed b/src/test/ui/rust-2021/future-prelude-collision-imported.fixed index c5ff0b4bcd0f8..15ccff7496e09 100644 --- a/src/test/ui/rust-2021/future-prelude-collision-imported.fixed +++ b/src/test/ui/rust-2021/future-prelude-collision-imported.fixed @@ -56,4 +56,15 @@ mod c { } } +mod d { + use super::m::*; + + fn main() { + // See https://github.com/rust-lang/rust/issues/88471 + let _: u32 = TryIntoU32::try_into(3u8).unwrap(); + //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 + //~^^ WARNING this is accepted in the current edition + } +} + fn main() {} diff --git a/src/test/ui/rust-2021/future-prelude-collision-imported.rs b/src/test/ui/rust-2021/future-prelude-collision-imported.rs index cd39eec47f2a4..cdffcaf754541 100644 --- a/src/test/ui/rust-2021/future-prelude-collision-imported.rs +++ b/src/test/ui/rust-2021/future-prelude-collision-imported.rs @@ -56,4 +56,15 @@ mod c { } } +mod d { + use super::m::*; + + fn main() { + // See https://github.com/rust-lang/rust/issues/88471 + let _: u32 = 3u8.try_into().unwrap(); + //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 + //~^^ WARNING this is accepted in the current edition + } +} + fn main() {} diff --git a/src/test/ui/rust-2021/future-prelude-collision-imported.stderr b/src/test/ui/rust-2021/future-prelude-collision-imported.stderr index fbda5d61f36dc..56abb8abd4d15 100644 --- a/src/test/ui/rust-2021/future-prelude-collision-imported.stderr +++ b/src/test/ui/rust-2021/future-prelude-collision-imported.stderr @@ -30,5 +30,14 @@ LL | let _: u32 = 3u8.try_into().unwrap(); = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! = note: for more information, see -warning: 3 warnings emitted +warning: trait method `try_into` will become ambiguous in Rust 2021 + --> $DIR/future-prelude-collision-imported.rs:64:22 + | +LL | let _: u32 = 3u8.try_into().unwrap(); + | ^^^^^^^^^^^^^^ help: disambiguate the associated function: `TryIntoU32::try_into(3u8)` + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see + +warning: 4 warnings emitted