From 1d036f408efa6e12b2fcd35588b4595fde5b0af2 Mon Sep 17 00:00:00 2001 From: Jonathan Brouwer Date: Sat, 14 Jun 2025 00:08:28 +0200 Subject: [PATCH] Fix incorrect suggestion when calling an associated type with a type anchor Signed-off-by: Jonathan Brouwer --- compiler/rustc_hir_typeck/src/method/suggest.rs | 2 +- tests/ui/associated-types/associated-type-call.fixed | 2 +- tests/ui/associated-types/associated-type-call.stderr | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 6cb53bbd7452..288d915e85c6 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -724,7 +724,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { { let def_path = tcx.def_path_str(adt_def.did()); err.span_suggestion( - ty.span.to(item_ident.span), + sugg_span, format!("to construct a value of type `{}`, use the explicit path", def_path), def_path, Applicability::MachineApplicable, diff --git a/tests/ui/associated-types/associated-type-call.fixed b/tests/ui/associated-types/associated-type-call.fixed index a3bc910f6111..d450b3b82c96 100644 --- a/tests/ui/associated-types/associated-type-call.fixed +++ b/tests/ui/associated-types/associated-type-call.fixed @@ -14,7 +14,7 @@ impl Trait for () { type Assoc = T; fn f() { - ::Assoc(); help: to construct a value of type `T`, use the explicit path | LL - ::Assoc(); -LL +