-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix diagnostics for async block cloning #122589
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//@ edition:2021 | ||
|
||
async fn clone_async_block(value: String) { | ||
for _ in 0..10 { | ||
async { //~ ERROR: use of moved value: `value` [E0382] | ||
drop(value); | ||
//~^ HELP: consider cloning the value if the performance cost is acceptable | ||
}.await | ||
} | ||
} | ||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
error[E0382]: use of moved value: `value` | ||
--> $DIR/cloning-in-async-block-121547.rs:5:9 | ||
| | ||
LL | async fn clone_async_block(value: String) { | ||
| ----- move occurs because `value` has type `String`, which does not implement the `Copy` trait | ||
LL | for _ in 0..10 { | ||
| -------------- inside of this loop | ||
LL | / async { | ||
LL | | drop(value); | ||
| | ----- use occurs due to use in coroutine | ||
LL | | | ||
LL | | }.await | ||
| |_________^ value moved here, in previous iteration of loop | ||
| | ||
help: consider cloning the value if the performance cost is acceptable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like this error message is not right in spirit. Really we should be saying something like "cloning the value [if this is the behavior that you intended]". Cloning here could have different semantics than actually moving the value into the async block, for example. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to make sure, are you suggesting we should change the help message in general for cloning or only for this particular case in the async block? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't actually know :/ I guess this is a more general problem than what this aims to fix There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May I suggest creating an issue where we can talk about the appropriate wording? I would like to also share my opinion, however, I think this is not the right PR for that. |
||
| | ||
LL | drop(value.clone()); | ||
| ++++++++ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0382`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure what is a more fitting span, whether the
path_span
or thecapture_kind_span
. Both seem to be working correctly with the provided test.