struct Test {
field: String,
}
impl std::ops::Deref for Test {
type Target = str;
fn deref(&self) -> &Self::Target {
&self.field
}
}
fn main() {
let test = Test {
field: String::new(),
};
let test_ref = &test;
let d1 = *test_ref;
let d = *test;
}
Current output
error[E0277]: the size for values of type `str` cannot be known at compilation time
--> src/main.rs:20:9
|
20 | let d = *test;
| ^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `str`
= note: all local variables must have a statically known size
= help: unsized locals are gated as an unstable feature
For more information about this error, try `rustc --explain E0277`.
error: could not compile `e0277` (bin "e0277") due to previous error
Desired output
No response
Rationale and extra context
FMPOV, analyzer/compiler tries to fit dereference (*) on existing Deref implementation. During this it happily "upgrades" deref signature from consuming ref and returning ref onto move semantics. Thus it reports no Sized implementation for str while declared is &str.
Code
Current output
Desired output
No response
Rationale and extra context
FMPOV, analyzer/compiler tries to fit dereference (
*
) on existingDeref
implementation. During this it happily "upgrades"deref
signature from consuming ref and returning ref onto move semantics. Thus it reports noSized
implementation forstr
while declared is&str
.Other cases
No response
Rust Version
Anything else?
No response