-
Notifications
You must be signed in to change notification settings - Fork 490
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
Document auto trait inference for async blocks #1093
base: master
Are you sure you want to change the base?
Conversation
We are in the process of changing this (rust-lang/#69663), but it would be good to document the existing rules before changing them. This should also help explain the compilation errors people are getting in the meantime.
src/expressions/block-expr.md
Outdated
# ; | ||
``` | ||
|
||
Here the result of `bar()` is in scope during the await of `foo()`, so the result of `bar()` will impact the inferred auto traits. |
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.
The phrase "during the await of foo()
" might be ambiguous, depending on what other assumptions the reader is making.
I guess my concern is about some scenario where you have an EXPR.await
, and the temporary scope of some baz()
is entirely contained within the EXPR, and does not overlap the .await
operator itself.
(I will see if I can construct an illustrative example.)
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 changed "during" to "for," but I don't think that really addresses your concern...
A couple of examples that might be relevant here could be something like foo().bar().await
, and { let bar = foo().bar(); bar }.await
. I'll have to experiment some more, but I think what happens here is that foo()
is borrowed across the away in the first example, but not the second.
I think this documentation would be improved if it had examples of both sides of the coin. Think of it as how some theorems are illuminated by showing both examples and counter-examples. E.g. you have shown a case where So I think the other thing I would show is some other bit of code, perhaps as close as possible to the provided example, (or even modify the existing example), where some temporary |
I added a couple more examples, one that's a slightly more complex version of the previous example, and another that shows a small change to remove a borrow from the scope. I'm not convinced these are the best examples, but they're an example of the cases I've looked closest at and they do highlight some of the trickier issues here. What do you think? |
@pnkfelix Did you have any more comments on this? |
This came up in the Lang Docs call today. It'd be good to get some up to date documentation in this area. The behavior described in this PR has changed now that drop-tracking-mir is on by default, so it needs to be brought up to date. #1088 might describe the current behavior, but it also should be checked for correctness. |
@rustbot author |
We are in the process of changing this (rust-lang/rust#69663), but it would be good to document the existing rules before changing them. This should also help explain the compilation errors people are getting in the meantime.