Skip to content

Commit 8607cb4

Browse files
committed
Remove unnecessary lifetimes in borrowck structs.
Similar to the previous commit, this commit merges two lifetimes in `Borrows`. This then lets lifetimes be removed from `BorrowckResults` and `BorrowckFlowState`.
1 parent d6400c0 commit 8607cb4

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,24 @@ use tracing::debug;
1515
use crate::{places_conflict, BorrowSet, PlaceConflictBias, PlaceExt, RegionInferenceContext};
1616

1717
/// The results of the dataflow analyses used by the borrow checker.
18-
pub(crate) struct BorrowckResults<'a, 'mir, 'tcx> {
19-
pub(crate) borrows: Results<'tcx, Borrows<'a, 'mir, 'tcx>>,
18+
pub(crate) struct BorrowckResults<'mir, 'tcx> {
19+
pub(crate) borrows: Results<'tcx, Borrows<'mir, 'tcx>>,
2020
pub(crate) uninits: Results<'tcx, MaybeUninitializedPlaces<'mir, 'tcx>>,
2121
pub(crate) ever_inits: Results<'tcx, EverInitializedPlaces<'mir, 'tcx>>,
2222
}
2323

2424
/// The transient state of the dataflow analyses used by the borrow checker.
2525
#[derive(Debug)]
26-
pub(crate) struct BorrowckFlowState<'a, 'mir, 'tcx> {
27-
pub(crate) borrows: <Borrows<'a, 'mir, 'tcx> as AnalysisDomain<'tcx>>::Domain,
26+
pub(crate) struct BorrowckFlowState<'mir, 'tcx> {
27+
pub(crate) borrows: <Borrows<'mir, 'tcx> as AnalysisDomain<'tcx>>::Domain,
2828
pub(crate) uninits: <MaybeUninitializedPlaces<'mir, 'tcx> as AnalysisDomain<'tcx>>::Domain,
2929
pub(crate) ever_inits: <EverInitializedPlaces<'mir, 'tcx> as AnalysisDomain<'tcx>>::Domain,
3030
}
3131

32-
impl<'a, 'mir, 'tcx> ResultsVisitable<'tcx> for BorrowckResults<'a, 'mir, 'tcx> {
32+
impl<'mir, 'tcx> ResultsVisitable<'tcx> for BorrowckResults<'mir, 'tcx> {
3333
// All three analyses are forward, but we have to use just one here.
34-
type Direction = <Borrows<'a, 'mir, 'tcx> as AnalysisDomain<'tcx>>::Direction;
35-
type FlowState = BorrowckFlowState<'a, 'mir, 'tcx>;
34+
type Direction = <Borrows<'mir, 'tcx> as AnalysisDomain<'tcx>>::Direction;
35+
type FlowState = BorrowckFlowState<'mir, 'tcx>;
3636

3737
fn new_flow_state(&self, body: &mir::Body<'tcx>) -> Self::FlowState {
3838
BorrowckFlowState {
@@ -106,11 +106,11 @@ rustc_index::newtype_index! {
106106
/// `BorrowIndex`, and maps each such index to a `BorrowData`
107107
/// describing the borrow. These indexes are used for representing the
108108
/// borrows in compact bitvectors.
109-
pub struct Borrows<'a, 'mir, 'tcx> {
109+
pub struct Borrows<'mir, 'tcx> {
110110
tcx: TyCtxt<'tcx>,
111111
body: &'mir Body<'tcx>,
112112

113-
borrow_set: &'a BorrowSet<'tcx>,
113+
borrow_set: &'mir BorrowSet<'tcx>,
114114
borrows_out_of_scope_at_location: FxIndexMap<Location, Vec<BorrowIndex>>,
115115
}
116116

@@ -389,12 +389,12 @@ impl<'tcx> PoloniusOutOfScopePrecomputer<'_, 'tcx> {
389389
}
390390
}
391391

392-
impl<'a, 'mir, 'tcx> Borrows<'a, 'mir, 'tcx> {
392+
impl<'mir, 'tcx> Borrows<'mir, 'tcx> {
393393
pub fn new(
394394
tcx: TyCtxt<'tcx>,
395395
body: &'mir Body<'tcx>,
396396
regioncx: &RegionInferenceContext<'tcx>,
397-
borrow_set: &'a BorrowSet<'tcx>,
397+
borrow_set: &'mir BorrowSet<'tcx>,
398398
) -> Self {
399399
let mut borrows_out_of_scope_at_location =
400400
calculate_borrows_out_of_scope_at_location(body, regioncx, borrow_set);
@@ -494,7 +494,7 @@ impl<'a, 'mir, 'tcx> Borrows<'a, 'mir, 'tcx> {
494494
}
495495
}
496496

497-
impl<'tcx> rustc_mir_dataflow::AnalysisDomain<'tcx> for Borrows<'_, '_, 'tcx> {
497+
impl<'tcx> rustc_mir_dataflow::AnalysisDomain<'tcx> for Borrows<'_, 'tcx> {
498498
type Domain = BitSet<BorrowIndex>;
499499

500500
const NAME: &'static str = "borrows";
@@ -517,7 +517,7 @@ impl<'tcx> rustc_mir_dataflow::AnalysisDomain<'tcx> for Borrows<'_, '_, 'tcx> {
517517
/// region stops containing the CFG points reachable from the issuing location.
518518
/// - we also kill loans of conflicting places when overwriting a shared path: e.g. borrows of
519519
/// `a.b.c` when `a` is overwritten.
520-
impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, '_, 'tcx> {
520+
impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
521521
type Idx = BorrowIndex;
522522

523523
fn domain_size(&self, _: &mir::Body<'tcx>) -> usize {
@@ -617,8 +617,8 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, '_, 'tcx> {
617617
}
618618
}
619619

620-
impl DebugWithContext<Borrows<'_, '_, '_>> for BorrowIndex {
621-
fn fmt_with(&self, ctxt: &Borrows<'_, '_, '_>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
620+
impl DebugWithContext<Borrows<'_, '_>> for BorrowIndex {
621+
fn fmt_with(&self, ctxt: &Borrows<'_, '_>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
622622
write!(f, "{:?}", ctxt.location(*self))
623623
}
624624
}

compiler/rustc_borrowck/src/lib.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -602,12 +602,12 @@ struct MirBorrowckCtxt<'a, 'mir, 'infcx, 'tcx> {
602602
impl<'a, 'mir, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'mir, 'tcx, R>
603603
for MirBorrowckCtxt<'a, 'mir, '_, 'tcx>
604604
{
605-
type FlowState = Flows<'a, 'mir, 'tcx>;
605+
type FlowState = Flows<'mir, 'tcx>;
606606

607607
fn visit_statement_before_primary_effect(
608608
&mut self,
609609
_results: &mut R,
610-
flow_state: &Flows<'_, 'mir, 'tcx>,
610+
flow_state: &Flows<'mir, 'tcx>,
611611
stmt: &'mir Statement<'tcx>,
612612
location: Location,
613613
) {
@@ -677,7 +677,7 @@ impl<'a, 'mir, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'mir, 'tcx, R>
677677
fn visit_terminator_before_primary_effect(
678678
&mut self,
679679
_results: &mut R,
680-
flow_state: &Flows<'_, 'mir, 'tcx>,
680+
flow_state: &Flows<'mir, 'tcx>,
681681
term: &'mir Terminator<'tcx>,
682682
loc: Location,
683683
) {
@@ -794,7 +794,7 @@ impl<'a, 'mir, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'mir, 'tcx, R>
794794
fn visit_terminator_after_primary_effect(
795795
&mut self,
796796
_results: &mut R,
797-
flow_state: &Flows<'_, 'mir, 'tcx>,
797+
flow_state: &Flows<'mir, 'tcx>,
798798
term: &'mir Terminator<'tcx>,
799799
loc: Location,
800800
) {
@@ -989,7 +989,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
989989
place_span: (Place<'tcx>, Span),
990990
kind: (AccessDepth, ReadOrWrite),
991991
is_local_mutation_allowed: LocalMutationIsAllowed,
992-
flow_state: &Flows<'_, 'mir, 'tcx>,
992+
flow_state: &Flows<'mir, 'tcx>,
993993
) {
994994
let (sd, rw) = kind;
995995

@@ -1039,7 +1039,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
10391039
place_span: (Place<'tcx>, Span),
10401040
sd: AccessDepth,
10411041
rw: ReadOrWrite,
1042-
flow_state: &Flows<'_, 'mir, 'tcx>,
1042+
flow_state: &Flows<'mir, 'tcx>,
10431043
) -> bool {
10441044
let mut error_reported = false;
10451045
let borrow_set = Rc::clone(&self.borrow_set);
@@ -1180,7 +1180,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
11801180
location: Location,
11811181
place_span: (Place<'tcx>, Span),
11821182
kind: AccessDepth,
1183-
flow_state: &Flows<'_, 'mir, 'tcx>,
1183+
flow_state: &Flows<'mir, 'tcx>,
11841184
) {
11851185
// Write of P[i] or *P requires P init'd.
11861186
self.check_if_assigned_path_is_moved(location, place_span, flow_state);
@@ -1198,7 +1198,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
11981198
&mut self,
11991199
location: Location,
12001200
(rvalue, span): (&'mir Rvalue<'tcx>, Span),
1201-
flow_state: &Flows<'_, 'mir, 'tcx>,
1201+
flow_state: &Flows<'mir, 'tcx>,
12021202
) {
12031203
match rvalue {
12041204
&Rvalue::Ref(_ /*rgn*/, bk, place) => {
@@ -1456,7 +1456,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
14561456
&mut self,
14571457
location: Location,
14581458
(operand, span): (&'mir Operand<'tcx>, Span),
1459-
flow_state: &Flows<'_, 'mir, 'tcx>,
1459+
flow_state: &Flows<'mir, 'tcx>,
14601460
) {
14611461
match *operand {
14621462
Operand::Copy(place) => {
@@ -1580,7 +1580,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
15801580
&mut self,
15811581
location: Location,
15821582
span: Span,
1583-
flow_state: &Flows<'_, 'mir, 'tcx>,
1583+
flow_state: &Flows<'mir, 'tcx>,
15841584
) {
15851585
// Two-phase borrow support: For each activation that is newly
15861586
// generated at this statement, check if it interferes with
@@ -1744,7 +1744,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
17441744
location: Location,
17451745
desired_action: InitializationRequiringAction,
17461746
place_span: (PlaceRef<'tcx>, Span),
1747-
flow_state: &Flows<'_, 'mir, 'tcx>,
1747+
flow_state: &Flows<'mir, 'tcx>,
17481748
) {
17491749
let maybe_uninits = &flow_state.uninits;
17501750

@@ -1849,7 +1849,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
18491849
location: Location,
18501850
desired_action: InitializationRequiringAction,
18511851
place_span: (PlaceRef<'tcx>, Span),
1852-
flow_state: &Flows<'_, 'mir, 'tcx>,
1852+
flow_state: &Flows<'mir, 'tcx>,
18531853
) {
18541854
let maybe_uninits = &flow_state.uninits;
18551855

@@ -1948,7 +1948,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
19481948
&mut self,
19491949
location: Location,
19501950
(place, span): (Place<'tcx>, Span),
1951-
flow_state: &Flows<'_, 'mir, 'tcx>,
1951+
flow_state: &Flows<'mir, 'tcx>,
19521952
) {
19531953
debug!("check_if_assigned_path_is_moved place: {:?}", place);
19541954

@@ -2014,7 +2014,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
20142014
location: Location,
20152015
base: PlaceRef<'tcx>,
20162016
span: Span,
2017-
flow_state: &Flows<'_, 'mir, 'tcx>,
2017+
flow_state: &Flows<'mir, 'tcx>,
20182018
) {
20192019
// rust-lang/rust#21232: Until Rust allows reads from the
20202020
// initialized parts of partially initialized structs, we
@@ -2105,7 +2105,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
21052105
(place, span): (Place<'tcx>, Span),
21062106
kind: ReadOrWrite,
21072107
is_local_mutation_allowed: LocalMutationIsAllowed,
2108-
flow_state: &Flows<'_, 'mir, 'tcx>,
2108+
flow_state: &Flows<'mir, 'tcx>,
21092109
location: Location,
21102110
) -> bool {
21112111
debug!(
@@ -2221,15 +2221,15 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
22212221
fn is_local_ever_initialized(
22222222
&self,
22232223
local: Local,
2224-
flow_state: &Flows<'_, 'mir, 'tcx>,
2224+
flow_state: &Flows<'mir, 'tcx>,
22252225
) -> Option<InitIndex> {
22262226
let mpi = self.move_data.rev_lookup.find_local(local)?;
22272227
let ii = &self.move_data.init_path_map[mpi];
22282228
ii.into_iter().find(|&&index| flow_state.ever_inits.contains(index)).copied()
22292229
}
22302230

22312231
/// Adds the place into the used mutable variables set
2232-
fn add_used_mut(&mut self, root_place: RootPlace<'tcx>, flow_state: &Flows<'_, 'mir, 'tcx>) {
2232+
fn add_used_mut(&mut self, root_place: RootPlace<'tcx>, flow_state: &Flows<'mir, 'tcx>) {
22332233
match root_place {
22342234
RootPlace { place_local: local, place_projection: [], is_local_mutation_allowed } => {
22352235
// If the local may have been initialized, and it is now currently being

0 commit comments

Comments
 (0)