Skip to content

Commit ee19f2c

Browse files
committed
simplify lifetime annotations for MirBorrowckCtxt
1 parent 072bae2 commit ee19f2c

File tree

1 file changed

+35
-37
lines changed

1 file changed

+35
-37
lines changed

src/librustc_mir/borrow_check.rs

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,13 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
147147
}
148148

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

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

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

185183
fn reset_to_entry_of(&mut self, bb: BasicBlock, flow_state: &mut Self::FlowState) {
186184
flow_state.each_flow(|b| b.reset_to_entry_of(bb),
@@ -431,12 +429,12 @@ enum WriteKind {
431429
Move,
432430
}
433431

434-
impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx> {
432+
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
435433
fn access_lvalue(&mut self,
436434
context: Context,
437435
lvalue_span: (&Lvalue<'tcx>, Span),
438436
kind: (ShallowOrDeep, ReadOrWrite),
439-
flow_state: &InProgress<'b, 'gcx, 'tcx>) {
437+
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
440438
// FIXME: also need to check permissions (e.g. reject mut
441439
// borrow of immutable ref, moves through non-`Box`-ref)
442440
let (sd, rw) = kind;
@@ -492,7 +490,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
492490
lvalue_span: (&Lvalue<'tcx>, Span),
493491
kind: ShallowOrDeep,
494492
mode: MutateMode,
495-
flow_state: &InProgress<'b, 'gcx, 'tcx>) {
493+
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
496494
// Write of P[i] or *P, or WriteAndRead of any P, requires P init'd.
497495
match mode {
498496
MutateMode::WriteAndRead => {
@@ -513,7 +511,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
513511
context: Context,
514512
(rvalue, span): (&Rvalue<'tcx>, Span),
515513
_location: Location,
516-
flow_state: &InProgress<'b, 'gcx, 'tcx>) {
514+
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
517515
match *rvalue {
518516
Rvalue::Ref(_/*rgn*/, bk, ref lvalue) => {
519517
let access_kind = match bk {
@@ -570,7 +568,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
570568
context: Context,
571569
consume_via_drop: ConsumeKind,
572570
(operand, span): (&Operand<'tcx>, Span),
573-
flow_state: &InProgress<'b, 'gcx, 'tcx>) {
571+
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
574572
match *operand {
575573
Operand::Consume(ref lvalue) => {
576574
self.consume_lvalue(context, consume_via_drop, (lvalue, span), flow_state)
@@ -583,7 +581,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
583581
context: Context,
584582
consume_via_drop: ConsumeKind,
585583
lvalue_span: (&Lvalue<'tcx>, Span),
586-
flow_state: &InProgress<'b, 'gcx, 'tcx>) {
584+
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
587585
let lvalue = lvalue_span.0;
588586
let ty = lvalue.ty(self.mir, self.tcx).to_ty(self.tcx);
589587
let moves_by_default =
@@ -610,11 +608,11 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
610608
}
611609
}
612610

613-
impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx> {
611+
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
614612
fn check_if_reassignment_to_immutable_state(&mut self,
615613
context: Context,
616614
(lvalue, span): (&Lvalue<'tcx>, Span),
617-
flow_state: &InProgress<'b, 'gcx, 'tcx>) {
615+
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
618616
let move_data = self.move_data;
619617

620618
// determine if this path has a non-mut owner (and thus needs checking).
@@ -665,7 +663,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
665663
context: Context,
666664
desired_action: &str,
667665
lvalue_span: (&Lvalue<'tcx>, Span),
668-
flow_state: &InProgress<'b, 'gcx, 'tcx>) {
666+
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
669667
// FIXME: analogous code in check_loans first maps `lvalue` to
670668
// its base_path ... but is that what we want here?
671669
let lvalue = self.base_path(lvalue_span.0);
@@ -788,7 +786,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
788786
fn check_if_assigned_path_is_moved(&mut self,
789787
context: Context,
790788
(lvalue, span): (&Lvalue<'tcx>, Span),
791-
flow_state: &InProgress<'b, 'gcx, 'tcx>) {
789+
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
792790
// recur down lvalue; dispatch to check_if_path_is_moved when necessary
793791
let mut lvalue = lvalue;
794792
loop {
@@ -853,11 +851,11 @@ enum NoMovePathFound {
853851
ReachedStatic,
854852
}
855853

856-
impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx> {
854+
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
857855
fn each_borrow_involving_path<F>(&mut self,
858856
_context: Context,
859857
access_lvalue: (ShallowOrDeep, &Lvalue<'tcx>),
860-
flow_state: &InProgress<'b, 'gcx, 'tcx>,
858+
flow_state: &InProgress<'cx, 'gcx, 'tcx>,
861859
mut op: F)
862860
where F: FnMut(&mut Self, BorrowIndex, &BorrowData<'tcx>, &Lvalue) -> Control
863861
{
@@ -957,11 +955,11 @@ mod prefixes {
957955
}
958956

959957

960-
pub(super) struct Prefixes<'c, 'gcx: 'tcx, 'tcx: 'c> {
961-
mir: &'c Mir<'tcx>,
962-
tcx: TyCtxt<'c, 'gcx, 'tcx>,
958+
pub(super) struct Prefixes<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
959+
mir: &'cx Mir<'tcx>,
960+
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
963961
kind: PrefixSet,
964-
next: Option<&'c Lvalue<'tcx>>,
962+
next: Option<&'cx Lvalue<'tcx>>,
965963
}
966964

967965
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
@@ -975,21 +973,21 @@ mod prefixes {
975973
Supporting,
976974
}
977975

978-
impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx> {
976+
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
979977
/// Returns an iterator over the prefixes of `lvalue`
980978
/// (inclusive) from longest to smallest, potentially
981979
/// terminating the iteration early based on `kind`.
982-
pub(super) fn prefixes<'d>(&self,
983-
lvalue: &'d Lvalue<'tcx>,
984-
kind: PrefixSet)
985-
-> Prefixes<'d, 'gcx, 'tcx> where 'b: 'd
980+
pub(super) fn prefixes(&self,
981+
lvalue: &'cx Lvalue<'tcx>,
982+
kind: PrefixSet)
983+
-> Prefixes<'cx, 'gcx, 'tcx>
986984
{
987985
Prefixes { next: Some(lvalue), kind, mir: self.mir, tcx: self.tcx }
988986
}
989987
}
990988

991-
impl<'c, 'gcx, 'tcx> Iterator for Prefixes<'c, 'gcx, 'tcx> {
992-
type Item = &'c Lvalue<'tcx>;
989+
impl<'cx, 'gcx, 'tcx> Iterator for Prefixes<'cx, 'gcx, 'tcx> {
990+
type Item = &'cx Lvalue<'tcx>;
993991
fn next(&mut self) -> Option<Self::Item> {
994992
let mut cursor = match self.next {
995993
None => return None,
@@ -1082,7 +1080,7 @@ mod prefixes {
10821080
}
10831081
}
10841082

1085-
impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx> {
1083+
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
10861084
fn report_use_of_moved(&mut self,
10871085
_context: Context,
10881086
desired_action: &str,
@@ -1203,7 +1201,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
12031201
}
12041202
}
12051203

1206-
impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx> {
1204+
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
12071205
// End-user visible description of `lvalue`
12081206
fn describe_lvalue(&self, lvalue: &Lvalue) -> String {
12091207
let mut buf = String::new();
@@ -1338,7 +1336,7 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
13381336
}
13391337
}
13401338

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

0 commit comments

Comments
 (0)