about summary refs log tree commit diff
diff options
context:
space:
mode:
authorjam1garner <8260240+jam1garner@users.noreply.github.com>2021-05-26 23:00:19 -0400
committerNiko Matsakis <niko@alum.mit.edu>2021-06-14 13:27:24 -0400
commit1626e1938ab6378c2b44891a1e4bd73c3f96719c (patch)
tree779bdf092b3a7f43a82f99e56f5ce34da0a7b390
parenta9dc234c436b17896e3109a88c12c093db515666 (diff)
downloadrust-1626e1938ab6378c2b44891a1e4bd73c3f96719c.tar.gz
rust-1626e1938ab6378c2b44891a1e4bd73c3f96719c.zip
Add support for associated functions to `future_prelude_collision` lint
-rw-r--r--compiler/rustc_span/src/symbol.rs1
-rw-r--r--compiler/rustc_typeck/src/check/method/mod.rs29
2 files changed, 29 insertions, 1 deletions
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();