-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Fix some suggestions where a Box<T>
is expected.
#111056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,12 @@ | ||
#![feature(async_closure)] | ||
|
||
// edition:2021 | ||
|
||
fn foo<X>(x: impl FnOnce() -> Box<X>) {} | ||
// just to make sure async closures can still be suggested for boxing. | ||
fn bar<X>(x: Box<dyn FnOnce() -> X>) {} | ||
|
||
fn main() { | ||
foo(async move || {}); //~ ERROR mismatched types | ||
bar(async move || {}); //~ ERROR mismatched types | ||
} |
This file contains hidden or 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,34 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-111011.rs:10:23 | ||
| | ||
LL | foo(async move || {}); | ||
| ^^ expected `Box<_>`, found `async` closure body | ||
| | ||
= note: expected struct `Box<_>` | ||
found `async` closure body `[async closure body@$DIR/issue-111011.rs:10:23: 10:25]` | ||
= note: for more on 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 | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-111011.rs:11:9 | ||
| | ||
LL | bar(async move || {}); | ||
| --- ^^^^^^^^^^^^^^^^ expected `Box<dyn FnOnce() -> _>`, found closure | ||
| | | ||
| arguments to this function are incorrect | ||
| | ||
= note: expected struct `Box<(dyn FnOnce() -> _ + 'static)>` | ||
found closure `[closure@$DIR/issue-111011.rs:11:9: 11:22]` | ||
= note: for more on 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 | ||
note: function defined here | ||
--> $DIR/issue-111011.rs:7:4 | ||
| | ||
LL | fn bar<X>(x: Box<dyn FnOnce() -> X>) {} | ||
| ^^^ ------------------------- | ||
help: store this in the heap by calling `Box::new` | ||
| | ||
LL | bar(Box::new(async move || {})); | ||
| +++++++++ + | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
This file contains hidden or 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,12 @@ | ||
#![feature(async_closure)] | ||
|
||
// edition:2021 | ||
// run-rustfix | ||
|
||
fn foo<T>(_: Box<T>) {} | ||
fn bar<T>(_: impl Fn() -> Box<T>) {} | ||
|
||
fn main() { | ||
foo(Box::new(())); //~ ERROR mismatched types | ||
bar(|| Box::new(())); //~ ERROR mismatched types | ||
} |
This file contains hidden or 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,12 @@ | ||
#![feature(async_closure)] | ||
|
||
// edition:2021 | ||
// run-rustfix | ||
|
||
fn foo<T>(_: Box<T>) {} | ||
fn bar<T>(_: impl Fn() -> Box<T>) {} | ||
|
||
fn main() { | ||
foo({}); //~ ERROR mismatched types | ||
bar(|| {}); //~ ERROR mismatched types | ||
} |
This file contains hidden or 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,33 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/suggest-boxed-empty-block.rs:10:9 | ||
| | ||
LL | foo({}); | ||
| ^^ expected `Box<_>`, found `()` | ||
| | ||
= note: expected struct `Box<_>` | ||
found unit type `()` | ||
= note: for more on 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: store this in the heap by calling `Box::new` | ||
| | ||
LL - foo({}); | ||
LL + foo(Box::new(())); | ||
| | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/suggest-boxed-empty-block.rs:11:12 | ||
| | ||
LL | bar(|| {}); | ||
| ^^ expected `Box<_>`, found `()` | ||
| | ||
= note: expected struct `Box<_>` | ||
found unit type `()` | ||
= note: for more on 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: store this in the heap by calling `Box::new` | ||
| | ||
LL - bar(|| {}); | ||
LL + bar(|| Box::new(())); | ||
| | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.