diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index 338cba7252726..90e1f34a275a0 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -2947,7 +2947,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { ); if def_id.is_local() { let name = tcx.def_path_str(def_id); - err.span_suggestion( + err.span_suggestion_verbose( tcx.def_span(def_id).shrink_to_lo(), format!("add `type` before `const` for `{name}`"), format!("type "), diff --git a/tests/ui/const-generics/mgca/assoc-const-without-type_const.stderr b/tests/ui/const-generics/mgca/assoc-const-without-type_const.stderr index 759a40cc06759..1a5f77ba33e15 100644 --- a/tests/ui/const-generics/mgca/assoc-const-without-type_const.stderr +++ b/tests/ui/const-generics/mgca/assoc-const-without-type_const.stderr @@ -1,20 +1,24 @@ error: use of `const` in the type system not defined as `type const` --> $DIR/assoc-const-without-type_const.rs:8:35 | -LL | const SIZE: usize; - | - help: add `type` before `const` for `Tr::SIZE`: `type` -... LL | fn mk_array(_x: T) -> [(); T::SIZE] { | ^^^^^^^ + | +help: add `type` before `const` for `Tr::SIZE` + | +LL | type const SIZE: usize; + | ++++ error: use of `const` in the type system not defined as `type const` --> $DIR/assoc-const-without-type_const.rs:10:10 | -LL | const SIZE: usize; - | - help: add `type` before `const` for `Tr::SIZE`: `type` -... LL | [(); T::SIZE] | ^^^^^^^ + | +help: add `type` before `const` for `Tr::SIZE` + | +LL | type const SIZE: usize; + | ++++ error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/mgca/unmarked-free-const.stderr b/tests/ui/const-generics/mgca/unmarked-free-const.stderr index 76875d8db0eff..dd33de4ce0223 100644 --- a/tests/ui/const-generics/mgca/unmarked-free-const.stderr +++ b/tests/ui/const-generics/mgca/unmarked-free-const.stderr @@ -1,11 +1,13 @@ error: use of `const` in the type system not defined as `type const` --> $DIR/unmarked-free-const.rs:9:18 | -LL | const N: usize = 4; - | - help: add `type` before `const` for `N`: `type` -... LL | let x = [(); N]; | ^ + | +help: add `type` before `const` for `N` + | +LL | type const N: usize = 4; + | ++++ error: aborting due to 1 previous error