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

Commit 1626e19

Browse files
jam1garnernikomatsakis
authored andcommitted
Add support for associated functions to future_prelude_collision lint
1 parent a9dc234 commit 1626e19

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ symbols! {
587587
from,
588588
from_desugaring,
589589
from_generator,
590+
from_iter,
590591
from_method,
591592
from_output,
592593
from_residual,

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
201201
self.lookup_probe(span, segment.ident, self_ty, call_expr, ProbeScope::TraitsInScope)?;
202202

203203
if span.edition() < Edition::Edition2021 {
204-
if let sym::try_from | sym::try_into = segment.ident.name {
204+
if let sym::try_into = segment.ident.name {
205205
if let probe::PickKind::TraitPick = pick.kind {
206206
if !matches!(self.tcx.crate_name(pick.item.def_id.krate), sym::std | sym::core)
207207
{
@@ -526,6 +526,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
526526
expr_id,
527527
ProbeScope::TraitsInScope,
528528
)?;
529+
530+
if span.edition() < Edition::Edition2021 {
531+
if let sym::try_into | sym::try_from | sym::from_iter = method_name.name {
532+
if let probe::PickKind::TraitPick = pick.kind {
533+
if !matches!(tcx.crate_name(pick.item.def_id.krate), sym::std | sym::core) {
534+
tcx.struct_span_lint_hir(FUTURE_PRELUDE_COLLISION, expr_id, span, |lint| {
535+
let trait_name = tcx.def_path_str(pick.item.container.assert_trait());
536+
537+
let mut lint = lint.build(&format!(
538+
"trait method `{}` will become ambiguous in Rust 2021",
539+
method_name.name
540+
));
541+
542+
lint.span_suggestion(
543+
span,
544+
"disambiguate the associated function",
545+
format!("<{} as {}>::{}", self_ty, trait_name, method_name.name,),
546+
Applicability::MachineApplicable,
547+
);
548+
549+
lint.emit();
550+
});
551+
}
552+
}
553+
}
554+
}
555+
529556
debug!("resolve_ufcs: pick={:?}", pick);
530557
{
531558
let mut typeck_results = self.typeck_results.borrow_mut();

0 commit comments

Comments
 (0)