Skip to content

Commit d86f9d4

Browse files
committed
Auto merge of rust-lang#85893 - pnkfelix:beta-backport-85564, r=simulacrum
[beta] backport of readd capture disjoint fields gate Beta backport of "readd capture disjoint fields gate", PR rust-lang#85564 Fix issue rust-lang#85435
2 parents e79b979 + f9f5fc8 commit d86f9d4

File tree

2 files changed

+45
-14
lines changed

2 files changed

+45
-14
lines changed

compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

+20-14
Original file line numberDiff line numberDiff line change
@@ -179,20 +179,26 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
179179
// match x { _ => () } // fake read of `x`
180180
// };
181181
// ```
182-
for (thir_place, cause, hir_id) in fake_reads.into_iter() {
183-
let place_builder = unpack!(block = this.as_place_builder(block, thir_place));
184-
185-
if let Ok(place_builder_resolved) =
186-
place_builder.try_upvars_resolved(this.tcx, this.typeck_results)
187-
{
188-
let mir_place =
189-
place_builder_resolved.into_place(this.tcx, this.typeck_results);
190-
this.cfg.push_fake_read(
191-
block,
192-
this.source_info(this.tcx.hir().span(*hir_id)),
193-
*cause,
194-
mir_place,
195-
);
182+
//
183+
// FIXME(RFC2229, rust#85435): Remove feature gate once diagnostics are
184+
// improved and unsafe checking works properly in closure bodies again.
185+
if this.tcx.features().capture_disjoint_fields {
186+
for (thir_place, cause, hir_id) in fake_reads.into_iter() {
187+
let place_builder =
188+
unpack!(block = this.as_place_builder(block, thir_place));
189+
190+
if let Ok(place_builder_resolved) =
191+
place_builder.try_upvars_resolved(this.tcx, this.typeck_results)
192+
{
193+
let mir_place =
194+
place_builder_resolved.into_place(this.tcx, this.typeck_results);
195+
this.cfg.push_fake_read(
196+
block,
197+
this.source_info(this.tcx.hir().span(*hir_id)),
198+
*cause,
199+
mir_place,
200+
);
201+
}
196202
}
197203
}
198204

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// check-pass
2+
3+
// This is issue #85435. But the real story is reflected in issue #85561, where
4+
// a bug in the implementation of feature(capture_disjoint_fields) () was
5+
// exposed to non-feature-gated code by a diagnostic changing PR that removed
6+
// the gating in one case.
7+
8+
// This test is double-checking that the case of interest continues to work as
9+
// expected in the *absence* of that feature gate. At the time of this writing,
10+
// enabling the feature gate will cause this test to fail. We obviously cannot
11+
// stabilize that feature until it can correctly handle this test.
12+
13+
fn main() {
14+
let val: u8 = 5;
15+
let u8_ptr: *const u8 = &val;
16+
let _closure = || {
17+
unsafe {
18+
let tmp = *u8_ptr;
19+
tmp
20+
21+
// Just dereferencing and returning directly compiles fine:
22+
// *u8_ptr
23+
}
24+
};
25+
}

0 commit comments

Comments
 (0)