1
Fork 0

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](https://github.com/rust-lang/rust/issues/85561#issuecomment-846223784) and [here](https://github.com/rust-lang/rust/issues/85561#issuecomment-847270533).

Closes #85561

r? ``@nikomatsakis``
This commit is contained in:
Yuki Okushi 2021-06-03 14:35:29 +09:00 committed by GitHub
commit 34f1275880
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 18 deletions

View file

@ -186,9 +186,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// }; // };
// ``` // ```
// //
// FIXME(RFC2229, rust#85435): Remove feature gate once diagnostics are
// improved and unsafe checking works properly in closure bodies again.
if this.tcx.features().capture_disjoint_fields {
for (thir_place, cause, hir_id) in fake_reads.into_iter() { for (thir_place, cause, hir_id) in fake_reads.into_iter() {
let place_builder = let place_builder =
unpack!(block = this.as_place_builder(block, &this.thir[*thir_place])); unpack!(block = this.as_place_builder(block, &this.thir[*thir_place]));
@ -206,7 +203,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
); );
} }
} }
}
// see (*) above // see (*) above
let operands: Vec<_> = upvars let operands: Vec<_> = upvars

View file

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