Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 43b81b3

Browse files
authoredApr 1, 2021
Rollup merge of rust-lang#83521 - sexxi-goose:quick-diagnostic-fix, r=nikomatsakis
2229: Fix diagnostic issue when using FakeReads in closures This PR fixes a diagnostic issue caused by rust-lang#82536. A temporary work around was used in this merged PR which involved feature gating the addition of FakeReads introduced as a result of pattern matching in closures. The fix involves adding an optional closure DefId to ForLet and ForMatchedPlace FakeReadCauses. This DefId will only be added if a closure pattern matches a Place starting with an Upvar. r? `@nikomatsakis`
2 parents 803ddb8 + 42797e2 commit 43b81b3

File tree

126 files changed

+1973
-1932
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+1973
-1932
lines changed
 

‎compiler/rustc_middle/src/mir/mod.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ pub enum StatementKind<'tcx> {
14821482
///
14831483
/// Note that this also is emitted for regular `let` bindings to ensure that locals that are
14841484
/// never accessed still get some sanity checks for, e.g., `let x: ! = ..;`
1485-
FakeRead(FakeReadCause, Box<Place<'tcx>>),
1485+
FakeRead(Box<(FakeReadCause, Place<'tcx>)>),
14861486

14871487
/// Write the discriminant for a variant to the enum Place.
14881488
SetDiscriminant { place: Box<Place<'tcx>>, variant_index: VariantIdx },
@@ -1575,7 +1575,12 @@ pub enum FakeReadCause {
15751575

15761576
/// `let x: !; match x {}` doesn't generate any read of x so we need to
15771577
/// generate a read of x to check that it is initialized and safe.
1578-
ForMatchedPlace,
1578+
///
1579+
/// If a closure pattern matches a Place starting with an Upvar, then we introduce a
1580+
/// FakeRead for that Place outside the closure, in such a case this option would be
1581+
/// Some(closure_def_id).
1582+
/// Otherwise, the value of the optional DefId will be None.
1583+
ForMatchedPlace(Option<DefId>),
15791584

15801585
/// A fake read of the RefWithinGuard version of a bind-by-value variable
15811586
/// in a match guard to ensure that it's value hasn't change by the time
@@ -1594,7 +1599,12 @@ pub enum FakeReadCause {
15941599
/// but in some cases it can affect the borrow checker, as in #53695.
15951600
/// Therefore, we insert a "fake read" here to ensure that we get
15961601
/// appropriate errors.
1597-
ForLet,
1602+
///
1603+
/// If a closure pattern matches a Place starting with an Upvar, then we introduce a
1604+
/// FakeRead for that Place outside the closure, in such a case this option would be
1605+
/// Some(closure_def_id).
1606+
/// Otherwise, the value of the optional DefId will be None.
1607+
ForLet(Option<DefId>),
15981608

15991609
/// If we have an index expression like
16001610
///
@@ -1618,7 +1628,9 @@ impl Debug for Statement<'_> {
16181628
use self::StatementKind::*;
16191629
match self.kind {
16201630
Assign(box (ref place, ref rv)) => write!(fmt, "{:?} = {:?}", place, rv),
1621-
FakeRead(ref cause, ref place) => write!(fmt, "FakeRead({:?}, {:?})", cause, place),
1631+
FakeRead(box (ref cause, ref place)) => {
1632+
write!(fmt, "FakeRead({:?}, {:?})", cause, place)
1633+
}
16221634
Retag(ref kind, ref place) => write!(
16231635
fmt,
16241636
"Retag({}{:?})",

‎compiler/rustc_middle/src/mir/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ macro_rules! make_mir_visitor {
380380
) => {
381381
self.visit_assign(place, rvalue, location);
382382
}
383-
StatementKind::FakeRead(_, place) => {
383+
StatementKind::FakeRead(box (_, place)) => {
384384
self.visit_place(
385385
place,
386386
PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),

0 commit comments

Comments
 (0)
Please sign in to comment.