From 01bdb8e38a5ba8c0db8ccaaeab66b1edd315aeca Mon Sep 17 00:00:00 2001 From: jam1garner <8260240+jam1garner@users.noreply.github.com> Date: Wed, 26 May 2021 00:53:30 -0400 Subject: [PATCH] Disable `future_prelude_collision` for 2021 edition --- compiler/rustc_typeck/src/check/method/mod.rs | 82 ++++++++++--------- 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/compiler/rustc_typeck/src/check/method/mod.rs b/compiler/rustc_typeck/src/check/method/mod.rs index 164b1a4910b..ba4635cc1bf 100644 --- a/compiler/rustc_typeck/src/check/method/mod.rs +++ b/compiler/rustc_typeck/src/check/method/mod.rs @@ -22,6 +22,7 @@ use rustc_middle::ty::subst::{InternalSubsts, SubstsRef}; use rustc_middle::ty::GenericParamDefKind; use rustc_middle::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TypeFoldable, WithConstness}; use rustc_session::lint::builtin::FUTURE_PRELUDE_COLLISION; +use rustc_span::edition::Edition; use rustc_span::symbol::{sym, Ident}; use rustc_span::Span; use rustc_trait_selection::traits; @@ -199,48 +200,51 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let pick = self.lookup_probe(span, segment.ident, self_ty, call_expr, ProbeScope::TraitsInScope)?; - if let sym::try_from | 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) { - self.tcx.struct_span_lint_hir( - FUTURE_PRELUDE_COLLISION, - call_expr.hir_id, - call_expr.span, - |lint| { - let sp = call_expr.span; - let trait_name = - self.tcx.def_path_str(pick.item.container.assert_trait()); + if span.edition() < Edition::Edition2021 { + if let sym::try_from | 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) + { + self.tcx.struct_span_lint_hir( + FUTURE_PRELUDE_COLLISION, + call_expr.hir_id, + call_expr.span, + |lint| { + let sp = call_expr.span; + let trait_name = + self.tcx.def_path_str(pick.item.container.assert_trait()); - let mut lint = lint.build(&format!( - "trait method `{}` will become ambiguous in Rust 2021", - segment.ident.name - )); + let mut lint = lint.build(&format!( + "trait method `{}` will become ambiguous in Rust 2021", + segment.ident.name + )); - if let Ok(self_expr) = - self.sess().source_map().span_to_snippet(self_expr.span) - { - lint.span_suggestion( - sp, - "disambiguate the associated function", - format!( - "{}::{}({})", - trait_name, segment.ident.name, self_expr, - ), - Applicability::MachineApplicable, - ); - } else { - lint.span_help( - sp, - &format!( - "disambiguate the associated function with `{}::{}(...)`", - trait_name, segment.ident, - ), - ); - } + if let Ok(self_expr) = + self.sess().source_map().span_to_snippet(self_expr.span) + { + lint.span_suggestion( + sp, + "disambiguate the associated function", + format!( + "{}::{}({})", + trait_name, segment.ident.name, self_expr, + ), + Applicability::MachineApplicable, + ); + } else { + lint.span_help( + sp, + &format!( + "disambiguate the associated function with `{}::{}(...)`", + trait_name, segment.ident, + ), + ); + } - lint.emit(); - }, - ); + lint.emit(); + }, + ); + } } } }