Skip to content

Commit d8e74b6

Browse files
Only assert for child/parent projection compatibility AFTER checking that theyre coming from the same place
1 parent ff24ef9 commit d8e74b6

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

compiler/rustc_mir_transform/src/coroutine/by_move_body.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,6 @@ impl<'tcx> MirPass<'tcx> for ByMoveBody {
156156
bug!("expected capture to be an upvar");
157157
};
158158

159-
assert!(
160-
child_capture.place.projections.len() >= parent_capture.place.projections.len()
161-
);
162159
// A parent matches a child they share the same prefix of projections.
163160
// The child may have more, if it is capturing sub-fields out of
164161
// something that is captured by-move in the parent closure.
@@ -180,6 +177,14 @@ impl<'tcx> MirPass<'tcx> for ByMoveBody {
180177
continue;
181178
}
182179

180+
// This analysis only makes sense if the parent capture is a
181+
// prefix of the child capture.
182+
assert!(
183+
child_capture.place.projections.len() >= parent_capture.place.projections.len(),
184+
"parent capture ({parent_capture:#?}) expected to be prefix of \
185+
child capture ({child_capture:#?})"
186+
);
187+
183188
// Store this set of additional projections (fields and derefs).
184189
// We need to re-apply them later.
185190
let child_precise_captures =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//@ check-pass
2+
//@ edition: 2021
3+
// issue: rust-lang/rust#123697
4+
5+
#![feature(async_closure)]
6+
7+
struct S { t: i32 }
8+
9+
fn test(s: &S, t: &i32) {
10+
async || {
11+
println!("{}", s.t);
12+
println!("{}", t);
13+
};
14+
}
15+
16+
fn main() {}

0 commit comments

Comments
 (0)