about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJonathan Brouwer <jonathantbrouwer@gmail.com>2025-06-14 00:08:28 +0200
committerJonathan Brouwer <jonathantbrouwer@gmail.com>2025-06-14 00:08:28 +0200
commit1d036f408efa6e12b2fcd35588b4595fde5b0af2 (patch)
treec8fb31bea7fcfff831c569584f3ebfb4c14c1529
parentc9995d2492dc94ea92ac6639ac8757199da749d0 (diff)
downloadrust-1d036f408efa6e12b2fcd35588b4595fde5b0af2.tar.gz
rust-1d036f408efa6e12b2fcd35588b4595fde5b0af2.zip
Fix incorrect suggestion when calling an associated type with a type anchor
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
-rw-r--r--compiler/rustc_hir_typeck/src/method/suggest.rs2
-rw-r--r--tests/ui/associated-types/associated-type-call.fixed2
-rw-r--r--tests/ui/associated-types/associated-type-call.stderr2
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 6cb53bbd745..288d915e85c 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 a3bc910f611..d450b3b82c9 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() {
-        <T();
+        T();
         //~^ ERROR no associated item named `Assoc` found for unit type `()` in the current scope
     }
 }
diff --git a/tests/ui/associated-types/associated-type-call.stderr b/tests/ui/associated-types/associated-type-call.stderr
index 634009433c8..eaef775e304 100644
--- a/tests/ui/associated-types/associated-type-call.stderr
+++ b/tests/ui/associated-types/associated-type-call.stderr
@@ -7,7 +7,7 @@ LL |         <Self>::Assoc();
 help: to construct a value of type `T`, use the explicit path
    |
 LL -         <Self>::Assoc();
-LL +         <T();
+LL +         T();
    |
 
 error: aborting due to 1 previous error