Skip to content

Commit 34f1275

Browse files
authored
Rollup merge of #85724 - sexxi-goose:rox-fix-issue-85435, r=nikomatsakis
Fix issue 85435 by restricting Fake Read precision This PR fixes the root bug of issue #85435 by restricting Fake Read precision in closures and removing the feature gate introduced in PR #85564. More info [here](#85561 (comment)) and [here](#85561 (comment)). Closes #85561 r? ``@nikomatsakis``
2 parents 9b1e105 + 382338f commit 34f1275

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

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

+15-19
Original file line numberDiff line numberDiff line change
@@ -186,25 +186,21 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
186186
// };
187187
// ```
188188
//
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-
}
189+
for (thir_place, cause, hir_id) in fake_reads.into_iter() {
190+
let place_builder =
191+
unpack!(block = this.as_place_builder(block, &this.thir[*thir_place]));
192+
193+
if let Ok(place_builder_resolved) =
194+
place_builder.try_upvars_resolved(this.tcx, this.typeck_results)
195+
{
196+
let mir_place =
197+
place_builder_resolved.into_place(this.tcx, this.typeck_results);
198+
this.cfg.push_fake_read(
199+
block,
200+
this.source_info(this.tcx.hir().span(*hir_id)),
201+
*cause,
202+
mir_place,
203+
);
208204
}
209205
}
210206

compiler/rustc_typeck/src/check/upvar.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,11 @@ impl<'a, 'tcx> InferBorrowKind<'a, 'tcx> {
15881588
impl<'a, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'tcx> {
15891589
fn fake_read(&mut self, place: Place<'tcx>, cause: FakeReadCause, diag_expr_id: hir::HirId) {
15901590
if let PlaceBase::Upvar(_) = place.base {
1591+
// We need to restrict Fake Read precision to avoid fake reading unsafe code,
1592+
// such as deref of a raw pointer.
1593+
let place = restrict_capture_precision(place);
1594+
let place =
1595+
restrict_repr_packed_field_ref_capture(self.fcx.tcx, self.fcx.param_env, &place);
15911596
self.fake_reads.push((place, cause, diag_expr_id));
15921597
}
15931598
}

0 commit comments

Comments
 (0)