Closed
Description
Consider this program:
struct Bravery {
guts: String
}
fn main() {
let guts = "mettle";
let _ = Bravery { guts };
}
Currently (as of nightly 23 July), we suggest just tacking on a .to_string()
, which isn't going to work.
error[E0308]: mismatched types
--> shorthand_method.rs:7:23
|
7 | let _ = Bravery { guts };
| ^^^^
| |
| expected struct `std::string::String`, found &str
| help: try using a conversion method: `guts.to_string()`
|
= note: expected type `std::string::String`
found type `&str`
error: aborting due to previous error
The conversion method suggestion was added in #46461. I fear it may be messier to remediate this than one might hope because demand_coerce
takes a hir::Expr
and would probably need another argument to know about the shorthand-ness, which lives on hir::FieldPat
.