rust/tests/ui/const-generics/generic_const_exprs/issue-83765.stderr
Esteban Küber 6b24fdf811 Provide structured suggestion for unconstrained generic constant
```
error: unconstrained generic constant
  --> $DIR/const-argument-if-length.rs:18:10
   |
LL |     pad: [u8; is_zst::<T>()],
   |          ^^^^^^^^^^^^^^^^^^^
   |
help: try adding a `where` bound
   |
LL | pub struct AtLeastByte<T: ?Sized> where [(); is_zst::<T>()]: {
   |                                   ++++++++++++++++++++++++++
```

Detect when the constant expression isn't `usize` and suggest casting:

```
error: unconstrained generic constant
 --> f300.rs:6:10
  |
6 |     bb::<{!N}>();
  |          ^^^^
-Ztrack-diagnostics: created at compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs:3539:36
  |
help: try adding a `where` bound
  |
5 | fn b<const N: bool>() where [(); {!N} as usize]: {
  |                       ++++++++++++++++++++++++++
```

Fix #122395.
2024-03-21 00:03:59 +00:00

38 lines
1.2 KiB
Plaintext

error[E0308]: method not compatible with trait
--> $DIR/issue-83765.rs:30:5
|
LL | fn size(&self) -> [usize; DIM] {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM`
|
= note: expected constant `Self::DIM`
found constant `DIM`
error: unconstrained generic constant
--> $DIR/issue-83765.rs:32:24
|
LL | self.reference.size()
| ^^^^
|
note: required by a bound in `TensorSize::size`
--> $DIR/issue-83765.rs:9:31
|
LL | fn size(&self) -> [usize; Self::DIM];
| ^^^^^^^^^ required by this bound in `TensorSize::size`
help: try adding a `where` bound
|
LL | fn size(&self) -> [usize; DIM] where [(); Self::DIM]: {
| ++++++++++++++++++++++
error[E0308]: mismatched types
--> $DIR/issue-83765.rs:32:9
|
LL | self.reference.size()
| ^^^^^^^^^^^^^^^^^^^^^ expected `DIM`, found `Self::DIM`
|
= note: expected constant `DIM`
found constant `Self::DIM`
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0308`.