-
Notifications
You must be signed in to change notification settings - Fork 14k
rustc_borrowck: fix async closure error note to report FnOnce rather than Fn #148713
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -331,7 +331,12 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> { | |
|
|
||
| let closure_kind = match def_ty { | ||
| DefiningTy::Closure(_, args) => args.as_closure().kind(), | ||
| DefiningTy::CoroutineClosure(_, args) => args.as_coroutine_closure().kind(), | ||
| DefiningTy::CoroutineClosure(_, args) => { | ||
| match args.as_coroutine_closure().kind() { | ||
| ty::ClosureKind::Fn => ty::ClosureKind::FnOnce, | ||
| kind => kind, | ||
| } | ||
| } | ||
| _ => { | ||
| // Can't have BrEnv in functions, constants or coroutines. | ||
| bug!("BrEnv outside of closure."); | ||
|
|
@@ -353,7 +358,8 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> { | |
| can't escape the closure" | ||
| } | ||
| ty::ClosureKind::FnOnce => { | ||
| bug!("BrEnv in a `FnOnce` closure"); | ||
| "closure implements `FnOnce`, so references to captured variables \ | ||
| can't escape the closure" | ||
| } | ||
| }; | ||
|
Contributor
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. Any way this can look like let note = format!("closure implements `{}`, so references to captured variables can't escape the closure", closure_kind.as_str());
Contributor
Author
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 did think about this. Correct me if I'm wrong, |
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
didn't look into this myself, but this seems... quite suboptimal.
Why are we not properly updating the kind for coroutine closures instead so that we don't have to deal with this weird behavior here?
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.
rust/compiler/rustc_hir_typeck/src/closure.rs
Lines 206 to 252 in a7b3715
It is marked as
Fnat line 212, I don't know if I am wording it correctly but my understanding is the existing code conflates calling capability with the actual type/behavior. This is the root cause.rust/compiler/rustc_hir_typeck/src/upvar.rs
Lines 251 to 261 in a7b3715
This fixme seems related. It could be a way larger refactor and I am not sure if we want to have the right behavior first, or do the refactor as well. It probably warrants more discussion.
rust/src/doc/rustc-dev-guide/src/coroutine-closures.md
Lines 269 to 287 in a7b3715
Might need to update the docs too if we do that.