Skip to content

Commit f724725

Browse files
committed
Put param_env into infcx.
Because they get passed around together a lot.
1 parent fcaf908 commit f724725

13 files changed

+55
-67
lines changed

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<'tcx> UniverseInfo<'tcx> {
6060
UniverseInfo::RelateTys { expected, found } => {
6161
let err = mbcx.infcx.err_ctxt().report_mismatched_types(
6262
&cause,
63-
mbcx.param_env,
63+
mbcx.infcx.param_env,
6464
expected,
6565
found,
6666
TypeError::RegionsPlaceholderMismatch,

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
832832
let ty = moved_place.ty(self.body, self.infcx.tcx).ty;
833833
debug!("ty: {:?}, kind: {:?}", ty, ty.kind());
834834

835-
let Some(assign_value) = self.infcx.err_ctxt().ty_kind_suggestion(self.param_env, ty)
835+
let Some(assign_value) = self.infcx.err_ctxt().ty_kind_suggestion(self.infcx.param_env, ty)
836836
else {
837837
return;
838838
};
@@ -1300,7 +1300,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
13001300
pub(crate) fn implements_clone(&self, ty: Ty<'tcx>) -> bool {
13011301
let Some(clone_trait_def) = self.infcx.tcx.lang_items().clone_trait() else { return false };
13021302
self.infcx
1303-
.type_implements_trait(clone_trait_def, [ty], self.param_env)
1303+
.type_implements_trait(clone_trait_def, [ty], self.infcx.param_env)
13041304
.must_apply_modulo_regions()
13051305
}
13061306

@@ -1433,7 +1433,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
14331433
let ocx = ObligationCtxt::new_with_diagnostics(self.infcx);
14341434
let cause = ObligationCause::misc(span, self.mir_def_id());
14351435

1436-
ocx.register_bound(cause, self.param_env, ty, def_id);
1436+
ocx.register_bound(cause, self.infcx.param_env, ty, def_id);
14371437
let errors = ocx.select_all_or_error();
14381438

14391439
// Only emit suggestion if all required predicates are on generic
@@ -1953,7 +1953,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
19531953
&& let ty::Ref(_, inner, _) = rcvr_ty.kind()
19541954
&& let inner = inner.peel_refs()
19551955
&& (Holds { ty: inner }).visit_ty(local_ty).is_break()
1956-
&& let None = self.infcx.type_implements_trait_shallow(clone, inner, self.param_env)
1956+
&& let None =
1957+
self.infcx.type_implements_trait_shallow(clone, inner, self.infcx.param_env)
19571958
{
19581959
err.span_label(
19591960
span,
@@ -1985,7 +1986,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
19851986
let obligation = Obligation::new(
19861987
self.infcx.tcx,
19871988
ObligationCause::dummy(),
1988-
self.param_env,
1989+
self.infcx.param_env,
19891990
trait_ref,
19901991
);
19911992
self.infcx.err_ctxt().suggest_derive(
@@ -3394,7 +3395,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
33943395
if let Some(iter_trait) = tcx.get_diagnostic_item(sym::Iterator)
33953396
&& self
33963397
.infcx
3397-
.type_implements_trait(iter_trait, [return_ty], self.param_env)
3398+
.type_implements_trait(iter_trait, [return_ty], self.infcx.param_env)
33983399
.must_apply_modulo_regions()
33993400
{
34003401
err.span_suggestion_hidden(
@@ -3833,11 +3834,11 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
38333834
if tcx.is_diagnostic_item(sym::deref_method, method_did) {
38343835
let deref_target =
38353836
tcx.get_diagnostic_item(sym::deref_target).and_then(|deref_target| {
3836-
Instance::try_resolve(tcx, self.param_env, deref_target, method_args)
3837+
Instance::try_resolve(tcx, self.infcx.param_env, deref_target, method_args)
38373838
.transpose()
38383839
});
38393840
if let Some(Ok(instance)) = deref_target {
3840-
let deref_target_ty = instance.ty(tcx, self.param_env);
3841+
let deref_target_ty = instance.ty(tcx, self.infcx.param_env);
38413842
err.note(format!("borrow occurs due to deref coercion to `{deref_target_ty}`"));
38423843
err.span_note(tcx.def_span(instance.def_id()), "deref defined here");
38433844
}

compiler/rustc_borrowck/src/diagnostics/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
864864

865865
let kind = call_kind(
866866
self.infcx.tcx,
867-
self.param_env,
867+
self.infcx.param_env,
868868
method_did,
869869
method_args,
870870
*fn_span,
@@ -1160,7 +1160,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
11601160
let suggest = match tcx.get_diagnostic_item(sym::IntoIterator) {
11611161
Some(def_id) => type_known_to_meet_bound_modulo_regions(
11621162
self.infcx,
1163-
self.param_env,
1163+
self.infcx.param_env,
11641164
Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, ty),
11651165
def_id,
11661166
),
@@ -1224,7 +1224,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
12241224
BoundRegionConversionTime::FnCall,
12251225
tcx.fn_sig(method_did).instantiate(tcx, method_args).input(0),
12261226
)
1227-
&& self.infcx.can_eq(self.param_env, ty, self_ty)
1227+
&& self.infcx.can_eq(self.infcx.param_env, ty, self_ty)
12281228
{
12291229
err.subdiagnostic(CaptureReasonSuggest::FreshReborrow {
12301230
span: move_span.shrink_to_hi(),
@@ -1258,7 +1258,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
12581258
if let Some(errors) = self.infcx.type_implements_trait_shallow(
12591259
clone_trait,
12601260
ty,
1261-
self.param_env,
1261+
self.infcx.param_env,
12621262
) && !has_sugg
12631263
{
12641264
let msg = match &errors[..] {

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
12421242
.type_implements_trait_shallow(
12431243
clone_trait,
12441244
ty.peel_refs(),
1245-
self.param_env,
1245+
self.infcx.param_env,
12461246
)
12471247
.as_deref()
12481248
{
@@ -1279,7 +1279,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
12791279
let obligation = traits::Obligation::new(
12801280
self.infcx.tcx,
12811281
traits::ObligationCause::dummy(),
1282-
self.param_env,
1282+
self.infcx.param_env,
12831283
trait_ref,
12841284
);
12851285
self.infcx.err_ctxt().suggest_derive(

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
952952

953953
if let Ok(Some(instance)) = ty::Instance::try_resolve(
954954
tcx,
955-
self.param_env,
955+
self.infcx.param_env,
956956
*fn_did,
957957
self.infcx.resolve_vars_if_possible(args),
958958
) {
@@ -1091,7 +1091,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
10911091
peeled_ty = ref_ty;
10921092
count += 1;
10931093
}
1094-
if !self.infcx.type_is_copy_modulo_regions(self.param_env, peeled_ty) {
1094+
if !self.infcx.type_is_copy_modulo_regions(self.infcx.param_env, peeled_ty) {
10951095
return;
10961096
}
10971097

@@ -1160,7 +1160,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
11601160
let ocx = ObligationCtxt::new(&self.infcx);
11611161
ocx.register_obligations(preds.iter().map(|(pred, span)| {
11621162
trace!(?pred);
1163-
Obligation::misc(tcx, span, self.mir_def_id(), self.param_env, pred)
1163+
Obligation::misc(tcx, span, self.mir_def_id(), self.infcx.param_env, pred)
11641164
}));
11651165

11661166
if ocx.select_all_or_error().is_empty() && count > 0 {

compiler/rustc_borrowck/src/lib.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ fn do_mir_borrowck<'tcx>(
140140
) -> (BorrowCheckResult<'tcx>, Option<Box<BodyWithBorrowckFacts<'tcx>>>) {
141141
let def = input_body.source.def_id().expect_local();
142142
let infcx = BorrowckInferCtxt::new(tcx, def);
143-
let param_env = tcx.param_env(def);
144143

145144
let mut local_names = IndexVec::from_elem(None, &input_body.local_decls);
146145
for var_debug_info in &input_body.var_debug_info {
@@ -175,8 +174,7 @@ fn do_mir_borrowck<'tcx>(
175174
// will have a lifetime tied to the inference context.
176175
let mut body_owned = input_body.clone();
177176
let mut promoted = input_promoted.to_owned();
178-
let free_regions =
179-
nll::replace_regions_in_mir(&infcx, param_env, &mut body_owned, &mut promoted);
177+
let free_regions = nll::replace_regions_in_mir(&infcx, &mut body_owned, &mut promoted);
180178
let body = &body_owned; // no further changes
181179

182180
// FIXME(-Znext-solver): A bit dubious that we're only registering
@@ -213,7 +211,6 @@ fn do_mir_borrowck<'tcx>(
213211
body,
214212
&promoted,
215213
&location_table,
216-
param_env,
217214
&mut flow_inits,
218215
&move_data,
219216
&borrow_set,
@@ -267,7 +264,6 @@ fn do_mir_borrowck<'tcx>(
267264
let promoted_body = &promoted[idx];
268265
let mut promoted_mbcx = MirBorrowckCtxt {
269266
infcx: &infcx,
270-
param_env,
271267
body: promoted_body,
272268
move_data: &move_data,
273269
location_table: &location_table, // no need to create a real one for the promoted, it is not used
@@ -307,7 +303,6 @@ fn do_mir_borrowck<'tcx>(
307303

308304
let mut mbcx = MirBorrowckCtxt {
309305
infcx: &infcx,
310-
param_env,
311306
body,
312307
move_data: &move_data,
313308
location_table: &location_table,
@@ -428,12 +423,14 @@ fn do_mir_borrowck<'tcx>(
428423
pub(crate) struct BorrowckInferCtxt<'tcx> {
429424
pub(crate) infcx: InferCtxt<'tcx>,
430425
pub(crate) reg_var_to_origin: RefCell<FxIndexMap<ty::RegionVid, RegionCtxt>>,
426+
pub(crate) param_env: ParamEnv<'tcx>,
431427
}
432428

433429
impl<'tcx> BorrowckInferCtxt<'tcx> {
434430
pub(crate) fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self {
435431
let infcx = tcx.infer_ctxt().build(TypingMode::analysis_in_body(tcx, def_id));
436-
BorrowckInferCtxt { infcx, reg_var_to_origin: RefCell::new(Default::default()) }
432+
let param_env = tcx.param_env(def_id);
433+
BorrowckInferCtxt { infcx, reg_var_to_origin: RefCell::new(Default::default()), param_env }
437434
}
438435

439436
pub(crate) fn next_region_var<F>(
@@ -512,7 +509,6 @@ impl<'tcx> Deref for BorrowckInferCtxt<'tcx> {
512509

513510
struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
514511
infcx: &'infcx BorrowckInferCtxt<'tcx>,
515-
param_env: ParamEnv<'tcx>,
516512
body: &'a Body<'tcx>,
517513
move_data: &'a MoveData<'tcx>,
518514

compiler/rustc_borrowck/src/nll.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ pub(crate) struct NllOutput<'tcx> {
5050
/// Rewrites the regions in the MIR to use NLL variables, also scraping out the set of universal
5151
/// regions (e.g., region parameters) declared on the function. That set will need to be given to
5252
/// `compute_regions`.
53-
#[instrument(skip(infcx, param_env, body, promoted), level = "debug")]
53+
#[instrument(skip(infcx, body, promoted), level = "debug")]
5454
pub(crate) fn replace_regions_in_mir<'tcx>(
5555
infcx: &BorrowckInferCtxt<'tcx>,
56-
param_env: ty::ParamEnv<'tcx>,
5756
body: &mut Body<'tcx>,
5857
promoted: &mut IndexSlice<Promoted, Body<'tcx>>,
5958
) -> UniversalRegions<'tcx> {
@@ -62,7 +61,7 @@ pub(crate) fn replace_regions_in_mir<'tcx>(
6261
debug!(?def);
6362

6463
// Compute named region information. This also renumbers the inputs/outputs.
65-
let universal_regions = UniversalRegions::new(infcx, def, param_env);
64+
let universal_regions = UniversalRegions::new(infcx, def);
6665

6766
// Replace all remaining regions with fresh inference variables.
6867
renumber::renumber_mir(infcx, body, promoted);
@@ -81,7 +80,6 @@ pub(crate) fn compute_regions<'a, 'tcx>(
8180
body: &Body<'tcx>,
8281
promoted: &IndexSlice<Promoted, Body<'tcx>>,
8382
location_table: &LocationTable,
84-
param_env: ty::ParamEnv<'tcx>,
8583
flow_inits: &mut ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
8684
move_data: &MoveData<'tcx>,
8785
borrow_set: &BorrowSet<'tcx>,
@@ -101,7 +99,6 @@ pub(crate) fn compute_regions<'a, 'tcx>(
10199
let MirTypeckResults { constraints, universal_region_relations, opaque_type_values } =
102100
type_check::type_check(
103101
infcx,
104-
param_env,
105102
body,
106103
promoted,
107104
universal_regions,

compiler/rustc_borrowck/src/type_check/canonical.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
132132
locations: Locations,
133133
category: ConstraintCategory<'tcx>,
134134
) {
135-
let param_env = self.param_env;
135+
let param_env = self.infcx.param_env;
136136
let predicate = predicate.upcast(self.tcx());
137137
let _: Result<_, ErrorGuaranteed> = self.fully_perform_op(
138138
locations,
@@ -158,7 +158,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
158158
where
159159
T: type_op::normalize::Normalizable<'tcx> + fmt::Display + Copy + 'tcx,
160160
{
161-
let param_env = self.param_env;
161+
let param_env = self.infcx.param_env;
162162
let result: Result<_, ErrorGuaranteed> = self.fully_perform_op(
163163
location.to_locations(),
164164
category,
@@ -176,7 +176,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
176176
let tcx = self.tcx();
177177
if self.infcx.next_trait_solver() {
178178
let body = self.body;
179-
let param_env = self.param_env;
179+
let param_env = self.infcx.param_env;
180180
self.fully_perform_op(
181181
location.to_locations(),
182182
ConstraintCategory::Boring,
@@ -223,7 +223,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
223223
let _: Result<_, ErrorGuaranteed> = self.fully_perform_op(
224224
Locations::All(span),
225225
ConstraintCategory::Boring,
226-
self.param_env.and(type_op::ascribe_user_type::AscribeUserType { mir_ty, user_ty }),
226+
self.infcx
227+
.param_env
228+
.and(type_op::ascribe_user_type::AscribeUserType { mir_ty, user_ty }),
227229
);
228230
}
229231

@@ -250,7 +252,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
250252
let mir_ty = self.normalize(mir_ty, Locations::All(span));
251253

252254
let cause = ObligationCause::dummy_with_span(span);
253-
let param_env = self.param_env;
255+
let param_env = self.infcx.param_env;
254256
let _: Result<_, ErrorGuaranteed> = self.fully_perform_op(
255257
Locations::All(span),
256258
ConstraintCategory::Boring,

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
234234
// In the new solver, normalize the type-outlives obligation assumptions.
235235
if self.infcx.next_trait_solver() {
236236
match deeply_normalize(
237-
self.infcx.at(&ObligationCause::misc(span, defining_ty_def_id), self.param_env),
237+
self.infcx.at(&ObligationCause::misc(span, defining_ty_def_id), param_env),
238238
outlives,
239239
) {
240240
Ok(normalized_outlives) => {
@@ -274,15 +274,15 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
274274
if let Some(c) = constraints_unnorm {
275275
constraints.push(c)
276276
}
277-
let TypeOpOutput { output: norm_ty, constraints: constraints_normalize, .. } = self
278-
.param_env
279-
.and(type_op::normalize::Normalize { value: ty })
280-
.fully_perform(self.infcx, span)
281-
.unwrap_or_else(|guar| TypeOpOutput {
282-
output: Ty::new_error(self.infcx.tcx, guar),
283-
constraints: None,
284-
error_info: None,
285-
});
277+
let TypeOpOutput { output: norm_ty, constraints: constraints_normalize, .. } =
278+
param_env
279+
.and(type_op::normalize::Normalize { value: ty })
280+
.fully_perform(self.infcx, span)
281+
.unwrap_or_else(|guar| TypeOpOutput {
282+
output: Ty::new_error(self.infcx.tcx, guar),
283+
constraints: None,
284+
error_info: None,
285+
});
286286
if let Some(c) = constraints_normalize {
287287
constraints.push(c)
288288
}
@@ -312,8 +312,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
312312
// Add implied bounds from impl header.
313313
if matches!(tcx.def_kind(defining_ty_def_id), DefKind::AssocFn | DefKind::AssocConst) {
314314
for &(ty, _) in tcx.assumed_wf_types(tcx.local_parent(defining_ty_def_id)) {
315-
let result: Result<_, ErrorGuaranteed> = self
316-
.param_env
315+
let result: Result<_, ErrorGuaranteed> = param_env
317316
.and(type_op::normalize::Normalize { value: ty })
318317
.fully_perform(self.infcx, span);
319318
let Ok(TypeOpOutput { output: norm_ty, constraints: c, .. }) = result else {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
608608

609609
value.visit_with(&mut for_liveness::FreeRegionsVisitor {
610610
tcx: typeck.tcx(),
611-
param_env: typeck.param_env,
611+
param_env: typeck.infcx.param_env,
612612
op: |r| {
613613
let live_region_vid = typeck.universal_regions.to_region_vid(r);
614614

@@ -621,6 +621,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
621621
debug!("compute_drop_data(dropped_ty={:?})", dropped_ty,);
622622

623623
match typeck
624+
.infcx
624625
.param_env
625626
.and(DropckOutlives { dropped_ty })
626627
.fully_perform(typeck.infcx, DUMMY_SP)

0 commit comments

Comments
 (0)