Open
Description
Code
use std::fmt::Debug;
fn f(x: &dyn Debug) {
println!("{:?}", x)
}
fn main() {
let x: &[u8] = &[1, 2, 3];
f(x);
}
Current output
Compiling playground v0.0.1 (/playground)
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> src/lib.rs:9:7
|
9 | f(x);
| ^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `[u8]`
= note: required for the cast from `[u8]` to the object type `dyn Debug`
help: consider borrowing the value, since `&[u8]` can be coerced into `dyn Debug`
|
9 | f(&x);
| +
For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (lib) due to previous error
Desired output
No response
Rationale and extra context
This error confused me as it was in a context that I thought the type of x
is actually [u8]
, but it was &[u8]
and the problem was about dyn
cast.
Other cases
No response
Anything else?
No response