forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#123658 - compiler-errors:stop-assuming, r=o…
…li-obk Stop making any assumption about the projections applied to the upvars in the `ByMoveBody` pass So it turns out that because of subtle optimizations like [`truncate_capture_for_optimization`](https://github.com/rust-lang/rust/blob/ab5bda1aa70f707014e2e691e43bc37a8819252a/compiler/rustc_hir_typeck/src/upvar.rs#L2351), we simply cannot make any assumptions about the shape of the projections applied to the upvar locals in a coroutine body. So stop doing that -- the code is resilient to such projections, so the assertion really existed only to "protect against the unknown". r? oli-obk Fixes rust-lang#123650
- Loading branch information
Showing
2 changed files
with
34 additions
and
19 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
17 changes: 17 additions & 0 deletions
17
tests/ui/async-await/async-closures/truncated-fields-when-imm.rs
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,17 @@ | ||
//@ edition: 2021 | ||
//@ check-pass | ||
|
||
#![feature(async_closure)] | ||
|
||
pub struct Struct { | ||
pub path: String, | ||
} | ||
|
||
// In `upvar.rs`, `truncate_capture_for_optimization` means that we don't actually | ||
// capture `&(*s.path)` here, but instead just `&(*s)`, but ONLY when the upvar is | ||
// immutable. This means that the assumption we have in `ByMoveBody` pass is wrong. | ||
pub fn test(s: &Struct) { | ||
let c = async move || { let path = &s.path; }; | ||
} | ||
|
||
fn main() {} |