1
Fork 0

Disable future_prelude_collision for 2021 edition

This commit is contained in:
jam1garner 2021-05-26 00:53:30 -04:00 committed by Niko Matsakis
parent 79388aa067
commit 01bdb8e38a

View file

@ -22,6 +22,7 @@ use rustc_middle::ty::subst::{InternalSubsts, SubstsRef};
use rustc_middle::ty::GenericParamDefKind; use rustc_middle::ty::GenericParamDefKind;
use rustc_middle::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TypeFoldable, WithConstness}; use rustc_middle::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TypeFoldable, WithConstness};
use rustc_session::lint::builtin::FUTURE_PRELUDE_COLLISION; use rustc_session::lint::builtin::FUTURE_PRELUDE_COLLISION;
use rustc_span::edition::Edition;
use rustc_span::symbol::{sym, Ident}; use rustc_span::symbol::{sym, Ident};
use rustc_span::Span; use rustc_span::Span;
use rustc_trait_selection::traits; use rustc_trait_selection::traits;
@ -199,48 +200,51 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let pick = let pick =
self.lookup_probe(span, segment.ident, self_ty, call_expr, ProbeScope::TraitsInScope)?; self.lookup_probe(span, segment.ident, self_ty, call_expr, ProbeScope::TraitsInScope)?;
if let sym::try_from | sym::try_into = segment.ident.name { if span.edition() < Edition::Edition2021 {
if let probe::PickKind::TraitPick = pick.kind { if let sym::try_from | sym::try_into = segment.ident.name {
if !matches!(self.tcx.crate_name(pick.item.def_id.krate), sym::std | sym::core) { if let probe::PickKind::TraitPick = pick.kind {
self.tcx.struct_span_lint_hir( if !matches!(self.tcx.crate_name(pick.item.def_id.krate), sym::std | sym::core)
FUTURE_PRELUDE_COLLISION, {
call_expr.hir_id, self.tcx.struct_span_lint_hir(
call_expr.span, FUTURE_PRELUDE_COLLISION,
|lint| { call_expr.hir_id,
let sp = call_expr.span; call_expr.span,
let trait_name = |lint| {
self.tcx.def_path_str(pick.item.container.assert_trait()); let sp = call_expr.span;
let trait_name =
self.tcx.def_path_str(pick.item.container.assert_trait());
let mut lint = lint.build(&format!( let mut lint = lint.build(&format!(
"trait method `{}` will become ambiguous in Rust 2021", "trait method `{}` will become ambiguous in Rust 2021",
segment.ident.name segment.ident.name
)); ));
if let Ok(self_expr) = if let Ok(self_expr) =
self.sess().source_map().span_to_snippet(self_expr.span) self.sess().source_map().span_to_snippet(self_expr.span)
{ {
lint.span_suggestion( lint.span_suggestion(
sp, sp,
"disambiguate the associated function", "disambiguate the associated function",
format!( format!(
"{}::{}({})", "{}::{}({})",
trait_name, segment.ident.name, self_expr, trait_name, segment.ident.name, self_expr,
), ),
Applicability::MachineApplicable, Applicability::MachineApplicable,
); );
} else { } else {
lint.span_help( lint.span_help(
sp, sp,
&format!( &format!(
"disambiguate the associated function with `{}::{}(...)`", "disambiguate the associated function with `{}::{}(...)`",
trait_name, segment.ident, trait_name, segment.ident,
), ),
); );
} }
lint.emit(); lint.emit();
}, },
); );
}
} }
} }
} }