Skip to content

Commit 9d4a644

Browse files
authored
Rollup merge of #85564 - pnkfelix:issue-85435-readd-capture-disjoint-fields-gate, r=nikomatsakis
readd capture disjoint fields gate This readds a feature gate guard that was added in PR #83521. (Basically, there were unintended consequences to the code exposed by removing the feature gate guard.) The root bug still remains to be resolved, as discussed in issue #85561. This is just a band-aid suitable for a beta backport. Cc issue #85435 Note that the latter issue is unfixed until we backport this (or another fix) to 1.53 beta
2 parents 3530a78 + 1c1d4f9 commit 9d4a644

File tree

2 files changed

+47
-15
lines changed

2 files changed

+47
-15
lines changed

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

+20-15
Original file line numberDiff line numberDiff line change
@@ -185,21 +185,26 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
185185
// match x { _ => () } // fake read of `x`
186186
// };
187187
// ```
188-
for (thir_place, cause, hir_id) in fake_reads.into_iter() {
189-
let place_builder =
190-
unpack!(block = this.as_place_builder(block, &this.thir[*thir_place]));
191-
192-
if let Ok(place_builder_resolved) =
193-
place_builder.try_upvars_resolved(this.tcx, this.typeck_results)
194-
{
195-
let mir_place =
196-
place_builder_resolved.into_place(this.tcx, this.typeck_results);
197-
this.cfg.push_fake_read(
198-
block,
199-
this.source_info(this.tcx.hir().span(*hir_id)),
200-
*cause,
201-
mir_place,
202-
);
188+
//
189+
// FIXME(RFC2229, rust#85435): Remove feature gate once diagnostics are
190+
// improved and unsafe checking works properly in closure bodies again.
191+
if this.tcx.features().capture_disjoint_fields {
192+
for (thir_place, cause, hir_id) in fake_reads.into_iter() {
193+
let place_builder =
194+
unpack!(block = this.as_place_builder(block, &this.thir[*thir_place]));
195+
196+
if let Ok(place_builder_resolved) =
197+
place_builder.try_upvars_resolved(this.tcx, this.typeck_results)
198+
{
199+
let mir_place =
200+
place_builder_resolved.into_place(this.tcx, this.typeck_results);
201+
this.cfg.push_fake_read(
202+
block,
203+
this.source_info(this.tcx.hir().span(*hir_id)),
204+
*cause,
205+
mir_place,
206+
);
207+
}
203208
}
204209
}
205210

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

0 commit comments

Comments
 (0)