Closed
Description
When encountering a boxed value as expected and a stack allocated value that could be boxed to fulfill the expectation, like in the following snippet, suggest Box::new
wrapping:
fn main() {
let x: Box<Fn() -> _> = || {
Err(())?;
Ok(())
};
}
error[E0308]: mismatched types
--> src/main.rs:3:29
|
3 | let x: Box<Fn() -> _> = || {
| _____________________________^
4 | | Err(())?;
5 | | Ok(())
6 | | };
| |_____^ expected struct `std::boxed::Box`, found closure
|
= note: expected type `std::boxed::Box<dyn std::ops::Fn() -> _>`
found type `[closure@src/main.rs:3:29: 6:6]`
Should suggest:
fn main() {
let x: Box<Fn() -> _> = Box::new(|| {
Err(())?;
Ok(())
});
}