Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 01bdb8e

Browse files
jam1garnernikomatsakis
authored andcommitted
Disable future_prelude_collision for 2021 edition
1 parent 79388aa commit 01bdb8e

File tree

1 file changed

+46
-42
lines changed
  • compiler/rustc_typeck/src/check/method

1 file changed

+46
-42
lines changed

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

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use rustc_middle::ty::subst::{InternalSubsts, SubstsRef};
2222
use rustc_middle::ty::GenericParamDefKind;
2323
use rustc_middle::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TypeFoldable, WithConstness};
2424
use rustc_session::lint::builtin::FUTURE_PRELUDE_COLLISION;
25+
use rustc_span::edition::Edition;
2526
use rustc_span::symbol::{sym, Ident};
2627
use rustc_span::Span;
2728
use rustc_trait_selection::traits;
@@ -199,48 +200,51 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
199200
let pick =
200201
self.lookup_probe(span, segment.ident, self_ty, call_expr, ProbeScope::TraitsInScope)?;
201202

202-
if let sym::try_from | sym::try_into = segment.ident.name {
203-
if let probe::PickKind::TraitPick = pick.kind {
204-
if !matches!(self.tcx.crate_name(pick.item.def_id.krate), sym::std | sym::core) {
205-
self.tcx.struct_span_lint_hir(
206-
FUTURE_PRELUDE_COLLISION,
207-
call_expr.hir_id,
208-
call_expr.span,
209-
|lint| {
210-
let sp = call_expr.span;
211-
let trait_name =
212-
self.tcx.def_path_str(pick.item.container.assert_trait());
213-
214-
let mut lint = lint.build(&format!(
215-
"trait method `{}` will become ambiguous in Rust 2021",
216-
segment.ident.name
217-
));
218-
219-
if let Ok(self_expr) =
220-
self.sess().source_map().span_to_snippet(self_expr.span)
221-
{
222-
lint.span_suggestion(
223-
sp,
224-
"disambiguate the associated function",
225-
format!(
226-
"{}::{}({})",
227-
trait_name, segment.ident.name, self_expr,
228-
),
229-
Applicability::MachineApplicable,
230-
);
231-
} else {
232-
lint.span_help(
233-
sp,
234-
&format!(
235-
"disambiguate the associated function with `{}::{}(...)`",
236-
trait_name, segment.ident,
237-
),
238-
);
239-
}
240-
241-
lint.emit();
242-
},
243-
);
203+
if span.edition() < Edition::Edition2021 {
204+
if let sym::try_from | sym::try_into = segment.ident.name {
205+
if let probe::PickKind::TraitPick = pick.kind {
206+
if !matches!(self.tcx.crate_name(pick.item.def_id.krate), sym::std | sym::core)
207+
{
208+
self.tcx.struct_span_lint_hir(
209+
FUTURE_PRELUDE_COLLISION,
210+
call_expr.hir_id,
211+
call_expr.span,
212+
|lint| {
213+
let sp = call_expr.span;
214+
let trait_name =
215+
self.tcx.def_path_str(pick.item.container.assert_trait());
216+
217+
let mut lint = lint.build(&format!(
218+
"trait method `{}` will become ambiguous in Rust 2021",
219+
segment.ident.name
220+
));
221+
222+
if let Ok(self_expr) =
223+
self.sess().source_map().span_to_snippet(self_expr.span)
224+
{
225+
lint.span_suggestion(
226+
sp,
227+
"disambiguate the associated function",
228+
format!(
229+
"{}::{}({})",
230+
trait_name, segment.ident.name, self_expr,
231+
),
232+
Applicability::MachineApplicable,
233+
);
234+
} else {
235+
lint.span_help(
236+
sp,
237+
&format!(
238+
"disambiguate the associated function with `{}::{}(...)`",
239+
trait_name, segment.ident,
240+
),
241+
);
242+
}
243+
244+
lint.emit();
245+
},
246+
);
247+
}
244248
}
245249
}
246250
}

0 commit comments

Comments
 (0)