Skip to content

Commit 1c4d0ce

Browse files
committed
Separate the lifetimes of the BorrowckInferCtxt from the other borrowed items
1 parent 06c072f commit 1c4d0ce

13 files changed

+41
-39
lines changed

compiler/rustc_borrowck/src/borrowck_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_middle::span_bug;
66
use rustc_middle::ty::{self, Ty, TyCtxt};
77
use rustc_span::Span;
88

9-
impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
9+
impl<'cx, 'tcx> crate::MirBorrowckCtxt<'_, 'cx, 'tcx> {
1010
pub fn dcx(&self) -> DiagCtxtHandle<'tcx> {
1111
self.infcx.dcx()
1212
}

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<'tcx> UniverseInfo<'tcx> {
5252

5353
pub(crate) fn report_error(
5454
&self,
55-
mbcx: &mut MirBorrowckCtxt<'_, 'tcx>,
55+
mbcx: &mut MirBorrowckCtxt<'_, '_, 'tcx>,
5656
placeholder: ty::PlaceholderRegion,
5757
error_element: RegionElement,
5858
cause: ObligationCause<'tcx>,
@@ -151,7 +151,7 @@ trait TypeOpInfo<'tcx> {
151151

152152
fn nice_error(
153153
&self,
154-
mbcx: &mut MirBorrowckCtxt<'_, 'tcx>,
154+
mbcx: &mut MirBorrowckCtxt<'_, '_, 'tcx>,
155155
cause: ObligationCause<'tcx>,
156156
placeholder_region: ty::Region<'tcx>,
157157
error_region: Option<ty::Region<'tcx>>,
@@ -160,7 +160,7 @@ trait TypeOpInfo<'tcx> {
160160
#[instrument(level = "debug", skip(self, mbcx))]
161161
fn report_error(
162162
&self,
163-
mbcx: &mut MirBorrowckCtxt<'_, 'tcx>,
163+
mbcx: &mut MirBorrowckCtxt<'_, '_, 'tcx>,
164164
placeholder: ty::PlaceholderRegion,
165165
error_element: RegionElement,
166166
cause: ObligationCause<'tcx>,
@@ -233,7 +233,7 @@ impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> {
233233

234234
fn nice_error(
235235
&self,
236-
mbcx: &mut MirBorrowckCtxt<'_, 'tcx>,
236+
mbcx: &mut MirBorrowckCtxt<'_, '_, 'tcx>,
237237
cause: ObligationCause<'tcx>,
238238
placeholder_region: ty::Region<'tcx>,
239239
error_region: Option<ty::Region<'tcx>>,
@@ -270,7 +270,7 @@ where
270270

271271
fn nice_error(
272272
&self,
273-
mbcx: &mut MirBorrowckCtxt<'_, 'tcx>,
273+
mbcx: &mut MirBorrowckCtxt<'_, '_, 'tcx>,
274274
cause: ObligationCause<'tcx>,
275275
placeholder_region: ty::Region<'tcx>,
276276
error_region: Option<ty::Region<'tcx>>,
@@ -310,7 +310,7 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
310310

311311
fn nice_error(
312312
&self,
313-
mbcx: &mut MirBorrowckCtxt<'_, 'tcx>,
313+
mbcx: &mut MirBorrowckCtxt<'_, '_, 'tcx>,
314314
cause: ObligationCause<'tcx>,
315315
placeholder_region: ty::Region<'tcx>,
316316
error_region: Option<ty::Region<'tcx>>,
@@ -336,7 +336,7 @@ impl<'tcx> TypeOpInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {
336336

337337
fn nice_error(
338338
&self,
339-
mbcx: &mut MirBorrowckCtxt<'_, 'tcx>,
339+
mbcx: &mut MirBorrowckCtxt<'_, '_, 'tcx>,
340340
_cause: ObligationCause<'tcx>,
341341
placeholder_region: ty::Region<'tcx>,
342342
error_region: Option<ty::Region<'tcx>>,

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ enum StorageDeadOrDrop<'tcx> {
7373
Destructor(Ty<'tcx>),
7474
}
7575

76-
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
76+
impl<'cx, 'tcx> MirBorrowckCtxt<'_, 'cx, 'tcx> {
7777
pub(crate) fn report_use_of_moved_or_uninitialized(
7878
&mut self,
7979
location: Location,
@@ -4243,7 +4243,7 @@ enum AnnotatedBorrowFnSignature<'tcx> {
42434243
impl<'tcx> AnnotatedBorrowFnSignature<'tcx> {
42444244
/// Annotate the provided diagnostic with information about borrow from the fn signature that
42454245
/// helps explain.
4246-
pub(crate) fn emit(&self, cx: &MirBorrowckCtxt<'_, 'tcx>, diag: &mut Diag<'_>) -> String {
4246+
pub(crate) fn emit(&self, cx: &MirBorrowckCtxt<'_, '_, 'tcx>, diag: &mut Diag<'_>) -> String {
42474247
match self {
42484248
&AnnotatedBorrowFnSignature::Closure { argument_ty, argument_span } => {
42494249
diag.span_label(

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
389389
}
390390
}
391391

392-
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
392+
impl<'cx, 'tcx> MirBorrowckCtxt<'_, 'cx, 'tcx> {
393393
fn free_region_constraint_info(
394394
&self,
395395
borrow_region: RegionVid,

compiler/rustc_borrowck/src/diagnostics/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub(super) struct DescribePlaceOpt {
6969

7070
pub(super) struct IncludingTupleField(pub(super) bool);
7171

72-
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
72+
impl<'cx, 'tcx> MirBorrowckCtxt<'_, 'cx, 'tcx> {
7373
/// Adds a suggestion when a closure is invoked twice with a moved variable or when a closure
7474
/// is moved after being invoked.
7575
///
@@ -771,7 +771,7 @@ struct CapturedMessageOpt {
771771
maybe_reinitialized_locations_is_empty: bool,
772772
}
773773

774-
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
774+
impl<'cx, 'tcx> MirBorrowckCtxt<'_, 'cx, 'tcx> {
775775
/// Finds the spans associated to a move or copy of move_place at location.
776776
pub(super) fn move_spans(
777777
&self,

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ enum GroupedMoveError<'tcx> {
9393
},
9494
}
9595

96-
impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
96+
impl<'a, 'tcx> MirBorrowckCtxt<'_, 'a, 'tcx> {
9797
pub(crate) fn report_move_errors(&mut self) {
9898
let grouped_errors = self.group_move_errors();
9999
for error in grouped_errors {

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub(crate) enum AccessKind {
3030
Mutate,
3131
}
3232

33-
impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
33+
impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
3434
pub(crate) fn report_mutability_error(
3535
&mut self,
3636
access_place: Place<'tcx>,

compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl OutlivesSuggestionBuilder {
7575
/// Returns a name for the region if it is suggestable. See `region_name_is_suggestable`.
7676
fn region_vid_to_name(
7777
&self,
78-
mbcx: &MirBorrowckCtxt<'_, '_>,
78+
mbcx: &MirBorrowckCtxt<'_, '_, '_>,
7979
region: RegionVid,
8080
) -> Option<RegionName> {
8181
mbcx.give_region_a_name(region).filter(Self::region_name_is_suggestable)
@@ -84,7 +84,7 @@ impl OutlivesSuggestionBuilder {
8484
/// Compiles a list of all suggestions to be printed in the final big suggestion.
8585
fn compile_all_suggestions(
8686
&self,
87-
mbcx: &MirBorrowckCtxt<'_, '_>,
87+
mbcx: &MirBorrowckCtxt<'_, '_, '_>,
8888
) -> SmallVec<[SuggestedConstraint; 2]> {
8989
let mut suggested = SmallVec::new();
9090

@@ -160,7 +160,7 @@ impl OutlivesSuggestionBuilder {
160160
/// Emit an intermediate note on the given `Diag` if the involved regions are suggestable.
161161
pub(crate) fn intermediate_suggestion(
162162
&mut self,
163-
mbcx: &MirBorrowckCtxt<'_, '_>,
163+
mbcx: &MirBorrowckCtxt<'_, '_, '_>,
164164
errci: &ErrorConstraintInfo<'_>,
165165
diag: &mut Diag<'_>,
166166
) {
@@ -179,7 +179,7 @@ impl OutlivesSuggestionBuilder {
179179

180180
/// If there is a suggestion to emit, add a diagnostic to the buffer. This is the final
181181
/// suggestion including all collected constraints.
182-
pub(crate) fn add_suggestion(&self, mbcx: &mut MirBorrowckCtxt<'_, '_>) {
182+
pub(crate) fn add_suggestion(&self, mbcx: &mut MirBorrowckCtxt<'_, '_, '_>) {
183183
// No constraints to add? Done.
184184
if self.constraints_to_add.is_empty() {
185185
debug!("No constraints to suggest.");

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub struct ErrorConstraintInfo<'tcx> {
160160
pub(super) span: Span,
161161
}
162162

163-
impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
163+
impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
164164
/// Converts a region inference variable into a `ty::Region` that
165165
/// we can use for error reporting. If `r` is universally bound,
166166
/// then we use the name that we have on record for it. If `r` is

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl rustc_errors::IntoDiagArg for RegionName {
198198
}
199199
}
200200

201-
impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
201+
impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
202202
pub(crate) fn mir_def_id(&self) -> hir::def_id::LocalDefId {
203203
self.body.source.def_id().expect_local()
204204
}

compiler/rustc_borrowck/src/lib.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,11 @@ fn do_mir_borrowck<'tcx>(
310310
promoted_mbcx.report_move_errors();
311311
diags = promoted_mbcx.diags;
312312

313-
struct MoveVisitor<'a, 'cx, 'tcx> {
314-
ctxt: &'a mut MirBorrowckCtxt<'cx, 'tcx>,
313+
struct MoveVisitor<'a, 'b, 'cx, 'tcx> {
314+
ctxt: &'a mut MirBorrowckCtxt<'b, 'cx, 'tcx>,
315315
}
316316

317-
impl<'tcx> Visitor<'tcx> for MoveVisitor<'_, '_, 'tcx> {
317+
impl<'tcx> Visitor<'tcx> for MoveVisitor<'_, '_, '_, 'tcx> {
318318
fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) {
319319
if let Operand::Move(place) = operand {
320320
self.ctxt.check_movable_place(location, *place);
@@ -528,15 +528,15 @@ impl<'tcx> Deref for BorrowckInferCtxt<'tcx> {
528528
}
529529
}
530530

531-
struct MirBorrowckCtxt<'cx, 'tcx> {
531+
struct MirBorrowckCtxt<'a, 'cx, 'tcx> {
532532
infcx: &'cx BorrowckInferCtxt<'tcx>,
533533
param_env: ParamEnv<'tcx>,
534-
body: &'cx Body<'tcx>,
535-
move_data: &'cx MoveData<'tcx>,
534+
body: &'a Body<'tcx>,
535+
move_data: &'a MoveData<'tcx>,
536536

537537
/// Map from MIR `Location` to `LocationIndex`; created
538538
/// when MIR borrowck begins.
539-
location_table: &'cx LocationTable,
539+
location_table: &'a LocationTable,
540540

541541
movable_coroutine: bool,
542542
/// This keeps track of whether local variables are free-ed when the function
@@ -605,7 +605,9 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
605605
// 2. loans made in overlapping scopes do not conflict
606606
// 3. assignments do not affect things loaned out as immutable
607607
// 4. moves do not affect things loaned out in any way
608-
impl<'cx, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx, R> for MirBorrowckCtxt<'cx, 'tcx> {
608+
impl<'cx, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx, R>
609+
for MirBorrowckCtxt<'_, 'cx, 'tcx>
610+
{
609611
type FlowState = Flows<'cx, 'tcx>;
610612

611613
fn visit_statement_before_primary_effect(
@@ -969,8 +971,8 @@ impl InitializationRequiringAction {
969971
}
970972
}
971973

972-
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
973-
fn body(&self) -> &'cx Body<'tcx> {
974+
impl<'a, 'cx, 'tcx> MirBorrowckCtxt<'a, 'cx, 'tcx> {
975+
fn body(&self) -> &'a Body<'tcx> {
974976
self.body
975977
}
976978

@@ -2002,7 +2004,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
20022004
}
20032005

20042006
fn check_parent_of_field<'cx, 'tcx>(
2005-
this: &mut MirBorrowckCtxt<'cx, 'tcx>,
2007+
this: &mut MirBorrowckCtxt<'_, 'cx, 'tcx>,
20062008
location: Location,
20072009
base: PlaceRef<'tcx>,
20082010
span: Span,
@@ -2476,7 +2478,7 @@ mod diags {
24762478
}
24772479
}
24782480

2479-
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
2481+
impl<'cx, 'tcx> MirBorrowckCtxt<'_, 'cx, 'tcx> {
24802482
pub fn buffer_error(&mut self, diag: Diag<'tcx>) {
24812483
self.diags.buffer_error(diag);
24822484
}

compiler/rustc_borrowck/src/prefixes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub(super) enum PrefixSet {
3434
Shallow,
3535
}
3636

37-
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
37+
impl<'cx, 'tcx> MirBorrowckCtxt<'_, 'cx, 'tcx> {
3838
/// Returns an iterator over the prefixes of `place`
3939
/// (inclusive) from longest to smallest, potentially
4040
/// terminating the iteration early based on `kind`.

compiler/rustc_borrowck/src/used_muts.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_middle::mir::{
66

77
use crate::MirBorrowckCtxt;
88

9-
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
9+
impl<'cx, 'tcx> MirBorrowckCtxt<'_, 'cx, 'tcx> {
1010
/// Walks the MIR adding to the set of `used_mut` locals that will be ignored for the purposes
1111
/// of the `unused_mut` lint.
1212
///
@@ -45,13 +45,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
4545

4646
/// MIR visitor for collecting used mutable variables.
4747
/// The 'visit lifetime represents the duration of the MIR walk.
48-
struct GatherUsedMutsVisitor<'visit, 'cx, 'tcx> {
48+
struct GatherUsedMutsVisitor<'visit, 'a, 'cx, 'tcx> {
4949
temporary_used_locals: FxIndexSet<Local>,
5050
never_initialized_mut_locals: &'visit mut FxIndexSet<Local>,
51-
mbcx: &'visit mut MirBorrowckCtxt<'cx, 'tcx>,
51+
mbcx: &'visit mut MirBorrowckCtxt<'a, 'cx, 'tcx>,
5252
}
5353

54-
impl GatherUsedMutsVisitor<'_, '_, '_> {
54+
impl GatherUsedMutsVisitor<'_, '_, '_, '_> {
5555
fn remove_never_initialized_mut_locals(&mut self, into: Place<'_>) {
5656
// Remove any locals that we found were initialized from the
5757
// `never_initialized_mut_locals` set. At the end, the only remaining locals will
@@ -63,7 +63,7 @@ impl GatherUsedMutsVisitor<'_, '_, '_> {
6363
}
6464
}
6565

66-
impl<'visit, 'cx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'cx, 'tcx> {
66+
impl<'visit, 'cx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, '_, 'cx, 'tcx> {
6767
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
6868
debug!("visit_terminator: terminator={:?}", terminator);
6969
match &terminator.kind {

0 commit comments

Comments
 (0)