You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
casting variable with type &Unsized to &dyn Trait incorrectly says that the variable is unsized. #111406
use std::fmt::Debug;fnf(x:&dynDebug){println!("{:?}", x)}fnmain(){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.
Activity
Rollup merge of rust-lang#111451 - compiler-errors:note-cast-origin, …
Rollup merge of rust-lang#111451 - compiler-errors:note-cast-origin, …
Rollup merge of rust-lang#111451 - compiler-errors:note-cast-origin, …
Rollup merge of rust-lang#111451 - compiler-errors:note-cast-origin, …
Rollup merge of rust-lang#111451 - compiler-errors:note-cast-origin, …
Zoybean commentedon May 17, 2024
I can see how this pointer could have been especially misleading, given
xis&[u8]and thereforeSized:Maybe if it instead said:
but that might risk being too much repetition of similar-but-distinct terms (
[u8],&[u8],dyn Debug,&dyn Debug) in the context of the full error