From 79388aa067e27824973f8f25fd6c4775d35388fd Mon Sep 17 00:00:00 2001 From: jam1garner <8260240+jam1garner@users.noreply.github.com> Date: Tue, 25 May 2021 23:27:26 -0400 Subject: Add future_prelude_collision lint --- compiler/rustc_span/src/symbol.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'compiler/rustc_span/src') diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index fb37c5e9c1e..8019569ab9b 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1236,7 +1236,9 @@ symbols! { truncf32, truncf64, try_blocks, + try_from, try_from_trait, + try_into, try_into_trait, try_trait_v2, tt, -- cgit 1.4.1-3-g733a5 From 1626e1938ab6378c2b44891a1e4bd73c3f96719c Mon Sep 17 00:00:00 2001 From: jam1garner <8260240+jam1garner@users.noreply.github.com> Date: Wed, 26 May 2021 23:00:19 -0400 Subject: Add support for associated functions to `future_prelude_collision` lint --- compiler/rustc_span/src/symbol.rs | 1 + compiler/rustc_typeck/src/check/method/mod.rs | 29 ++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'compiler/rustc_span/src') diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 8019569ab9b..19f55c47d58 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -587,6 +587,7 @@ symbols! { from, from_desugaring, from_generator, + from_iter, from_method, from_output, from_residual, diff --git a/compiler/rustc_typeck/src/check/method/mod.rs b/compiler/rustc_typeck/src/check/method/mod.rs index d2bd4b0dd32..1960e757bad 100644 --- a/compiler/rustc_typeck/src/check/method/mod.rs +++ b/compiler/rustc_typeck/src/check/method/mod.rs @@ -201,7 +201,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.lookup_probe(span, segment.ident, self_ty, call_expr, ProbeScope::TraitsInScope)?; if span.edition() < Edition::Edition2021 { - if let sym::try_from | sym::try_into = segment.ident.name { + if let sym::try_into = segment.ident.name { if let probe::PickKind::TraitPick = pick.kind { if !matches!(self.tcx.crate_name(pick.item.def_id.krate), sym::std | sym::core) { @@ -526,6 +526,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expr_id, ProbeScope::TraitsInScope, )?; + + if span.edition() < Edition::Edition2021 { + if let sym::try_into | sym::try_from | sym::from_iter = method_name.name { + if let probe::PickKind::TraitPick = pick.kind { + if !matches!(tcx.crate_name(pick.item.def_id.krate), sym::std | sym::core) { + tcx.struct_span_lint_hir(FUTURE_PRELUDE_COLLISION, expr_id, span, |lint| { + let trait_name = tcx.def_path_str(pick.item.container.assert_trait()); + + let mut lint = lint.build(&format!( + "trait method `{}` will become ambiguous in Rust 2021", + method_name.name + )); + + lint.span_suggestion( + span, + "disambiguate the associated function", + format!("<{} as {}>::{}", self_ty, trait_name, method_name.name,), + Applicability::MachineApplicable, + ); + + lint.emit(); + }); + } + } + } + } + debug!("resolve_ufcs: pick={:?}", pick); { let mut typeck_results = self.typeck_results.borrow_mut(); -- cgit 1.4.1-3-g733a5