Skip to content

Commit db44069

Browse files
authored
Rollup merge of #88497 - m-ou-se:prelude-collision-glob, r=nikomatsakis
Fix prelude collision suggestions for glob imported traits. Fixes #88471 cc `@nikomatsakis`
2 parents fdf9c09 + 89a9867 commit db44069

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

compiler/rustc_typeck/src/check/method/prelude2021.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hir as hir;
77
use rustc_middle::ty::subst::InternalSubsts;
88
use rustc_middle::ty::{Adt, Ref, Ty};
99
use rustc_session::lint::builtin::RUST_2021_PRELUDE_COLLISIONS;
10-
use rustc_span::symbol::kw::Underscore;
10+
use rustc_span::symbol::kw::{Empty, Underscore};
1111
use rustc_span::symbol::{sym, Ident};
1212
use rustc_span::Span;
1313
use rustc_trait_selection::infer::InferCtxtExt;
@@ -333,7 +333,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
333333
.filter_map(|item| if item.ident.name != Underscore { Some(item.ident) } else { None })
334334
.next();
335335
if let Some(any_id) = any_id {
336-
return Some(format!("{}", any_id));
336+
if any_id.name == Empty {
337+
// Glob import, so just use its name.
338+
return None;
339+
} else {
340+
return Some(format!("{}", any_id));
341+
}
337342
}
338343

339344
// All that is left is `_`! We need to use the full path. It doesn't matter which one we pick,

src/test/ui/rust-2021/future-prelude-collision-imported.fixed

+11
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,15 @@ mod c {
5656
}
5757
}
5858

59+
mod d {
60+
use super::m::*;
61+
62+
fn main() {
63+
// See https://github.com/rust-lang/rust/issues/88471
64+
let _: u32 = TryIntoU32::try_into(3u8).unwrap();
65+
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
66+
//~^^ WARNING this is accepted in the current edition
67+
}
68+
}
69+
5970
fn main() {}

src/test/ui/rust-2021/future-prelude-collision-imported.rs

+11
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,15 @@ mod c {
5656
}
5757
}
5858

59+
mod d {
60+
use super::m::*;
61+
62+
fn main() {
63+
// See https://github.com/rust-lang/rust/issues/88471
64+
let _: u32 = 3u8.try_into().unwrap();
65+
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
66+
//~^^ WARNING this is accepted in the current edition
67+
}
68+
}
69+
5970
fn main() {}

src/test/ui/rust-2021/future-prelude-collision-imported.stderr

+10-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,14 @@ LL | let _: u32 = 3u8.try_into().unwrap();
3030
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
3131
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>
3232

33-
warning: 3 warnings emitted
33+
warning: trait method `try_into` will become ambiguous in Rust 2021
34+
--> $DIR/future-prelude-collision-imported.rs:64:22
35+
|
36+
LL | let _: u32 = 3u8.try_into().unwrap();
37+
| ^^^^^^^^^^^^^^ help: disambiguate the associated function: `TryIntoU32::try_into(3u8)`
38+
|
39+
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
40+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>
41+
42+
warning: 4 warnings emitted
3443

0 commit comments

Comments
 (0)