-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
6 changed files
with
100 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// run-rustfix | ||
|
||
fn main() { | ||
let _x: Box<dyn Fn() -> Result<(), ()>> = Box::new(|| { //~ ERROR mismatched types | ||
Err(())?; | ||
Ok(()) | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// run-rustfix | ||
|
||
fn main() { | ||
let _x: Box<dyn Fn() -> Result<(), ()>> = || { //~ ERROR mismatched types | ||
Err(())?; | ||
Ok(()) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/suggest-box.rs:4:47 | ||
| | ||
LL | let _x: Box<dyn Fn() -> Result<(), ()>> = || { | ||
| _______________________________________________^ | ||
LL | | Err(())?; | ||
LL | | Ok(()) | ||
LL | | }; | ||
| |_____^ expected struct `std::boxed::Box`, found closure | ||
| | ||
= note: expected type `std::boxed::Box<dyn std::ops::Fn() -> std::result::Result<(), ()>>` | ||
found type `[closure@$DIR/suggest-box.rs:4:47: 7:6]` | ||
= note: for more information about the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html and https://doc.rust-lang.org/std/boxed/index.html | ||
help: you can store this in the heap calling `Box::new` | ||
| | ||
LL | let _x: Box<dyn Fn() -> Result<(), ()>> = Box::new(|| { | ||
LL | Err(())?; | ||
LL | Ok(()) | ||
LL | }); | ||
| | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |