Skip to content

Commit 28219e1

Browse files
committed
Newtype for FakeRead semi-traversable tuple
1 parent a5c812f commit 28219e1

File tree

13 files changed

+36
-27
lines changed

13 files changed

+36
-27
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ use rustc_middle::hir::nested_filter::OnlyBodies;
1414
use rustc_middle::mir::tcx::PlaceTy;
1515
use rustc_middle::mir::{
1616
self, AggregateKind, BindingForm, BorrowKind, CallSource, ClearCrossCrate, ConstraintCategory,
17-
FakeReadCause, LocalDecl, LocalInfo, LocalKind, Location, MutBorrowKind, Operand, Place,
18-
PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind,
19-
VarBindingForm,
17+
FakeReadCause, FakeReadCauseAndPlace, LocalDecl, LocalInfo, LocalKind, Location, MutBorrowKind,
18+
Operand, Place, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Terminator,
19+
TerminatorKind, VarBindingForm,
2020
};
2121
use rustc_middle::ty::{self, suggest_constraining_type_params, PredicateKind, Ty};
2222
use rustc_middle::util::CallKind;
@@ -3010,9 +3010,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
30103010
impl<'tcx> Visitor<'tcx> for FakeReadCauseFinder<'tcx> {
30113011
fn visit_statement(&mut self, statement: &Statement<'tcx>, _: Location) {
30123012
match statement {
3013-
Statement { kind: StatementKind::FakeRead(box (cause, place)), .. }
3014-
if *place == self.place =>
3015-
{
3013+
Statement {
3014+
kind: StatementKind::FakeRead(box FakeReadCauseAndPlace(cause, place)),
3015+
..
3016+
} if *place == self.place => {
30163017
self.cause = Some(*cause);
30173018
}
30183019
_ => (),

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use rustc_hir::intravisit::Visitor;
66
use rustc_index::IndexSlice;
77
use rustc_infer::infer::NllRegionVariableOrigin;
88
use rustc_middle::mir::{
9-
Body, CallSource, CastKind, ConstraintCategory, FakeReadCause, Local, LocalInfo, Location,
10-
Operand, Place, Rvalue, Statement, StatementKind, TerminatorKind,
9+
Body, CallSource, CastKind, ConstraintCategory, FakeReadCause, FakeReadCauseAndPlace, Local,
10+
LocalInfo, Location, Operand, Place, Rvalue, Statement, StatementKind, TerminatorKind,
1111
};
1212
use rustc_middle::ty::adjustment::PointerCoercion;
1313
use rustc_middle::ty::{self, RegionVid, TyCtxt};
@@ -477,7 +477,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
477477
let block = &self.body.basic_blocks[location.block];
478478

479479
let kind = if let Some(&Statement {
480-
kind: StatementKind::FakeRead(box (FakeReadCause::ForLet(_), place)),
480+
kind:
481+
StatementKind::FakeRead(box FakeReadCauseAndPlace(
482+
FakeReadCause::ForLet(_),
483+
place,
484+
)),
481485
..
482486
}) = block.statements.get(location.statement_index)
483487
{

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ use rustc_index::IndexSlice;
1313
use rustc_infer::infer::LateBoundRegionConversionTime;
1414
use rustc_middle::mir::tcx::PlaceTy;
1515
use rustc_middle::mir::{
16-
AggregateKind, CallSource, ConstOperand, FakeReadCause, Local, LocalInfo, LocalKind, Location,
17-
Operand, Place, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Terminator,
18-
TerminatorKind,
16+
AggregateKind, CallSource, ConstOperand, FakeReadCause, FakeReadCauseAndPlace, Local,
17+
LocalInfo, LocalKind, Location, Operand, Place, PlaceRef, ProjectionElem, Rvalue, Statement,
18+
StatementKind, Terminator, TerminatorKind,
1919
};
2020
use rustc_middle::ty::print::Print;
2121
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
@@ -797,7 +797,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
797797

798798
// StatementKind::FakeRead only contains a def_id if they are introduced as a result
799799
// of pattern matching within a closure.
800-
if let StatementKind::FakeRead(box (cause, place)) = stmt.kind {
800+
if let StatementKind::FakeRead(box FakeReadCauseAndPlace(cause, place)) = stmt.kind {
801801
match cause {
802802
FakeReadCause::ForMatchedPlace(Some(closure_def_id))
803803
| FakeReadCause::ForLet(Some(closure_def_id)) => {

compiler/rustc_borrowck/src/invalidation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
6262

6363
self.mutate_place(location, *lhs, Shallow(None));
6464
}
65-
StatementKind::FakeRead(box (_, _)) => {
65+
StatementKind::FakeRead(_) => {
6666
// Only relevant for initialized/liveness/safety checks.
6767
}
6868
StatementKind::Intrinsic(box NonDivergingIntrinsic::Assume(op)) => {

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ impl<'cx, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx, R> for MirBorro
629629

630630
self.mutate_place(location, (*lhs, span), Shallow(None), flow_state);
631631
}
632-
StatementKind::FakeRead(box (_, place)) => {
632+
StatementKind::FakeRead(box FakeReadCauseAndPlace(_, place)) => {
633633
// Read for match doesn't access any memory and is used to
634634
// assert that a place is safe and live. So we don't have to
635635
// do any checks here.

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ impl Debug for Statement<'_> {
680680
use self::StatementKind::*;
681681
match self.kind {
682682
Assign(box (ref place, ref rv)) => write!(fmt, "{place:?} = {rv:?}"),
683-
FakeRead(box (ref cause, ref place)) => {
683+
FakeRead(box FakeReadCauseAndPlace(ref cause, ref place)) => {
684684
write!(fmt, "FakeRead({cause:?}, {place:?})")
685685
}
686686
Retag(ref kind, ref place) => write!(

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ pub enum StatementKind<'tcx> {
288288
/// When executed at runtime this is a nop.
289289
///
290290
/// Disallowed after drop elaboration.
291-
FakeRead(Box<(FakeReadCause, Place<'tcx>)>),
291+
FakeRead(Box<FakeReadCauseAndPlace<'tcx>>),
292292

293293
/// Write the discriminant for a variant to the enum Place.
294294
///
@@ -459,6 +459,10 @@ pub enum RetagKind {
459459
Default,
460460
}
461461

462+
#[derive(Copy, Clone, TyEncodable, TyDecodable, Debug, Hash, HashStable, PartialEq)]
463+
#[derive(TypeFoldable, TypeVisitable)]
464+
pub struct FakeReadCauseAndPlace<'tcx>(pub FakeReadCause, pub Place<'tcx>);
465+
462466
/// The `FakeReadCause` describes the type of pattern why a FakeRead statement exists.
463467
#[derive(Copy, Clone, TyEncodable, TyDecodable, Debug, Hash, HashStable, PartialEq)]
464468
pub enum FakeReadCause {

compiler/rustc_middle/src/mir/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ macro_rules! make_mir_visitor {
379379
) => {
380380
self.visit_assign(place, rvalue, location);
381381
}
382-
StatementKind::FakeRead(box (_, place)) => {
382+
StatementKind::FakeRead(box FakeReadCauseAndPlace(_, place)) => {
383383
self.visit_place(
384384
place,
385385
PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect),

compiler/rustc_mir_build/src/build/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl<'tcx> CFG<'tcx> {
8585
cause: FakeReadCause,
8686
place: Place<'tcx>,
8787
) {
88-
let kind = StatementKind::FakeRead(Box::new((cause, place)));
88+
let kind = StatementKind::FakeRead(Box::new(FakeReadCauseAndPlace(cause, place)));
8989
let stmt = Statement { source_info, kind };
9090
self.push(block, stmt);
9191
}

compiler/rustc_mir_dataflow/src/move_paths/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> {
376376
}
377377
self.gather_rvalue(rval);
378378
}
379-
StatementKind::FakeRead(box (_, place)) => {
379+
StatementKind::FakeRead(box FakeReadCauseAndPlace(_, place)) => {
380380
self.create_move_path(*place);
381381
}
382382
StatementKind::StorageLive(_) => {}

compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_data_structures::captures::Captures;
22
use rustc_middle::mir::{
3-
self, AggregateKind, FakeReadCause, Rvalue, Statement, StatementKind, Terminator,
4-
TerminatorKind,
3+
self, AggregateKind, FakeReadCause, FakeReadCauseAndPlace, Rvalue, Statement, StatementKind,
4+
Terminator, TerminatorKind,
55
};
66
use rustc_span::Span;
77

@@ -120,10 +120,10 @@ fn filtered_statement_span(statement: &Statement<'_>) -> Option<Span> {
120120
// and `_1` is the `Place` for `somenum`.
121121
//
122122
// If and when the Issue is resolved, remove this special case match pattern:
123-
StatementKind::FakeRead(box (FakeReadCause::ForGuardBinding, _)) => None,
123+
StatementKind::FakeRead(box FakeReadCauseAndPlace(FakeReadCause::ForGuardBinding, _)) => None,
124124

125125
// Retain spans from all other statements
126-
StatementKind::FakeRead(box (_, _)) // Not including `ForGuardBinding`
126+
StatementKind::FakeRead(_) // Not including `ForGuardBinding`
127127
| StatementKind::Intrinsic(..)
128128
| StatementKind::Assign(_)
129129
| StatementKind::SetDiscriminant { .. }

compiler/rustc_mir_transform/src/remove_zsts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
113113
| StatementKind::AscribeUserType(box (place, _), _)
114114
| StatementKind::Retag(_, box place)
115115
| StatementKind::PlaceMention(box place)
116-
| StatementKind::FakeRead(box (_, place)) => Some(place),
116+
| StatementKind::FakeRead(box FakeReadCauseAndPlace(_, place)) => Some(place),
117117
StatementKind::StorageLive(local) | StatementKind::StorageDead(local) => {
118118
Some(local.into())
119119
}

src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_hir::def_id::DefId;
1212
use rustc_infer::infer::TyCtxtInferExt;
1313
use rustc_infer::traits::Obligation;
1414
use rustc_middle::mir::{
15-
Body, CastKind, NonDivergingIntrinsic, NullOp, Operand, Place, ProjectionElem, Rvalue, Statement, StatementKind,
15+
Body, CastKind, FakeReadCauseAndPlace, NonDivergingIntrinsic, NullOp, Operand, Place, ProjectionElem, Rvalue, Statement, StatementKind,
1616
Terminator, TerminatorKind,
1717
};
1818
use rustc_middle::traits::{BuiltinImplSource, ImplSource, ObligationCause};
@@ -207,7 +207,7 @@ fn check_statement<'tcx>(
207207
check_rvalue(tcx, body, def_id, rval, span)
208208
},
209209

210-
StatementKind::FakeRead(box (_, place)) => check_place(tcx, *place, span, body),
210+
StatementKind::FakeRead(box FakeReadCauseAndPlace(_, place)) => check_place(tcx, *place, span, body),
211211
// just an assignment
212212
StatementKind::SetDiscriminant { place, .. } | StatementKind::Deinit(place) => {
213213
check_place(tcx, **place, span, body)

0 commit comments

Comments
 (0)