Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ca87b53

Browse files
committedNov 4, 2024
Auto merge of #132250 - nnethercote:rustc_borrowck-cleanups, r=compiler-errors
`rustc_borrowck` cleanups A bunch of cleanups I made while reading over this crate. r? `@lqd`
2 parents 56c6a2f + e0e7a43 commit ca87b53

File tree

22 files changed

+251
-385
lines changed

22 files changed

+251
-385
lines changed
 

‎compiler/rustc_borrowck/src/borrow_set.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ pub struct BorrowSet<'tcx> {
2020
/// by the `Location` of the assignment statement in which it
2121
/// appears on the right hand side. Thus the location is the map
2222
/// key, and its position in the map corresponds to `BorrowIndex`.
23-
pub location_map: FxIndexMap<Location, BorrowData<'tcx>>,
23+
pub(crate) location_map: FxIndexMap<Location, BorrowData<'tcx>>,
2424

2525
/// Locations which activate borrows.
2626
/// NOTE: a given location may activate more than one borrow in the future
2727
/// when more general two-phase borrow support is introduced, but for now we
2828
/// only need to store one borrow index.
29-
pub activation_map: FxIndexMap<Location, Vec<BorrowIndex>>,
29+
pub(crate) activation_map: FxIndexMap<Location, Vec<BorrowIndex>>,
3030

3131
/// Map from local to all the borrows on that local.
32-
pub local_map: FxIndexMap<mir::Local, FxIndexSet<BorrowIndex>>,
32+
pub(crate) local_map: FxIndexMap<mir::Local, FxIndexSet<BorrowIndex>>,
3333

34-
pub locals_state_at_exit: LocalsStateAtExit,
34+
pub(crate) locals_state_at_exit: LocalsStateAtExit,
3535
}
3636

3737
impl<'tcx> Index<BorrowIndex> for BorrowSet<'tcx> {
@@ -45,7 +45,7 @@ impl<'tcx> Index<BorrowIndex> for BorrowSet<'tcx> {
4545
/// Location where a two-phase borrow is activated, if a borrow
4646
/// is in fact a two-phase borrow.
4747
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
48-
pub enum TwoPhaseActivation {
48+
pub(crate) enum TwoPhaseActivation {
4949
NotTwoPhase,
5050
NotActivated,
5151
ActivatedAt(Location),
@@ -55,17 +55,17 @@ pub enum TwoPhaseActivation {
5555
pub struct BorrowData<'tcx> {
5656
/// Location where the borrow reservation starts.
5757
/// In many cases, this will be equal to the activation location but not always.
58-
pub reserve_location: Location,
58+
pub(crate) reserve_location: Location,
5959
/// Location where the borrow is activated.
60-
pub activation_location: TwoPhaseActivation,
60+
pub(crate) activation_location: TwoPhaseActivation,
6161
/// What kind of borrow this is
62-
pub kind: mir::BorrowKind,
62+
pub(crate) kind: mir::BorrowKind,
6363
/// The region for which this borrow is live
64-
pub region: RegionVid,
64+
pub(crate) region: RegionVid,
6565
/// Place from which we are borrowing
66-
pub borrowed_place: mir::Place<'tcx>,
66+
pub(crate) borrowed_place: mir::Place<'tcx>,
6767
/// Place to which the borrow was stored
68-
pub assigned_place: mir::Place<'tcx>,
68+
pub(crate) assigned_place: mir::Place<'tcx>,
6969
}
7070

7171
impl<'tcx> fmt::Display for BorrowData<'tcx> {
@@ -120,7 +120,7 @@ impl LocalsStateAtExit {
120120
}
121121

122122
impl<'tcx> BorrowSet<'tcx> {
123-
pub fn build(
123+
pub(crate) fn build(
124124
tcx: TyCtxt<'tcx>,
125125
body: &Body<'tcx>,
126126
locals_are_invalidated_at_exit: bool,
@@ -156,7 +156,7 @@ impl<'tcx> BorrowSet<'tcx> {
156156
self.activation_map.get(&location).map_or(&[], |activations| &activations[..])
157157
}
158158

159-
pub fn len(&self) -> usize {
159+
pub(crate) fn len(&self) -> usize {
160160
self.location_map.len()
161161
}
162162

‎compiler/rustc_borrowck/src/constraints/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl<'tcx> fmt::Debug for OutlivesConstraint<'tcx> {
210210

211211
rustc_index::newtype_index! {
212212
#[debug_format = "OutlivesConstraintIndex({})"]
213-
pub struct OutlivesConstraintIndex {}
213+
pub(crate) struct OutlivesConstraintIndex {}
214214
}
215215

216216
rustc_index::newtype_index! {

‎compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ impl<'tcx> PoloniusOutOfScopePrecomputer<'_, 'tcx> {
254254
let sccs = self.regioncx.constraint_sccs();
255255
let universal_regions = self.regioncx.universal_regions();
256256

257-
// We first handle the cases where the loan doesn't go out of scope, depending on the issuing
258-
// region's successors.
257+
// We first handle the cases where the loan doesn't go out of scope, depending on the
258+
// issuing region's successors.
259259
for successor in graph::depth_first_search(&self.regioncx.region_graph(), issuing_region) {
260260
// 1. Via applied member constraints
261261
//

‎compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::rc::Rc;
33

44
use rustc_errors::Diag;
55
use rustc_hir::def_id::LocalDefId;
6-
use rustc_infer::infer::canonical::CanonicalQueryInput;
76
use rustc_infer::infer::region_constraints::{Constraint, RegionConstraintData};
87
use rustc_infer::infer::{
98
InferCtxt, RegionResolutionError, RegionVariableOrigin, SubregionOrigin, TyCtxtInferExt as _,
@@ -21,7 +20,6 @@ use rustc_span::Span;
2120
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
2221
use rustc_trait_selection::error_reporting::infer::nice_region_error::NiceRegionError;
2322
use rustc_trait_selection::traits::ObligationCtxt;
24-
use rustc_trait_selection::traits::query::type_op;
2523
use rustc_traits::{type_op_ascribe_user_type_with_span, type_op_prove_predicate_with_cause};
2624
use tracing::{debug, instrument};
2725

@@ -31,12 +29,9 @@ use crate::session_diagnostics::{
3129
HigherRankedErrorCause, HigherRankedLifetimeError, HigherRankedSubtypeError,
3230
};
3331

34-
#[derive(Clone)]
35-
pub(crate) struct UniverseInfo<'tcx>(UniverseInfoInner<'tcx>);
36-
3732
/// What operation a universe was created for.
3833
#[derive(Clone)]
39-
enum UniverseInfoInner<'tcx> {
34+
pub(crate) enum UniverseInfo<'tcx> {
4035
/// Relating two types which have binders.
4136
RelateTys { expected: Ty<'tcx>, found: Ty<'tcx> },
4237
/// Created from performing a `TypeOp`.
@@ -47,11 +42,11 @@ enum UniverseInfoInner<'tcx> {
4742

4843
impl<'tcx> UniverseInfo<'tcx> {
4944
pub(crate) fn other() -> UniverseInfo<'tcx> {
50-
UniverseInfo(UniverseInfoInner::Other)
45+
UniverseInfo::Other
5146
}
5247

5348
pub(crate) fn relate(expected: Ty<'tcx>, found: Ty<'tcx>) -> UniverseInfo<'tcx> {
54-
UniverseInfo(UniverseInfoInner::RelateTys { expected, found })
49+
UniverseInfo::RelateTys { expected, found }
5550
}
5651

5752
pub(crate) fn report_error(
@@ -61,8 +56,8 @@ impl<'tcx> UniverseInfo<'tcx> {
6156
error_element: RegionElement,
6257
cause: ObligationCause<'tcx>,
6358
) {
64-
match self.0 {
65-
UniverseInfoInner::RelateTys { expected, found } => {
59+
match *self {
60+
UniverseInfo::RelateTys { expected, found } => {
6661
let err = mbcx.infcx.err_ctxt().report_mismatched_types(
6762
&cause,
6863
mbcx.param_env,
@@ -72,10 +67,10 @@ impl<'tcx> UniverseInfo<'tcx> {
7267
);
7368
mbcx.buffer_error(err);
7469
}
75-
UniverseInfoInner::TypeOp(ref type_op_info) => {
70+
UniverseInfo::TypeOp(ref type_op_info) => {
7671
type_op_info.report_error(mbcx, placeholder, error_element, cause);
7772
}
78-
UniverseInfoInner::Other => {
73+
UniverseInfo::Other => {
7974
// FIXME: This error message isn't great, but it doesn't show
8075
// up in the existing UI tests. Consider investigating this
8176
// some more.
@@ -93,46 +88,30 @@ pub(crate) trait ToUniverseInfo<'tcx> {
9388

9489
impl<'tcx> ToUniverseInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {
9590
fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
96-
UniverseInfo(UniverseInfoInner::TypeOp(Rc::new(crate::type_check::InstantiateOpaqueType {
91+
UniverseInfo::TypeOp(Rc::new(crate::type_check::InstantiateOpaqueType {
9792
base_universe: Some(base_universe),
9893
..self
99-
})))
94+
}))
10095
}
10196
}
10297

10398
impl<'tcx> ToUniverseInfo<'tcx> for CanonicalTypeOpProvePredicateGoal<'tcx> {
10499
fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
105-
UniverseInfo(UniverseInfoInner::TypeOp(Rc::new(PredicateQuery {
106-
canonical_query: self,
107-
base_universe,
108-
})))
100+
UniverseInfo::TypeOp(Rc::new(PredicateQuery { canonical_query: self, base_universe }))
109101
}
110102
}
111103

112104
impl<'tcx, T: Copy + fmt::Display + TypeFoldable<TyCtxt<'tcx>> + 'tcx> ToUniverseInfo<'tcx>
113105
for CanonicalTypeOpNormalizeGoal<'tcx, T>
114106
{
115107
fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
116-
UniverseInfo(UniverseInfoInner::TypeOp(Rc::new(NormalizeQuery {
117-
canonical_query: self,
118-
base_universe,
119-
})))
108+
UniverseInfo::TypeOp(Rc::new(NormalizeQuery { canonical_query: self, base_universe }))
120109
}
121110
}
122111

123112
impl<'tcx> ToUniverseInfo<'tcx> for CanonicalTypeOpAscribeUserTypeGoal<'tcx> {
124113
fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
125-
UniverseInfo(UniverseInfoInner::TypeOp(Rc::new(AscribeUserTypeQuery {
126-
canonical_query: self,
127-
base_universe,
128-
})))
129-
}
130-
}
131-
132-
impl<'tcx, F> ToUniverseInfo<'tcx> for CanonicalQueryInput<'tcx, type_op::custom::CustomTypeOp<F>> {
133-
fn to_universe_info(self, _base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
134-
// We can't rerun custom type ops.
135-
UniverseInfo::other()
114+
UniverseInfo::TypeOp(Rc::new(AscribeUserTypeQuery { canonical_query: self, base_universe }))
136115
}
137116
}
138117

@@ -143,7 +122,7 @@ impl<'tcx> ToUniverseInfo<'tcx> for ! {
143122
}
144123

145124
#[allow(unused_lifetimes)]
146-
trait TypeOpInfo<'tcx> {
125+
pub(crate) trait TypeOpInfo<'tcx> {
147126
/// Returns an error to be reported if rerunning the type op fails to
148127
/// recover the error's cause.
149128
fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> Diag<'tcx>;
@@ -289,8 +268,8 @@ where
289268
// `rustc_traits::type_op::type_op_normalize` query to allow the span we need in the
290269
// `ObligationCause`. The normalization results are currently different between
291270
// `QueryNormalizeExt::query_normalize` used in the query and `normalize` called below:
292-
// the former fails to normalize the `nll/relate_tys/impl-fn-ignore-binder-via-bottom.rs` test.
293-
// Check after #85499 lands to see if its fixes have erased this difference.
271+
// the former fails to normalize the `nll/relate_tys/impl-fn-ignore-binder-via-bottom.rs`
272+
// test. Check after #85499 lands to see if its fixes have erased this difference.
294273
let (param_env, value) = key.into_parts();
295274
let _ = ocx.normalize(&cause, param_env, value.value);
296275

‎compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,11 +1345,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
13451345
// See `tests/ui/moves/needs-clone-through-deref.rs`
13461346
return false;
13471347
}
1348-
// We don't want to suggest `.clone()` in a move closure, since the value has already been captured.
1348+
// We don't want to suggest `.clone()` in a move closure, since the value has already been
1349+
// captured.
13491350
if self.in_move_closure(expr) {
13501351
return false;
13511352
}
1352-
// We also don't want to suggest cloning a closure itself, since the value has already been captured.
1353+
// We also don't want to suggest cloning a closure itself, since the value has already been
1354+
// captured.
13531355
if let hir::ExprKind::Closure(_) = expr.kind {
13541356
return false;
13551357
}
@@ -1381,7 +1383,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
13811383
}
13821384
}
13831385
}
1384-
// Cloning the raw pointer doesn't make sense in some cases and would cause a type mismatch error. (see #126863)
1386+
// Cloning the raw pointer doesn't make sense in some cases and would cause a type mismatch
1387+
// error. (see #126863)
13851388
if inner_expr.span.lo() != expr.span.lo() && !is_raw_ptr {
13861389
// Remove "(*" or "(&"
13871390
sugg.push((expr.span.with_hi(inner_expr.span.lo()), String::new()));
@@ -1553,8 +1556,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
15531556
let use_spans = self.move_spans(place.as_ref(), location);
15541557
let span = use_spans.var_or_use();
15551558

1556-
// If the attempted use is in a closure then we do not care about the path span of the place we are currently trying to use
1557-
// we call `var_span_label` on `borrow_spans` to annotate if the existing borrow was in a closure
1559+
// If the attempted use is in a closure then we do not care about the path span of the
1560+
// place we are currently trying to use we call `var_span_label` on `borrow_spans` to
1561+
// annotate if the existing borrow was in a closure.
15581562
let mut err = self.cannot_use_when_mutably_borrowed(
15591563
span,
15601564
&self.describe_any_place(place.as_ref()),
@@ -2480,7 +2484,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
24802484
if let hir::ExprKind::Closure(closure) = ex.kind
24812485
&& ex.span.contains(self.borrow_span)
24822486
// To support cases like `|| { v.call(|this| v.get()) }`
2483-
// FIXME: actually support such cases (need to figure out how to move from the capture place to original local)
2487+
// FIXME: actually support such cases (need to figure out how to move from the
2488+
// capture place to original local).
24842489
&& self.res.as_ref().map_or(true, |(prev_res, _)| prev_res.span.contains(ex.span))
24852490
{
24862491
self.res = Some((ex, closure));
@@ -2733,7 +2738,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
27332738
/// cannot borrow `a.u` (via `a.u.z.c`) as immutable because it is also borrowed as
27342739
/// mutable (via `a.u.s.b`) [E0502]
27352740
/// ```
2736-
pub(crate) fn describe_place_for_conflicting_borrow(
2741+
fn describe_place_for_conflicting_borrow(
27372742
&self,
27382743
first_borrowed_place: Place<'tcx>,
27392744
second_borrowed_place: Place<'tcx>,
@@ -3188,8 +3193,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
31883193
/// misleading users in cases like `tests/ui/nll/borrowed-temporary-error.rs`.
31893194
/// We could expand the analysis to suggest hoising all of the relevant parts of
31903195
/// the users' code to make the code compile, but that could be too much.
3191-
/// We found the `prop_expr` by the way to check whether the expression is a `FormatArguments`,
3192-
/// which is a special case since it's generated by the compiler.
3196+
/// We found the `prop_expr` by the way to check whether the expression is a
3197+
/// `FormatArguments`, which is a special case since it's generated by the
3198+
/// compiler.
31933199
struct NestedStatementVisitor<'tcx> {
31943200
span: Span,
31953201
current: usize,
@@ -3420,7 +3426,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
34203426
let (sugg_span, suggestion) = match tcx.sess.source_map().span_to_snippet(args_span) {
34213427
Ok(string) => {
34223428
let coro_prefix = if string.starts_with("async") {
3423-
// `async` is 5 chars long. Not using `.len()` to avoid the cast from `usize` to `u32`
3429+
// `async` is 5 chars long. Not using `.len()` to avoid the cast from `usize`
3430+
// to `u32`.
34243431
Some(5)
34253432
} else if string.starts_with("gen") {
34263433
// `gen` is 3 chars long
@@ -3618,10 +3625,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
36183625
let stmt_kind =
36193626
self.body[location.block].statements.get(location.statement_index).map(|s| &s.kind);
36203627
if let Some(StatementKind::StorageDead(..)) = stmt_kind {
3621-
// this analysis only tries to find moves explicitly
3622-
// written by the user, so we ignore the move-outs
3623-
// created by `StorageDead` and at the beginning
3624-
// of a function.
3628+
// This analysis only tries to find moves explicitly written by the user, so we
3629+
// ignore the move-outs created by `StorageDead` and at the beginning of a
3630+
// function.
36253631
} else {
36263632
// If we are found a use of a.b.c which was in error, then we want to look for
36273633
// moves not only of a.b.c but also a.b and a.
@@ -3706,13 +3712,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
37063712
}
37073713
}
37083714
if (is_argument || !reached_start) && result.is_empty() {
3709-
/* Process back edges (moves in future loop iterations) only if
3710-
the move path is definitely initialized upon loop entry,
3711-
to avoid spurious "in previous iteration" errors.
3712-
During DFS, if there's a path from the error back to the start
3713-
of the function with no intervening init or move, then the
3714-
move path may be uninitialized at loop entry.
3715-
*/
3715+
// Process back edges (moves in future loop iterations) only if
3716+
// the move path is definitely initialized upon loop entry,
3717+
// to avoid spurious "in previous iteration" errors.
3718+
// During DFS, if there's a path from the error back to the start
3719+
// of the function with no intervening init or move, then the
3720+
// move path may be uninitialized at loop entry.
37163721
while let Some(location) = back_edge_stack.pop() {
37173722
if dfs_iter(&mut result, location, true) {
37183723
continue;

‎compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ impl<'tcx> BorrowExplanation<'tcx> {
130130
{
131131
suggest_rewrite_if_let(tcx, expr, &pat, init, conseq, alt, err);
132132
} else if path_span.map_or(true, |path_span| path_span == var_or_use_span) {
133-
// We can use `var_or_use_span` if either `path_span` is not present, or both spans are the same
133+
// We can use `var_or_use_span` if either `path_span` is not present, or both
134+
// spans are the same.
134135
if borrow_span.map_or(true, |sp| !sp.overlaps(var_or_use_span)) {
135136
err.span_label(
136137
var_or_use_span,
@@ -165,7 +166,8 @@ impl<'tcx> BorrowExplanation<'tcx> {
165166
LaterUseKind::FakeLetRead => "borrow later stored here",
166167
LaterUseKind::Other => "borrow used here, in later iteration of loop",
167168
};
168-
// We can use `var_or_use_span` if either `path_span` is not present, or both spans are the same
169+
// We can use `var_or_use_span` if either `path_span` is not present, or both spans
170+
// are the same.
169171
if path_span.map(|path_span| path_span == var_or_use_span).unwrap_or(true) {
170172
err.span_label(var_or_use_span, format!("{borrow_desc}{message}"));
171173
} else {
@@ -285,7 +287,8 @@ impl<'tcx> BorrowExplanation<'tcx> {
285287
span: _,
286288
pat,
287289
init,
288-
// FIXME(#101728): enable rewrite when type ascription is stabilized again
290+
// FIXME(#101728): enable rewrite when type ascription is
291+
// stabilized again.
289292
ty: None,
290293
recovered: _,
291294
}) = cond.kind
@@ -353,8 +356,8 @@ impl<'tcx> BorrowExplanation<'tcx> {
353356
unsize_ty: Ty<'tcx>,
354357
) {
355358
if let ty::Adt(def, args) = unsize_ty.kind() {
356-
// We try to elaborate the object lifetime defaults and present those to the user. This should
357-
// make it clear where the region constraint is coming from.
359+
// We try to elaborate the object lifetime defaults and present those to the user. This
360+
// should make it clear where the region constraint is coming from.
358361
let generics = tcx.generics_of(def.did());
359362

360363
let mut has_dyn = false;
@@ -531,9 +534,10 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
531534
let mut use_in_later_iteration_of_loop = false;
532535

533536
if region_sub == borrow_region_vid {
534-
// When `region_sub` is the same as `borrow_region_vid` (the location where the borrow is
535-
// issued is the same location that invalidates the reference), this is likely a loop iteration
536-
// - in this case, try using the loop terminator location in `find_sub_region_live_at`.
537+
// When `region_sub` is the same as `borrow_region_vid` (the location where the borrow
538+
// is issued is the same location that invalidates the reference), this is likely a
539+
// loop iteration. In this case, try using the loop terminator location in
540+
// `find_sub_region_live_at`.
537541
if let Some(loop_terminator_location) =
538542
regioncx.find_loop_terminator_location(borrow.region, body)
539543
{

‎compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ impl<'tcx> BorrowedContentSource<'tcx> {
763763
}
764764
}
765765

766-
///helper struct for explain_captures()
766+
/// Helper struct for `explain_captures`.
767767
struct CapturedMessageOpt {
768768
is_partial_move: bool,
769769
is_loop_message: bool,

‎compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
793793
let reason = if let PlaceBase::Upvar(upvar_id) = closure_kind_origin.base {
794794
let upvar = ty::place_to_string_for_capture(tcx, closure_kind_origin);
795795
let root_hir_id = upvar_id.var_path.hir_id;
796-
// we have an origin for this closure kind starting at this root variable so it's safe to unwrap here
796+
// We have an origin for this closure kind starting at this root variable so it's
797+
// safe to unwrap here.
797798
let captured_places =
798799
tables.closure_min_captures[&closure_local_def_id].get(&root_hir_id).unwrap();
799800

@@ -966,8 +967,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
966967
}
967968
};
968969

969-
// If we can detect the expression to be an function or method call where the closure was an argument,
970-
// we point at the function or method definition argument...
970+
// If we can detect the expression to be an function or method call where the closure was
971+
// an argument, we point at the function or method definition argument...
971972
if let Some((callee_def_id, call_span, call_args)) = get_call_details() {
972973
let arg_pos = call_args
973974
.iter()

‎compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ pub(crate) struct RegionName {
3030
}
3131

3232
/// Denotes the source of a region that is named by a `RegionName`. For example, a free region that
33-
/// was named by the user would get `NamedLateParamRegion` and `'static` lifetime would get `Static`.
34-
/// This helps to print the right kinds of diagnostics.
33+
/// was named by the user would get `NamedLateParamRegion` and `'static` lifetime would get
34+
/// `Static`. This helps to print the right kinds of diagnostics.
3535
#[derive(Debug, Clone, Copy)]
3636
pub(crate) enum RegionNameSource {
3737
/// A bound (not free) region that was instantiated at the def site (not an HRTB).
@@ -825,8 +825,8 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
825825
/// async fn foo() -> i32 { 2 }
826826
/// ```
827827
///
828-
/// this function, given the lowered return type of `foo`, an [`OpaqueDef`] that implements `Future<Output=i32>`,
829-
/// returns the `i32`.
828+
/// this function, given the lowered return type of `foo`, an [`OpaqueDef`] that implements
829+
/// `Future<Output=i32>`, returns the `i32`.
830830
///
831831
/// [`OpaqueDef`]: hir::TyKind::OpaqueDef
832832
fn get_future_inner_return_ty(&self, hir_ty: &'tcx hir::Ty<'tcx>) -> &'tcx hir::Ty<'tcx> {

‎compiler/rustc_borrowck/src/lib.rs

Lines changed: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use std::collections::BTreeMap;
2020
use std::marker::PhantomData;
2121
use std::ops::Deref;
2222

23-
use consumers::{BodyWithBorrowckFacts, ConsumerOptions};
2423
use rustc_abi::FieldIdx;
2524
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
2625
use rustc_data_structures::graph::dominators::Dominators;
@@ -49,13 +48,21 @@ use rustc_span::{Span, Symbol};
4948
use smallvec::SmallVec;
5049
use tracing::{debug, instrument};
5150

52-
use self::diagnostics::{AccessKind, IllegalMoveOriginKind, MoveError, RegionName};
53-
use self::location::LocationTable;
54-
use self::path_utils::*;
55-
use self::prefixes::PrefixSet;
51+
use crate::borrow_set::{BorrowData, BorrowSet};
52+
use crate::consumers::{BodyWithBorrowckFacts, ConsumerOptions};
53+
use crate::dataflow::{BorrowIndex, BorrowckDomain, BorrowckResults, Borrows};
54+
use crate::diagnostics::{AccessKind, IllegalMoveOriginKind, MoveError, RegionName};
55+
use crate::location::LocationTable;
56+
use crate::nll::PoloniusOutput;
57+
use crate::path_utils::*;
58+
use crate::place_ext::PlaceExt;
59+
use crate::places_conflict::{PlaceConflictBias, places_conflict};
60+
use crate::prefixes::PrefixSet;
61+
use crate::region_infer::RegionInferenceContext;
62+
use crate::renumber::RegionCtxt;
5663
use crate::session_diagnostics::VarNeedNotMut;
5764

58-
pub mod borrow_set;
65+
mod borrow_set;
5966
mod borrowck_errors;
6067
mod constraints;
6168
mod dataflow;
@@ -81,18 +88,11 @@ mod util;
8188
/// A public API provided for the Rust compiler consumers.
8289
pub mod consumers;
8390

84-
use borrow_set::{BorrowData, BorrowSet};
85-
use dataflow::{BorrowIndex, BorrowckDomain, BorrowckResults, Borrows};
86-
use nll::PoloniusOutput;
87-
use place_ext::PlaceExt;
88-
use places_conflict::{PlaceConflictBias, places_conflict};
89-
use region_infer::RegionInferenceContext;
90-
use renumber::RegionCtxt;
91-
9291
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
9392

9493
/// Associate some local constants with the `'tcx` lifetime
9594
struct TyCtxtConsts<'tcx>(PhantomData<&'tcx ()>);
95+
9696
impl<'tcx> TyCtxtConsts<'tcx> {
9797
const DEREF_PROJECTION: &'tcx [PlaceElem<'tcx>; 1] = &[ProjectionElem::Deref];
9898
}
@@ -162,7 +162,7 @@ fn do_mir_borrowck<'tcx>(
162162
}
163163
}
164164

165-
let mut diags = diags::BorrowckDiags::new();
165+
let diags = &mut diags::BorrowckDiags::new();
166166

167167
// Gather the upvars of a closure, if any.
168168
if let Some(e) = input_body.tainted_by_errors {
@@ -227,14 +227,7 @@ fn do_mir_borrowck<'tcx>(
227227

228228
// We also have a `#[rustc_regions]` annotation that causes us to dump
229229
// information.
230-
nll::dump_annotation(
231-
&infcx,
232-
body,
233-
&regioncx,
234-
&opt_closure_req,
235-
&opaque_type_values,
236-
&mut diags,
237-
);
230+
nll::dump_annotation(&infcx, body, &regioncx, &opt_closure_req, &opaque_type_values, diags);
238231

239232
// The various `flow_*` structures can be large. We drop `flow_inits` here
240233
// so it doesn't overlap with the others below. This reduces peak memory
@@ -299,7 +292,6 @@ fn do_mir_borrowck<'tcx>(
299292
};
300293
MoveVisitor { ctxt: &mut promoted_mbcx }.visit_body(promoted_body);
301294
promoted_mbcx.report_move_errors();
302-
diags = promoted_mbcx.diags;
303295

304296
struct MoveVisitor<'a, 'b, 'infcx, 'tcx> {
305297
ctxt: &'a mut MirBorrowckCtxt<'b, 'infcx, 'tcx>,
@@ -434,7 +426,7 @@ fn do_mir_borrowck<'tcx>(
434426
(result, body_with_facts)
435427
}
436428

437-
pub struct BorrowckInferCtxt<'tcx> {
429+
pub(crate) struct BorrowckInferCtxt<'tcx> {
438430
pub(crate) infcx: InferCtxt<'tcx>,
439431
pub(crate) reg_var_to_origin: RefCell<FxIndexMap<ty::RegionVid, RegionCtxt>>,
440432
}
@@ -587,7 +579,7 @@ struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
587579
/// Results of Polonius analysis.
588580
polonius_output: Option<Box<PoloniusOutput>>,
589581

590-
diags: diags::BorrowckDiags<'infcx, 'tcx>,
582+
diags: &'a mut diags::BorrowckDiags<'infcx, 'tcx>,
591583
move_errors: Vec<MoveError<'tcx>>,
592584
}
593585

@@ -638,7 +630,9 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
638630
);
639631
}
640632
StatementKind::Intrinsic(box kind) => match kind {
641-
NonDivergingIntrinsic::Assume(op) => self.consume_operand(location, (op, span), state),
633+
NonDivergingIntrinsic::Assume(op) => {
634+
self.consume_operand(location, (op, span), state);
635+
}
642636
NonDivergingIntrinsic::CopyNonOverlapping(..) => span_bug!(
643637
span,
644638
"Unexpected CopyNonOverlapping, should only appear after lower_intrinsics",
@@ -2105,7 +2099,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
21052099
| Write(WriteKind::MutableBorrow(BorrowKind::Mut { kind: mut_borrow_kind })) => {
21062100
let is_local_mutation_allowed = match mut_borrow_kind {
21072101
// `ClosureCapture` is used for mutable variable with an immutable binding.
2108-
// This is only behaviour difference between `ClosureCapture` and mutable borrows.
2102+
// This is only behaviour difference between `ClosureCapture` and mutable
2103+
// borrows.
21092104
MutBorrowKind::ClosureCapture => LocalMutationIsAllowed::Yes,
21102105
MutBorrowKind::Default | MutBorrowKind::TwoPhaseBorrow => {
21112106
is_local_mutation_allowed
@@ -2350,23 +2345,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
23502345
) => Err(place),
23512346
(Mutability::Not, LocalMutationIsAllowed::Yes)
23522347
| (Mutability::Mut, _) => {
2353-
// Subtle: this is an upvar
2354-
// reference, so it looks like
2355-
// `self.foo` -- we want to double
2356-
// check that the location `*self`
2357-
// is mutable (i.e., this is not a
2358-
// `Fn` closure). But if that
2359-
// check succeeds, we want to
2360-
// *blame* the mutability on
2361-
// `place` (that is,
2362-
// `self.foo`). This is used to
2363-
// propagate the info about
2364-
// whether mutability declarations
2365-
// are used outwards, so that we register
2366-
// the outer variable as mutable. Otherwise a
2367-
// test like this fails to record the `mut`
2368-
// as needed:
2369-
//
2348+
// Subtle: this is an upvar reference, so it looks like
2349+
// `self.foo` -- we want to double check that the location
2350+
// `*self` is mutable (i.e., this is not a `Fn` closure). But
2351+
// if that check succeeds, we want to *blame* the mutability on
2352+
// `place` (that is, `self.foo`). This is used to propagate the
2353+
// info about whether mutability declarations are used
2354+
// outwards, so that we register the outer variable as mutable.
2355+
// Otherwise a test like this fails to record the `mut` as
2356+
// needed:
23702357
// ```
23712358
// fn foo<F: FnOnce()>(_f: F) { }
23722359
// fn main() {
@@ -2511,15 +2498,15 @@ mod diags {
25112498
// Buffer any move errors that we collected and de-duplicated.
25122499
for (_, (_, diag)) in std::mem::take(&mut self.diags.buffered_move_errors) {
25132500
// We have already set tainted for this error, so just buffer it.
2514-
self.diags.buffered_diags.push(BufferedDiag::Error(diag));
2501+
self.diags.buffer_error(diag);
25152502
}
25162503
for (_, (mut diag, count)) in std::mem::take(&mut self.diags.buffered_mut_errors) {
25172504
if count > 10 {
25182505
#[allow(rustc::diagnostic_outside_of_impl)]
25192506
#[allow(rustc::untranslatable_diagnostic)]
25202507
diag.note(format!("...and {} other attempted mutable borrows", count - 10));
25212508
}
2522-
self.diags.buffered_diags.push(BufferedDiag::Error(diag));
2509+
self.diags.buffer_error(diag);
25232510
}
25242511

25252512
if !self.diags.buffered_diags.is_empty() {

‎compiler/rustc_borrowck/src/prefixes.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'tcx> Iterator for Prefixes<'tcx> {
5353
// may hold one further down (e.g., we never return
5454
// downcasts here, but may return a base of a downcast).
5555

56-
'cursor: loop {
56+
loop {
5757
match cursor.last_projection() {
5858
None => {
5959
self.next = None;
@@ -72,7 +72,6 @@ impl<'tcx> Iterator for Prefixes<'tcx> {
7272
| ProjectionElem::ConstantIndex { .. }
7373
| ProjectionElem::Index(_) => {
7474
cursor = cursor_base;
75-
continue 'cursor;
7675
}
7776
ProjectionElem::Subtype(..) => {
7877
panic!("Subtype projection is not allowed before borrow check")

‎compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ impl RegionTracker {
9999
pub(crate) fn new(rvid: RegionVid, definition: &RegionDefinition<'_>) -> Self {
100100
let (representative_is_placeholder, representative_is_existential) = match definition.origin
101101
{
102-
rustc_infer::infer::NllRegionVariableOrigin::FreeRegion => (false, false),
103-
rustc_infer::infer::NllRegionVariableOrigin::Placeholder(_) => (true, false),
104-
rustc_infer::infer::NllRegionVariableOrigin::Existential { .. } => (false, true),
102+
NllRegionVariableOrigin::FreeRegion => (false, false),
103+
NllRegionVariableOrigin::Placeholder(_) => (true, false),
104+
NllRegionVariableOrigin::Existential { .. } => (false, true),
105105
};
106106

107107
let placeholder_universe =
@@ -553,20 +553,22 @@ impl<'tcx> RegionInferenceContext<'tcx> {
553553
}
554554

555555
/// Returns an iterator over all the region indices.
556-
pub fn regions(&self) -> impl Iterator<Item = RegionVid> + 'tcx {
556+
pub(crate) fn regions(&self) -> impl Iterator<Item = RegionVid> + 'tcx {
557557
self.definitions.indices()
558558
}
559559

560560
/// Given a universal region in scope on the MIR, returns the
561561
/// corresponding index.
562562
///
563563
/// (Panics if `r` is not a registered universal region.)
564-
pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
564+
pub(crate) fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
565565
self.universal_regions.to_region_vid(r)
566566
}
567567

568568
/// Returns an iterator over all the outlives constraints.
569-
pub fn outlives_constraints(&self) -> impl Iterator<Item = OutlivesConstraint<'tcx>> + '_ {
569+
pub(crate) fn outlives_constraints(
570+
&self,
571+
) -> impl Iterator<Item = OutlivesConstraint<'tcx>> + '_ {
570572
self.constraints.outlives().iter().copied()
571573
}
572574

@@ -1495,6 +1497,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
14951497
fn scc_universe(&self, scc: ConstraintSccIndex) -> UniverseIndex {
14961498
self.constraint_sccs().annotation(scc).min_universe()
14971499
}
1500+
14981501
/// Checks the final value for the free region `fr` to see if it
14991502
/// grew too large. In particular, examine what `end(X)` points
15001503
/// wound up in `fr`'s final value; for each `end(X)` where `X !=
@@ -1667,7 +1670,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
16671670
placeholder,
16681671
});
16691672

1670-
// Stop after the first error, it gets too noisy otherwise, and does not provide more information.
1673+
// Stop after the first error, it gets too noisy otherwise, and does not provide more
1674+
// information.
16711675
break;
16721676
}
16731677
debug!("check_bound_universal_region: all bounds satisfied");
@@ -2000,8 +2004,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20002004

20012005
// We try to avoid reporting a `ConstraintCategory::Predicate` as our best constraint.
20022006
// Instead, we use it to produce an improved `ObligationCauseCode`.
2003-
// FIXME - determine what we should do if we encounter multiple `ConstraintCategory::Predicate`
2004-
// constraints. Currently, we just pick the first one.
2007+
// FIXME - determine what we should do if we encounter multiple
2008+
// `ConstraintCategory::Predicate` constraints. Currently, we just pick the first one.
20052009
let cause_code = path
20062010
.iter()
20072011
.find_map(|constraint| {

‎compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
145145
continue;
146146
}
147147
// Sometimes two opaque types are the same only after we remap the generic parameters
148-
// back to the opaque type definition. E.g. we may have `OpaqueType<X, Y>` mapped to `(X, Y)`
149-
// and `OpaqueType<Y, X>` mapped to `(Y, X)`, and those are the same, but we only know that
150-
// once we convert the generic parameters to those of the opaque type.
148+
// back to the opaque type definition. E.g. we may have `OpaqueType<X, Y>` mapped to
149+
// `(X, Y)` and `OpaqueType<Y, X>` mapped to `(Y, X)`, and those are the same, but we
150+
// only know that once we convert the generic parameters to those of the opaque type.
151151
if let Some(prev) = result.get_mut(&opaque_type_key.def_id) {
152152
if prev.ty != ty {
153153
let guar = ty.error_reported().err().unwrap_or_else(|| {

‎compiler/rustc_borrowck/src/region_infer/values.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::BorrowIndex;
1515
rustc_index::newtype_index! {
1616
/// A single integer representing a `ty::Placeholder`.
1717
#[debug_format = "PlaceholderIndex({})"]
18-
pub struct PlaceholderIndex {}
18+
pub(crate) struct PlaceholderIndex {}
1919
}
2020

2121
/// An individual element in a region value -- the value of a

‎compiler/rustc_borrowck/src/type_check/canonical.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
6262
{
6363
let universe_info = error_info.to_universe_info(old_universe);
6464
for u in (old_universe + 1)..=universe {
65-
self.borrowck_context.constraints.universe_causes.insert(u, universe_info.clone());
65+
self.constraints.universe_causes.insert(u, universe_info.clone());
6666
}
6767
}
6868

‎compiler/rustc_borrowck/src/type_check/input_output.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
4848
// FIXME(async_closures): It's kind of wacky that we must apply this
4949
// transformation here, since we do the same thing in HIR typeck.
5050
// Maybe we could just fix up the canonicalized signature during HIR typeck?
51-
if let DefiningTy::CoroutineClosure(_, args) =
52-
self.borrowck_context.universal_regions.defining_ty
53-
{
51+
if let DefiningTy::CoroutineClosure(_, args) = self.universal_regions.defining_ty {
5452
assert_matches!(
5553
self.tcx().coroutine_kind(self.tcx().coroutine_for_closure(mir_def_id)),
5654
Some(hir::CoroutineKind::Desugared(
@@ -59,8 +57,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
5957
)),
6058
"this needs to be modified if we're lowering non-async closures"
6159
);
62-
// Make sure to use the args from `DefiningTy` so the right NLL region vids are prepopulated
63-
// into the type.
60+
// Make sure to use the args from `DefiningTy` so the right NLL region vids are
61+
// prepopulated into the type.
6462
let args = args.as_coroutine_closure();
6563
let tupled_upvars_ty = ty::CoroutineClosureSignature::tupled_upvars_by_closure_kind(
6664
self.tcx(),
@@ -195,8 +193,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
195193
// doing so ends up causing some other trouble.
196194
let b = self.normalize(b, Locations::All(span));
197195

198-
// Note: if we have to introduce new placeholders during normalization above, then we won't have
199-
// added those universes to the universe info, which we would want in `relate_tys`.
196+
// Note: if we have to introduce new placeholders during normalization above, then we
197+
// won't have added those universes to the universe info, which we would want in
198+
// `relate_tys`.
200199
if let Err(terr) =
201200
self.eq_types(a, b, Locations::All(span), ConstraintCategory::BoringNoLocation)
202201
{

‎compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs

Lines changed: 14 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -137,56 +137,22 @@ struct LocalUseMapBuild<'me> {
137137
locals_with_use_data: IndexVec<Local, bool>,
138138
}
139139

140-
impl LocalUseMapBuild<'_> {
141-
fn insert_def(&mut self, local: Local, location: Location) {
142-
Self::insert(
143-
self.elements,
144-
&mut self.local_use_map.first_def_at[local],
145-
&mut self.local_use_map.appearances,
146-
location,
147-
);
148-
}
149-
150-
fn insert_use(&mut self, local: Local, location: Location) {
151-
Self::insert(
152-
self.elements,
153-
&mut self.local_use_map.first_use_at[local],
154-
&mut self.local_use_map.appearances,
155-
location,
156-
);
157-
}
158-
159-
fn insert_drop(&mut self, local: Local, location: Location) {
160-
Self::insert(
161-
self.elements,
162-
&mut self.local_use_map.first_drop_at[local],
163-
&mut self.local_use_map.appearances,
164-
location,
165-
);
166-
}
167-
168-
fn insert(
169-
elements: &DenseLocationMap,
170-
first_appearance: &mut Option<AppearanceIndex>,
171-
appearances: &mut Appearances,
172-
location: Location,
173-
) {
174-
let point_index = elements.point_from_location(location);
175-
let appearance_index =
176-
appearances.push(Appearance { point_index, next: *first_appearance });
177-
*first_appearance = Some(appearance_index);
178-
}
179-
}
180-
181140
impl Visitor<'_> for LocalUseMapBuild<'_> {
182141
fn visit_local(&mut self, local: Local, context: PlaceContext, location: Location) {
183-
if self.locals_with_use_data[local] {
184-
match def_use::categorize(context) {
185-
Some(DefUse::Def) => self.insert_def(local, location),
186-
Some(DefUse::Use) => self.insert_use(local, location),
187-
Some(DefUse::Drop) => self.insert_drop(local, location),
188-
_ => (),
189-
}
142+
if self.locals_with_use_data[local]
143+
&& let Some(def_use) = def_use::categorize(context)
144+
{
145+
let first_appearance = match def_use {
146+
DefUse::Def => &mut self.local_use_map.first_def_at[local],
147+
DefUse::Use => &mut self.local_use_map.first_use_at[local],
148+
DefUse::Drop => &mut self.local_use_map.first_drop_at[local],
149+
};
150+
let point_index = self.elements.point_from_location(location);
151+
let appearance_index = self
152+
.local_use_map
153+
.appearances
154+
.push(Appearance { point_index, next: *first_appearance });
155+
*first_appearance = Some(appearance_index);
190156
}
191157
}
192158
}

‎compiler/rustc_borrowck/src/type_check/liveness/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ pub(super) fn generate<'a, 'tcx>(
3939

4040
let free_regions = regions_that_outlive_free_regions(
4141
typeck.infcx.num_region_vars(),
42-
typeck.borrowck_context.universal_regions,
43-
&typeck.borrowck_context.constraints.outlives_constraints,
42+
typeck.universal_regions,
43+
&typeck.constraints.outlives_constraints,
4444
);
4545
let (relevant_live_locals, boring_locals) =
4646
compute_relevant_live_locals(typeck.tcx(), &free_regions, body);
@@ -59,11 +59,7 @@ pub(super) fn generate<'a, 'tcx>(
5959

6060
// Mark regions that should be live where they appear within rvalues or within a call: like
6161
// args, regions, and types.
62-
record_regular_live_regions(
63-
typeck.tcx(),
64-
&mut typeck.borrowck_context.constraints.liveness_constraints,
65-
body,
66-
);
62+
record_regular_live_regions(typeck.tcx(), &mut typeck.constraints.liveness_constraints, body);
6763
}
6864

6965
// The purpose of `compute_relevant_live_locals` is to define the subset of `Local`

‎compiler/rustc_borrowck/src/type_check/liveness/polonius.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ pub(super) fn populate_access_facts<'a, 'tcx>(
8888
body: &Body<'tcx>,
8989
move_data: &MoveData<'tcx>,
9090
) {
91-
if let Some(facts) = typeck.borrowck_context.all_facts.as_mut() {
91+
if let Some(facts) = typeck.all_facts.as_mut() {
9292
debug!("populate_access_facts()");
93-
let location_table = typeck.borrowck_context.location_table;
93+
let location_table = typeck.location_table;
9494

9595
let mut extractor = UseFactsExtractor {
9696
var_defined_at: &mut facts.var_defined_at,
@@ -108,7 +108,7 @@ pub(super) fn populate_access_facts<'a, 'tcx>(
108108
local, local_decl.ty
109109
);
110110
let _prof_timer = typeck.infcx.tcx.prof.generic_activity("polonius_fact_generation");
111-
let universal_regions = &typeck.borrowck_context.universal_regions;
111+
let universal_regions = &typeck.universal_regions;
112112
typeck.infcx.tcx.for_each_free_region(&local_decl.ty, |region| {
113113
let region_vid = universal_regions.to_region_vid(region);
114114
facts.use_of_var_derefs_origin.push((local, region_vid.into()));
@@ -125,9 +125,9 @@ pub(super) fn add_drop_of_var_derefs_origin<'tcx>(
125125
kind: &GenericArg<'tcx>,
126126
) {
127127
debug!("add_drop_of_var_derefs_origin(local={:?}, kind={:?}", local, kind);
128-
if let Some(facts) = typeck.borrowck_context.all_facts.as_mut() {
128+
if let Some(facts) = typeck.all_facts.as_mut() {
129129
let _prof_timer = typeck.infcx.tcx.prof.generic_activity("polonius_fact_generation");
130-
let universal_regions = &typeck.borrowck_context.universal_regions;
130+
let universal_regions = &typeck.universal_regions;
131131
typeck.infcx.tcx.for_each_free_region(kind, |drop_live_region| {
132132
let region_vid = universal_regions.to_region_vid(drop_live_region);
133133
facts.drop_of_var_derefs_origin.push((local, region_vid.into()));

‎compiler/rustc_borrowck/src/type_check/liveness/trace.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,12 @@ pub(super) fn trace<'a, 'tcx>(
4747

4848
// When using `-Zpolonius=next`, compute the set of loans that can reach a given region.
4949
if typeck.tcx().sess.opts.unstable_opts.polonius.is_next_enabled() {
50-
let borrowck_context = &mut typeck.borrowck_context;
51-
let borrow_set = &borrowck_context.borrow_set;
50+
let borrow_set = &typeck.borrow_set;
5251
let mut live_loans = LiveLoans::new(borrow_set.len());
53-
let outlives_constraints = &borrowck_context.constraints.outlives_constraints;
52+
let outlives_constraints = &typeck.constraints.outlives_constraints;
5453
let graph = outlives_constraints.graph(typeck.infcx.num_region_vars());
5554
let region_graph =
56-
graph.region_graph(outlives_constraints, borrowck_context.universal_regions.fr_static);
55+
graph.region_graph(outlives_constraints, typeck.universal_regions.fr_static);
5756

5857
// Traverse each issuing region's constraints, and record the loan as flowing into the
5958
// outlived region.
@@ -73,7 +72,7 @@ pub(super) fn trace<'a, 'tcx>(
7372

7473
// Store the inflowing loans in the liveness constraints: they will be used to compute live
7574
// loans when liveness data is recorded there.
76-
borrowck_context.constraints.liveness_constraints.loans = Some(live_loans);
75+
typeck.constraints.liveness_constraints.loans = Some(live_loans);
7776
};
7877

7978
let cx = LivenessContext {
@@ -222,7 +221,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
222221
// It may be necessary to just pick out the parts of
223222
// `add_drop_live_facts_for()` that make sense.
224223
let facts_to_add: Vec<_> = {
225-
let drop_used = &self.cx.typeck.borrowck_context.all_facts.as_ref()?.var_dropped_at;
224+
let drop_used = &self.cx.typeck.all_facts.as_ref()?.var_dropped_at;
226225

227226
let relevant_live_locals: FxIndexSet<_> =
228227
relevant_live_locals.iter().copied().collect();
@@ -235,12 +234,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
235234
return None;
236235
}
237236

238-
let location = match self
239-
.cx
240-
.typeck
241-
.borrowck_context
242-
.location_table
243-
.to_location(*location_index)
237+
let location = match self.cx.typeck.location_table.to_location(*location_index)
244238
{
245239
RichLocation::Start(l) => l,
246240
RichLocation::Mid(l) => l,
@@ -251,7 +245,8 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
251245
.collect()
252246
};
253247

254-
// FIXME: these locations seem to have a special meaning (e.g. everywhere, at the end, ...), but I don't know which one. Please help me rename it to something descriptive!
248+
// FIXME: these locations seem to have a special meaning (e.g. everywhere, at the end,
249+
// ...), but I don't know which one. Please help me rename it to something descriptive!
255250
// Also, if this IntervalSet is used in many places, it maybe should have a newtype'd
256251
// name with a description of what it means for future mortals passing by.
257252
let locations = IntervalSet::new(self.cx.elements.num_points());
@@ -615,13 +610,9 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
615610
tcx: typeck.tcx(),
616611
param_env: typeck.param_env,
617612
op: |r| {
618-
let live_region_vid = typeck.borrowck_context.universal_regions.to_region_vid(r);
613+
let live_region_vid = typeck.universal_regions.to_region_vid(r);
619614

620-
typeck
621-
.borrowck_context
622-
.constraints
623-
.liveness_constraints
624-
.add_points(live_region_vid, live_at);
615+
typeck.constraints.liveness_constraints.add_points(live_region_vid, live_at);
625616
},
626617
});
627618
}

‎compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 68 additions & 124 deletions
Large diffs are not rendered by default.

‎compiler/rustc_borrowck/src/type_check/relate_tys.rs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,7 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
240240

241241
fn create_next_universe(&mut self) -> ty::UniverseIndex {
242242
let universe = self.type_checker.infcx.create_next_universe();
243-
self.type_checker
244-
.borrowck_context
245-
.constraints
246-
.universe_causes
247-
.insert(universe, self.universe_info.clone());
243+
self.type_checker.constraints.universe_causes.insert(universe, self.universe_info.clone());
248244
universe
249245
}
250246

@@ -264,11 +260,8 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
264260

265261
#[instrument(skip(self), level = "debug")]
266262
fn next_placeholder_region(&mut self, placeholder: ty::PlaceholderRegion) -> ty::Region<'tcx> {
267-
let reg = self
268-
.type_checker
269-
.borrowck_context
270-
.constraints
271-
.placeholder_region(self.type_checker.infcx, placeholder);
263+
let reg =
264+
self.type_checker.constraints.placeholder_region(self.type_checker.infcx, placeholder);
272265

273266
let reg_info = match placeholder.bound.kind {
274267
ty::BoundRegionKind::BrAnon => sym::anon,
@@ -294,19 +287,17 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
294287
sub: ty::Region<'tcx>,
295288
info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
296289
) {
297-
let sub = self.type_checker.borrowck_context.universal_regions.to_region_vid(sub);
298-
let sup = self.type_checker.borrowck_context.universal_regions.to_region_vid(sup);
299-
self.type_checker.borrowck_context.constraints.outlives_constraints.push(
300-
OutlivesConstraint {
301-
sup,
302-
sub,
303-
locations: self.locations,
304-
span: self.locations.span(self.type_checker.body),
305-
category: self.category,
306-
variance_info: info,
307-
from_closure: false,
308-
},
309-
);
290+
let sub = self.type_checker.universal_regions.to_region_vid(sub);
291+
let sup = self.type_checker.universal_regions.to_region_vid(sup);
292+
self.type_checker.constraints.outlives_constraints.push(OutlivesConstraint {
293+
sup,
294+
sub,
295+
locations: self.locations,
296+
span: self.locations.span(self.type_checker.body),
297+
category: self.category,
298+
variance_info: info,
299+
from_closure: false,
300+
});
310301
}
311302
}
312303

0 commit comments

Comments
 (0)
Please sign in to comment.