Skip to content

Commit 35cb28b

Browse files
committed
Verbose suggestion to make param const
``` error[E0747]: type provided when a constant was expected --> $DIR/invalid-const-arguments.rs:10:19 | LL | impl<N> Foo for B<N> {} | ^ | help: consider changing this type parameter to a const parameter | LL - impl<N> Foo for B<N> {} LL + impl<const N: u8> Foo for B<N> {} | ```
1 parent df8102f commit 35cb28b

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn generic_arg_mismatch_err(
7373
let param_name = tcx.hir_ty_param_name(param_local_id);
7474
let param_type = tcx.type_of(param.def_id).instantiate_identity();
7575
if param_type.is_suggestable(tcx, false) {
76-
err.span_suggestion(
76+
err.span_suggestion_verbose(
7777
tcx.def_span(src_def_id),
7878
"consider changing this type parameter to a const parameter",
7979
format!("const {param_name}: {param_type}"),

tests/ui/const-generics/early/invalid-const-arguments.stderr

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@ error[E0747]: type provided when a constant was expected
5151
--> $DIR/invalid-const-arguments.rs:10:19
5252
|
5353
LL | impl<N> Foo for B<N> {}
54-
| - ^
55-
| |
56-
| help: consider changing this type parameter to a const parameter: `const N: u8`
54+
| ^
55+
|
56+
help: consider changing this type parameter to a const parameter
57+
|
58+
LL - impl<N> Foo for B<N> {}
59+
LL + impl<const N: u8> Foo for B<N> {}
60+
|
5761

5862
error[E0747]: unresolved item provided when a constant was expected
5963
--> $DIR/invalid-const-arguments.rs:14:32

tests/ui/const-generics/kind_mismatch.stderr

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,25 @@ error[E0747]: type provided when a constant was expected
22
--> $DIR/kind_mismatch.rs:11:38
33
|
44
LL | impl<K> ContainsKey<K> for KeyHolder<K> {}
5-
| - ^
6-
| |
7-
| help: consider changing this type parameter to a const parameter: `const K: u8`
5+
| ^
6+
|
7+
help: consider changing this type parameter to a const parameter
8+
|
9+
LL - impl<K> ContainsKey<K> for KeyHolder<K> {}
10+
LL + impl<const K: u8> ContainsKey<K> for KeyHolder<K> {}
11+
|
812

913
error[E0747]: type provided when a constant was expected
1014
--> $DIR/kind_mismatch.rs:11:21
1115
|
1216
LL | impl<K> ContainsKey<K> for KeyHolder<K> {}
13-
| - ^
14-
| |
15-
| help: consider changing this type parameter to a const parameter: `const K: u8`
17+
| ^
18+
|
19+
help: consider changing this type parameter to a const parameter
20+
|
21+
LL - impl<K> ContainsKey<K> for KeyHolder<K> {}
22+
LL + impl<const K: u8> ContainsKey<K> for KeyHolder<K> {}
23+
|
1624

1725
error: aborting due to 2 previous errors
1826

0 commit comments

Comments
 (0)