Skip to content

Commit 4cf1117

Browse files
committed
simplify lifetime annotations for MirBorrowckCtxt
1 parent 0aef9ba commit 4cf1117

File tree

1 file changed

+35
-37
lines changed

1 file changed

+35
-37
lines changed

src/librustc_mir/borrow_check.rs

+35-37
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
148148
}
149149

150150
#[allow(dead_code)]
151-
pub struct MirBorrowckCtxt<'c, 'b, 'a: 'b+'c, 'gcx: 'a+'tcx, 'tcx: 'a> {
152-
tcx: TyCtxt<'a, 'gcx, 'tcx>,
153-
mir: &'b Mir<'tcx>,
151+
pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
152+
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
153+
mir: &'cx Mir<'tcx>,
154154
node_id: ast::NodeId,
155-
move_data: &'b MoveData<'tcx>,
156-
param_env: ParamEnv<'tcx>,
157-
fake_infer_ctxt: &'c InferCtxt<'c, 'gcx, 'tcx>,
155+
move_data: &'cx MoveData<'tcx>,
156+
param_env: ParamEnv<'gcx>,
157+
fake_infer_ctxt: &'cx InferCtxt<'cx, 'gcx, 'tcx>,
158158
}
159159

160160
// (forced to be `pub` due to its use as an associated type below.)
@@ -177,12 +177,10 @@ struct FlowInProgress<BD> where BD: BitDenotation {
177177
// 2. loans made in overlapping scopes do not conflict
178178
// 3. assignments do not affect things loaned out as immutable
179179
// 4. moves do not affect things loaned out in any way
180-
impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> DataflowResultsConsumer<'b, 'tcx>
181-
for MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
182-
{
183-
type FlowState = InProgress<'b, 'gcx, 'tcx>;
180+
impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
181+
type FlowState = InProgress<'cx, 'gcx, 'tcx>;
184182

185-
fn mir(&self) -> &'b Mir<'tcx> { self.mir }
183+
fn mir(&self) -> &'cx Mir<'tcx> { self.mir }
186184

187185
fn reset_to_entry_of(&mut self, bb: BasicBlock, flow_state: &mut Self::FlowState) {
188186
flow_state.each_flow(|b| b.reset_to_entry_of(bb),
@@ -437,12 +435,12 @@ enum WriteKind {
437435
Move,
438436
}
439437

440-
impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx> {
438+
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
441439
fn access_lvalue(&mut self,
442440
context: Context,
443441
lvalue_span: (&Lvalue<'tcx>, Span),
444442
kind: (ShallowOrDeep, ReadOrWrite),
445-
flow_state: &InProgress<'b, 'gcx, 'tcx>) {
443+
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
446444

447445
let (sd, rw) = kind;
448446

@@ -501,7 +499,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
501499
lvalue_span: (&Lvalue<'tcx>, Span),
502500
kind: ShallowOrDeep,
503501
mode: MutateMode,
504-
flow_state: &InProgress<'b, 'gcx, 'tcx>) {
502+
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
505503
// Write of P[i] or *P, or WriteAndRead of any P, requires P init'd.
506504
match mode {
507505
MutateMode::WriteAndRead => {
@@ -522,7 +520,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
522520
context: Context,
523521
(rvalue, span): (&Rvalue<'tcx>, Span),
524522
_location: Location,
525-
flow_state: &InProgress<'b, 'gcx, 'tcx>) {
523+
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
526524
match *rvalue {
527525
Rvalue::Ref(_/*rgn*/, bk, ref lvalue) => {
528526
let access_kind = match bk {
@@ -579,7 +577,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
579577
context: Context,
580578
consume_via_drop: ConsumeKind,
581579
(operand, span): (&Operand<'tcx>, Span),
582-
flow_state: &InProgress<'b, 'gcx, 'tcx>) {
580+
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
583581
match *operand {
584582
Operand::Consume(ref lvalue) => {
585583
self.consume_lvalue(context, consume_via_drop, (lvalue, span), flow_state)
@@ -592,7 +590,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
592590
context: Context,
593591
consume_via_drop: ConsumeKind,
594592
lvalue_span: (&Lvalue<'tcx>, Span),
595-
flow_state: &InProgress<'b, 'gcx, 'tcx>) {
593+
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
596594
let lvalue = lvalue_span.0;
597595
let ty = lvalue.ty(self.mir, self.tcx).to_ty(self.tcx);
598596
let moves_by_default =
@@ -619,11 +617,11 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
619617
}
620618
}
621619

622-
impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx> {
620+
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
623621
fn check_if_reassignment_to_immutable_state(&mut self,
624622
context: Context,
625623
(lvalue, span): (&Lvalue<'tcx>, Span),
626-
flow_state: &InProgress<'b, 'gcx, 'tcx>) {
624+
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
627625
let move_data = self.move_data;
628626

629627
// determine if this path has a non-mut owner (and thus needs checking).
@@ -674,7 +672,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
674672
context: Context,
675673
desired_action: &str,
676674
lvalue_span: (&Lvalue<'tcx>, Span),
677-
flow_state: &InProgress<'b, 'gcx, 'tcx>) {
675+
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
678676
// FIXME: analogous code in check_loans first maps `lvalue` to
679677
// its base_path ... but is that what we want here?
680678
let lvalue = self.base_path(lvalue_span.0);
@@ -802,7 +800,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
802800
fn check_if_assigned_path_is_moved(&mut self,
803801
context: Context,
804802
(lvalue, span): (&Lvalue<'tcx>, Span),
805-
flow_state: &InProgress<'b, 'gcx, 'tcx>) {
803+
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
806804
// recur down lvalue; dispatch to check_if_path_is_moved when necessary
807805
let mut lvalue = lvalue;
808806
loop {
@@ -1015,11 +1013,11 @@ enum NoMovePathFound {
10151013
ReachedStatic,
10161014
}
10171015

1018-
impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx> {
1016+
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
10191017
fn each_borrow_involving_path<F>(&mut self,
10201018
_context: Context,
10211019
access_lvalue: (ShallowOrDeep, &Lvalue<'tcx>),
1022-
flow_state: &InProgress<'b, 'gcx, 'tcx>,
1020+
flow_state: &InProgress<'cx, 'gcx, 'tcx>,
10231021
mut op: F)
10241022
where F: FnMut(&mut Self, BorrowIndex, &BorrowData<'tcx>, &Lvalue) -> Control
10251023
{
@@ -1119,11 +1117,11 @@ mod prefixes {
11191117
}
11201118

11211119

1122-
pub(super) struct Prefixes<'c, 'gcx: 'tcx, 'tcx: 'c> {
1123-
mir: &'c Mir<'tcx>,
1124-
tcx: TyCtxt<'c, 'gcx, 'tcx>,
1120+
pub(super) struct Prefixes<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
1121+
mir: &'cx Mir<'tcx>,
1122+
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
11251123
kind: PrefixSet,
1126-
next: Option<&'c Lvalue<'tcx>>,
1124+
next: Option<&'cx Lvalue<'tcx>>,
11271125
}
11281126

11291127
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
@@ -1137,21 +1135,21 @@ mod prefixes {
11371135
Supporting,
11381136
}
11391137

1140-
impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx> {
1138+
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
11411139
/// Returns an iterator over the prefixes of `lvalue`
11421140
/// (inclusive) from longest to smallest, potentially
11431141
/// terminating the iteration early based on `kind`.
1144-
pub(super) fn prefixes<'d>(&self,
1145-
lvalue: &'d Lvalue<'tcx>,
1146-
kind: PrefixSet)
1147-
-> Prefixes<'d, 'gcx, 'tcx> where 'b: 'd
1142+
pub(super) fn prefixes(&self,
1143+
lvalue: &'cx Lvalue<'tcx>,
1144+
kind: PrefixSet)
1145+
-> Prefixes<'cx, 'gcx, 'tcx>
11481146
{
11491147
Prefixes { next: Some(lvalue), kind, mir: self.mir, tcx: self.tcx }
11501148
}
11511149
}
11521150

1153-
impl<'c, 'gcx, 'tcx> Iterator for Prefixes<'c, 'gcx, 'tcx> {
1154-
type Item = &'c Lvalue<'tcx>;
1151+
impl<'cx, 'gcx, 'tcx> Iterator for Prefixes<'cx, 'gcx, 'tcx> {
1152+
type Item = &'cx Lvalue<'tcx>;
11551153
fn next(&mut self) -> Option<Self::Item> {
11561154
let mut cursor = match self.next {
11571155
None => return None,
@@ -1244,7 +1242,7 @@ mod prefixes {
12441242
}
12451243
}
12461244

1247-
impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx> {
1245+
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
12481246
fn report_use_of_moved_or_uninitialized(&mut self,
12491247
_context: Context,
12501248
desired_action: &str,
@@ -1481,7 +1479,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
14811479
}
14821480
}
14831481

1484-
impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx> {
1482+
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
14851483
// End-user visible description of `lvalue`
14861484
fn describe_lvalue(&self, lvalue: &Lvalue) -> String {
14871485
let mut buf = String::new();
@@ -1616,7 +1614,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
16161614
}
16171615
}
16181616

1619-
impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx> {
1617+
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
16201618
// FIXME (#16118): function intended to allow the borrow checker
16211619
// to be less precise in its handling of Box while still allowing
16221620
// moves out of a Box. They should be removed when/if we stop

0 commit comments

Comments
 (0)