Rollup merge of #142043 - estebank:const-suggestion, r=wesleywiser

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> {}
   |
```

Part of rust-lang/rust#141973.
This commit is contained in:
Guillaume Gomez 2025-06-06 23:53:17 +02:00 committed by GitHub
commit 4ce2db5b31
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 10 deletions

View file

@ -73,7 +73,7 @@ fn generic_arg_mismatch_err(
let param_name = tcx.hir_ty_param_name(param_local_id);
let param_type = tcx.type_of(param.def_id).instantiate_identity();
if param_type.is_suggestable(tcx, false) {
err.span_suggestion(
err.span_suggestion_verbose(
tcx.def_span(src_def_id),
"consider changing this type parameter to a const parameter",
format!("const {param_name}: {param_type}"),

View file

@ -51,9 +51,13 @@ 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: `const N: u8`
| ^
|
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> {}
|
error[E0747]: unresolved item provided when a constant was expected
--> $DIR/invalid-const-arguments.rs:14:32

View file

@ -2,17 +2,25 @@ error[E0747]: type provided when a constant was expected
--> $DIR/kind_mismatch.rs:11:38
|
LL | impl<K> ContainsKey<K> for KeyHolder<K> {}
| - ^
| |
| help: consider changing this type parameter to a const parameter: `const K: u8`
| ^
|
help: consider changing this type parameter to a const parameter
|
LL - impl<K> ContainsKey<K> for KeyHolder<K> {}
LL + impl<const K: u8> ContainsKey<K> for KeyHolder<K> {}
|
error[E0747]: type provided when a constant was expected
--> $DIR/kind_mismatch.rs:11:21
|
LL | impl<K> ContainsKey<K> for KeyHolder<K> {}
| - ^
| |
| help: consider changing this type parameter to a const parameter: `const K: u8`
| ^
|
help: consider changing this type parameter to a const parameter
|
LL - impl<K> ContainsKey<K> for KeyHolder<K> {}
LL + impl<const K: u8> ContainsKey<K> for KeyHolder<K> {}
|
error: aborting due to 2 previous errors