Skip to content

Commit f5a1261

Browse files
Rollup merge of rust-lang#119096 - compiler-errors:yeet-unnecessary-param-envs, r=lcnr
Yeet unnecessary param envs We don't need to pass in param-envs around in the lexical region resolution code (or in `MatchAgainstFreshVars` in the solver), since it is only used to eval some consts in `structurally_relate_tys` which I removed. This is in preparation for normalizing the outlives clauses in `ParamEnv` for the new trait solver. r? lcnr
2 parents 505ae86 + a75d002 commit f5a1261

File tree

17 files changed

+48
-108
lines changed

17 files changed

+48
-108
lines changed

compiler/rustc_borrowck/src/region_infer/mod.rs

+6-23
Original file line numberDiff line numberDiff line change
@@ -674,13 +674,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
674674
// eagerly.
675675
let mut outlives_requirements = infcx.tcx.is_typeck_child(mir_def_id).then(Vec::new);
676676

677-
self.check_type_tests(
678-
infcx,
679-
param_env,
680-
body,
681-
outlives_requirements.as_mut(),
682-
&mut errors_buffer,
683-
);
677+
self.check_type_tests(infcx, body, outlives_requirements.as_mut(), &mut errors_buffer);
684678

685679
debug!(?errors_buffer);
686680
debug!(?outlives_requirements);
@@ -938,7 +932,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
938932
fn check_type_tests(
939933
&self,
940934
infcx: &InferCtxt<'tcx>,
941-
param_env: ty::ParamEnv<'tcx>,
942935
body: &Body<'tcx>,
943936
mut propagated_outlives_requirements: Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
944937
errors_buffer: &mut RegionErrors<'tcx>,
@@ -956,7 +949,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
956949
let generic_ty = type_test.generic_kind.to_ty(tcx);
957950
if self.eval_verify_bound(
958951
infcx,
959-
param_env,
960952
generic_ty,
961953
type_test.lower_bound,
962954
&type_test.verify_bound,
@@ -967,7 +959,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
967959
if let Some(propagated_outlives_requirements) = &mut propagated_outlives_requirements {
968960
if self.try_promote_type_test(
969961
infcx,
970-
param_env,
971962
body,
972963
type_test,
973964
propagated_outlives_requirements,
@@ -1025,7 +1016,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
10251016
fn try_promote_type_test(
10261017
&self,
10271018
infcx: &InferCtxt<'tcx>,
1028-
param_env: ty::ParamEnv<'tcx>,
10291019
body: &Body<'tcx>,
10301020
type_test: &TypeTest<'tcx>,
10311021
propagated_outlives_requirements: &mut Vec<ClosureOutlivesRequirement<'tcx>>,
@@ -1087,7 +1077,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
10871077
// where `ur` is a local bound -- we are sometimes in a
10881078
// position to prove things that our caller cannot. See
10891079
// #53570 for an example.
1090-
if self.eval_verify_bound(infcx, param_env, generic_ty, ur, &type_test.verify_bound) {
1080+
if self.eval_verify_bound(infcx, generic_ty, ur, &type_test.verify_bound) {
10911081
continue;
10921082
}
10931083

@@ -1270,7 +1260,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
12701260
fn eval_verify_bound(
12711261
&self,
12721262
infcx: &InferCtxt<'tcx>,
1273-
param_env: ty::ParamEnv<'tcx>,
12741263
generic_ty: Ty<'tcx>,
12751264
lower_bound: RegionVid,
12761265
verify_bound: &VerifyBound<'tcx>,
@@ -1279,7 +1268,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
12791268

12801269
match verify_bound {
12811270
VerifyBound::IfEq(verify_if_eq_b) => {
1282-
self.eval_if_eq(infcx, param_env, generic_ty, lower_bound, *verify_if_eq_b)
1271+
self.eval_if_eq(infcx, generic_ty, lower_bound, *verify_if_eq_b)
12831272
}
12841273

12851274
VerifyBound::IsEmpty => {
@@ -1293,31 +1282,25 @@ impl<'tcx> RegionInferenceContext<'tcx> {
12931282
}
12941283

12951284
VerifyBound::AnyBound(verify_bounds) => verify_bounds.iter().any(|verify_bound| {
1296-
self.eval_verify_bound(infcx, param_env, generic_ty, lower_bound, verify_bound)
1285+
self.eval_verify_bound(infcx, generic_ty, lower_bound, verify_bound)
12971286
}),
12981287

12991288
VerifyBound::AllBounds(verify_bounds) => verify_bounds.iter().all(|verify_bound| {
1300-
self.eval_verify_bound(infcx, param_env, generic_ty, lower_bound, verify_bound)
1289+
self.eval_verify_bound(infcx, generic_ty, lower_bound, verify_bound)
13011290
}),
13021291
}
13031292
}
13041293

13051294
fn eval_if_eq(
13061295
&self,
13071296
infcx: &InferCtxt<'tcx>,
1308-
param_env: ty::ParamEnv<'tcx>,
13091297
generic_ty: Ty<'tcx>,
13101298
lower_bound: RegionVid,
13111299
verify_if_eq_b: ty::Binder<'tcx, VerifyIfEq<'tcx>>,
13121300
) -> bool {
13131301
let generic_ty = self.normalize_to_scc_representatives(infcx.tcx, generic_ty);
13141302
let verify_if_eq_b = self.normalize_to_scc_representatives(infcx.tcx, verify_if_eq_b);
1315-
match test_type_match::extract_verify_if_eq(
1316-
infcx.tcx,
1317-
param_env,
1318-
&verify_if_eq_b,
1319-
generic_ty,
1320-
) {
1303+
match test_type_match::extract_verify_if_eq(infcx.tcx, &verify_if_eq_b, generic_ty) {
13211304
Some(r) => {
13221305
let r_vid = self.to_region_vid(r);
13231306
self.eval_outlives(r_vid, lower_bound)

compiler/rustc_infer/src/infer/error_reporting/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -2653,11 +2653,6 @@ impl<'tcx> TypeRelation<'tcx> for SameTypeModuloInfer<'_, 'tcx> {
26532653
self.0.tcx
26542654
}
26552655

2656-
fn param_env(&self) -> ty::ParamEnv<'tcx> {
2657-
// Unused, only for consts which we treat as always equal
2658-
ty::ParamEnv::empty()
2659-
}
2660-
26612656
fn tag(&self) -> &'static str {
26622657
"SameTypeModuloInfer"
26632658
}

compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@ use super::outlives::test_type_match;
3131
/// all the variables as well as a set of errors that must be reported.
3232
#[instrument(level = "debug", skip(region_rels, var_infos, data))]
3333
pub(crate) fn resolve<'tcx>(
34-
param_env: ty::ParamEnv<'tcx>,
3534
region_rels: &RegionRelations<'_, 'tcx>,
3635
var_infos: VarInfos,
3736
data: RegionConstraintData<'tcx>,
3837
) -> (LexicalRegionResolutions<'tcx>, Vec<RegionResolutionError<'tcx>>) {
3938
let mut errors = vec![];
40-
let mut resolver = LexicalResolver { param_env, region_rels, var_infos, data };
39+
let mut resolver = LexicalResolver { region_rels, var_infos, data };
4140
let values = resolver.infer_variable_values(&mut errors);
4241
(values, errors)
4342
}
@@ -120,7 +119,6 @@ struct RegionAndOrigin<'tcx> {
120119
type RegionGraph<'tcx> = Graph<(), Constraint<'tcx>>;
121120

122121
struct LexicalResolver<'cx, 'tcx> {
123-
param_env: ty::ParamEnv<'tcx>,
124122
region_rels: &'cx RegionRelations<'cx, 'tcx>,
125123
var_infos: VarInfos,
126124
data: RegionConstraintData<'tcx>,
@@ -914,12 +912,8 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
914912
match bound {
915913
VerifyBound::IfEq(verify_if_eq_b) => {
916914
let verify_if_eq_b = var_values.normalize(self.region_rels.tcx, *verify_if_eq_b);
917-
match test_type_match::extract_verify_if_eq(
918-
self.tcx(),
919-
self.param_env,
920-
&verify_if_eq_b,
921-
generic_ty,
922-
) {
915+
match test_type_match::extract_verify_if_eq(self.tcx(), &verify_if_eq_b, generic_ty)
916+
{
923917
Some(r) => {
924918
self.bound_is_met(&VerifyBound::OutlivedBy(r), var_values, generic_ty, min)
925919
}

compiler/rustc_infer/src/infer/outlives/for_liveness.rs

-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ where
8484
} else {
8585
test_type_match::extract_verify_if_eq(
8686
tcx,
87-
param_env,
8887
&outlives.map_bound(|ty::OutlivesPredicate(ty, bound)| {
8988
VerifyIfEq { ty, bound }
9089
}),

compiler/rustc_infer/src/infer/outlives/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<'tcx> InferCtxt<'tcx> {
6767
let region_rels = &RegionRelations::new(self.tcx, outlives_env.free_region_map());
6868

6969
let (lexical_region_resolutions, errors) =
70-
lexical_region_resolve::resolve(outlives_env.param_env, region_rels, var_infos, data);
70+
lexical_region_resolve::resolve(region_rels, var_infos, data);
7171

7272
let old_value = self.lexical_region_resolutions.replace(Some(lexical_region_resolutions));
7373
assert!(old_value.is_none());

compiler/rustc_infer/src/infer/outlives/test_type_match.rs

+7-16
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@ use crate::infer::region_constraints::VerifyIfEq;
3636
/// like are used. This is a particular challenge since this function is invoked
3737
/// very late in inference and hence cannot make use of the normal inference
3838
/// machinery.
39-
#[instrument(level = "debug", skip(tcx, param_env))]
39+
#[instrument(level = "debug", skip(tcx))]
4040
pub fn extract_verify_if_eq<'tcx>(
4141
tcx: TyCtxt<'tcx>,
42-
param_env: ty::ParamEnv<'tcx>,
4342
verify_if_eq_b: &ty::Binder<'tcx, VerifyIfEq<'tcx>>,
4443
test_ty: Ty<'tcx>,
4544
) -> Option<ty::Region<'tcx>> {
4645
assert!(!verify_if_eq_b.has_escaping_bound_vars());
47-
let mut m = MatchAgainstHigherRankedOutlives::new(tcx, param_env);
46+
let mut m = MatchAgainstHigherRankedOutlives::new(tcx);
4847
let verify_if_eq = verify_if_eq_b.skip_binder();
4948
m.relate(verify_if_eq.ty, test_ty).ok()?;
5049

@@ -73,10 +72,9 @@ pub fn extract_verify_if_eq<'tcx>(
7372
}
7473

7574
/// True if a (potentially higher-ranked) outlives
76-
#[instrument(level = "debug", skip(tcx, param_env))]
75+
#[instrument(level = "debug", skip(tcx))]
7776
pub(super) fn can_match_erased_ty<'tcx>(
7877
tcx: TyCtxt<'tcx>,
79-
param_env: ty::ParamEnv<'tcx>,
8078
outlives_predicate: ty::Binder<'tcx, ty::TypeOutlivesPredicate<'tcx>>,
8179
erased_ty: Ty<'tcx>,
8280
) -> bool {
@@ -87,25 +85,20 @@ pub(super) fn can_match_erased_ty<'tcx>(
8785
// pointless micro-optimization
8886
true
8987
} else {
90-
MatchAgainstHigherRankedOutlives::new(tcx, param_env).relate(outlives_ty, erased_ty).is_ok()
88+
MatchAgainstHigherRankedOutlives::new(tcx).relate(outlives_ty, erased_ty).is_ok()
9189
}
9290
}
9391

9492
struct MatchAgainstHigherRankedOutlives<'tcx> {
9593
tcx: TyCtxt<'tcx>,
96-
param_env: ty::ParamEnv<'tcx>,
9794
pattern_depth: ty::DebruijnIndex,
9895
map: FxHashMap<ty::BoundRegion, ty::Region<'tcx>>,
9996
}
10097

10198
impl<'tcx> MatchAgainstHigherRankedOutlives<'tcx> {
102-
fn new(
103-
tcx: TyCtxt<'tcx>,
104-
param_env: ty::ParamEnv<'tcx>,
105-
) -> MatchAgainstHigherRankedOutlives<'tcx> {
99+
fn new(tcx: TyCtxt<'tcx>) -> MatchAgainstHigherRankedOutlives<'tcx> {
106100
MatchAgainstHigherRankedOutlives {
107101
tcx,
108-
param_env,
109102
pattern_depth: ty::INNERMOST,
110103
map: FxHashMap::default(),
111104
}
@@ -144,15 +137,13 @@ impl<'tcx> MatchAgainstHigherRankedOutlives<'tcx> {
144137

145138
impl<'tcx> TypeRelation<'tcx> for MatchAgainstHigherRankedOutlives<'tcx> {
146139
fn tag(&self) -> &'static str {
147-
"Match"
140+
"MatchAgainstHigherRankedOutlives"
148141
}
149142

150143
fn tcx(&self) -> TyCtxt<'tcx> {
151144
self.tcx
152145
}
153-
fn param_env(&self) -> ty::ParamEnv<'tcx> {
154-
self.param_env
155-
}
146+
156147
fn a_is_expected(&self) -> bool {
157148
true
158149
} // irrelevant

compiler/rustc_infer/src/infer/outlives/verify.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,8 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
322322
) -> impl Iterator<Item = ty::Binder<'tcx, ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>>>
323323
{
324324
let tcx = self.tcx;
325-
let param_env = self.param_env;
326325
clauses.filter_map(|p| p.as_type_outlives_clause()).filter(move |outlives_predicate| {
327-
super::test_type_match::can_match_erased_ty(
328-
tcx,
329-
param_env,
330-
*outlives_predicate,
331-
erased_ty,
332-
)
326+
super::test_type_match::can_match_erased_ty(tcx, *outlives_predicate, erased_ty)
333327
})
334328
}
335329
}

compiler/rustc_infer/src/infer/relate/combine.rs

+2
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,8 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
563563
}
564564

565565
pub trait ObligationEmittingRelation<'tcx>: TypeRelation<'tcx> {
566+
fn param_env(&self) -> ty::ParamEnv<'tcx>;
567+
566568
/// Register obligations that must hold in order for this relation to hold
567569
fn register_obligations(&mut self, obligations: PredicateObligations<'tcx>);
568570

compiler/rustc_infer/src/infer/relate/equate.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
3333
self.fields.tcx()
3434
}
3535

36-
fn param_env(&self) -> ty::ParamEnv<'tcx> {
37-
self.fields.param_env
38-
}
39-
4036
fn a_is_expected(&self) -> bool {
4137
self.a_is_expected
4238
}
@@ -174,6 +170,10 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
174170
}
175171

176172
impl<'tcx> ObligationEmittingRelation<'tcx> for Equate<'_, '_, 'tcx> {
173+
fn param_env(&self) -> ty::ParamEnv<'tcx> {
174+
self.fields.param_env
175+
}
176+
177177
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::ToPredicate<'tcx>>) {
178178
self.fields.register_predicates(obligations);
179179
}

compiler/rustc_infer/src/infer/relate/generalize.rs

-4
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,6 @@ where
182182
self.infcx.tcx
183183
}
184184

185-
fn param_env(&self) -> ty::ParamEnv<'tcx> {
186-
self.delegate.param_env()
187-
}
188-
189185
fn tag(&self) -> &'static str {
190186
"Generalizer"
191187
}

compiler/rustc_infer/src/infer/relate/glb.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ impl<'tcx> TypeRelation<'tcx> for Glb<'_, '_, 'tcx> {
3232
self.fields.tcx()
3333
}
3434

35-
fn param_env(&self) -> ty::ParamEnv<'tcx> {
36-
self.fields.param_env
37-
}
38-
3935
fn a_is_expected(&self) -> bool {
4036
self.a_is_expected
4137
}
@@ -138,6 +134,10 @@ impl<'combine, 'infcx, 'tcx> LatticeDir<'infcx, 'tcx> for Glb<'combine, 'infcx,
138134
}
139135

140136
impl<'tcx> ObligationEmittingRelation<'tcx> for Glb<'_, '_, 'tcx> {
137+
fn param_env(&self) -> ty::ParamEnv<'tcx> {
138+
self.fields.param_env
139+
}
140+
141141
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::ToPredicate<'tcx>>) {
142142
self.fields.register_predicates(obligations);
143143
}

compiler/rustc_infer/src/infer/relate/lub.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ impl<'tcx> TypeRelation<'tcx> for Lub<'_, '_, 'tcx> {
3232
self.fields.tcx()
3333
}
3434

35-
fn param_env(&self) -> ty::ParamEnv<'tcx> {
36-
self.fields.param_env
37-
}
38-
3935
fn a_is_expected(&self) -> bool {
4036
self.a_is_expected
4137
}
@@ -138,6 +134,10 @@ impl<'combine, 'infcx, 'tcx> LatticeDir<'infcx, 'tcx> for Lub<'combine, 'infcx,
138134
}
139135

140136
impl<'tcx> ObligationEmittingRelation<'tcx> for Lub<'_, '_, 'tcx> {
137+
fn param_env(&self) -> ty::ParamEnv<'tcx> {
138+
self.fields.param_env
139+
}
140+
141141
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::ToPredicate<'tcx>>) {
142142
self.fields.register_predicates(obligations);
143143
}

compiler/rustc_infer/src/infer/relate/nll.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,6 @@ where
431431
self.infcx.tcx
432432
}
433433

434-
fn param_env(&self) -> ty::ParamEnv<'tcx> {
435-
self.delegate.param_env()
436-
}
437-
438434
fn tag(&self) -> &'static str {
439435
"nll::subtype"
440436
}
@@ -670,6 +666,10 @@ impl<'tcx, D> ObligationEmittingRelation<'tcx> for TypeRelating<'_, 'tcx, D>
670666
where
671667
D: TypeRelatingDelegate<'tcx>,
672668
{
669+
fn param_env(&self) -> ty::ParamEnv<'tcx> {
670+
self.delegate.param_env()
671+
}
672+
673673
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::ToPredicate<'tcx>>) {
674674
self.delegate.register_obligations(
675675
obligations

compiler/rustc_infer/src/infer/relate/sub.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
3939
self.fields.infcx.tcx
4040
}
4141

42-
fn param_env(&self) -> ty::ParamEnv<'tcx> {
43-
self.fields.param_env
44-
}
45-
4642
fn a_is_expected(&self) -> bool {
4743
self.a_is_expected
4844
}
@@ -203,6 +199,10 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
203199
}
204200

205201
impl<'tcx> ObligationEmittingRelation<'tcx> for Sub<'_, '_, 'tcx> {
202+
fn param_env(&self) -> ty::ParamEnv<'tcx> {
203+
self.fields.param_env
204+
}
205+
206206
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::ToPredicate<'tcx>>) {
207207
self.fields.register_predicates(obligations);
208208
}

0 commit comments

Comments
 (0)