Closed
Description
I tried this code:
fn main() {
let data: &[u8] = &[0; 10][..];
let points: &[i8] = data.into();
}
which outputs
error[E0277]: the trait bound `&[i8]: std::convert::From<&[u8]>` is not satisfied
--> src/main.rs:3:25
|
3 | let points: &[i8] = data.into();
| ^^^^^^^^^^^^^^^ the trait `std::convert::From<&[u8]>` is not implemented for `&[i8]`
|
= note: `std::convert::From<&[u8]>` is implemented for `&mut [i8]`, but not for `&[i8]`
= note: required because of the requirements on the impl of `std::convert::Into<&[i8]>` for `&[u8]`
= note: required by `std::convert::Into::into`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground`.
To learn more, run the command again with --verbose.
Note the suggestion
= note: `std::convert::From<&[u8]>` is implemented for `&mut [i8]`, but not for `&[i8]`
Changing the type of points
to &mut [i8]
will simply swap the suggestion to say From<&[u8]>
is not implemented for &mut [i8]
, but it is implemented for &[i8]
, ultimately making me chase my own tail. I have scoured the docs and came to the conclusion that From<&[u8]>
is not implemented for either of those types, so why does the compiler suggest it is?
This behaviour occurs across stable, beta and nightly on 1.42.