Skip to content

Commit eacc881

Browse files
ParamEnv::new -> ParamEnv::from_elaborated_clauses
1 parent 300d4a5 commit eacc881

File tree

10 files changed

+32
-22
lines changed

10 files changed

+32
-22
lines changed

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ fn compare_method_predicate_entailment<'tcx>(
221221
// The key step here is to update the caller_bounds's predicates to be
222222
// the new hybrid bounds we computed.
223223
let normalize_cause = traits::ObligationCause::misc(impl_m_span, impl_m_def_id);
224-
let param_env = ty::ParamEnv::new(
224+
let param_env = ty::ParamEnv::from_elaborated_clauses(
225225
tcx.mk_clauses_from_iter(util::elaborate(tcx, hybrid_preds.predicates)),
226226
Reveal::UserFacing,
227227
);
@@ -488,7 +488,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
488488
.into_iter()
489489
.chain(tcx.predicates_of(trait_m.def_id).instantiate_own(tcx, trait_to_placeholder_args))
490490
.map(|(clause, _)| clause);
491-
let param_env = ty::ParamEnv::new(
491+
let param_env = ty::ParamEnv::from_elaborated_clauses(
492492
tcx.mk_clauses_from_iter(util::elaborate(tcx, hybrid_preds)),
493493
Reveal::UserFacing,
494494
);
@@ -1782,7 +1782,7 @@ fn compare_const_predicate_entailment<'tcx>(
17821782
.map(|(predicate, _)| predicate),
17831783
);
17841784

1785-
let param_env = ty::ParamEnv::new(
1785+
let param_env = ty::ParamEnv::from_elaborated_clauses(
17861786
tcx.mk_clauses_from_iter(util::elaborate(tcx, hybrid_preds.predicates)),
17871787
Reveal::UserFacing,
17881788
);
@@ -1924,7 +1924,7 @@ fn compare_type_predicate_entailment<'tcx>(
19241924

19251925
let impl_ty_span = tcx.def_span(impl_ty_def_id);
19261926
let normalize_cause = ObligationCause::misc(impl_ty_span, impl_ty_def_id);
1927-
let param_env = ty::ParamEnv::new(
1927+
let param_env = ty::ParamEnv::from_elaborated_clauses(
19281928
tcx.mk_clauses_from_iter(util::elaborate(tcx, hybrid_preds.predicates)),
19291929
Reveal::UserFacing,
19301930
);
@@ -2236,7 +2236,7 @@ fn param_env_with_gat_bounds<'tcx>(
22362236
};
22372237
}
22382238

2239-
ty::ParamEnv::new(tcx.mk_clauses(&predicates), Reveal::UserFacing)
2239+
ty::ParamEnv::from_elaborated_clauses(tcx.mk_clauses(&predicates), Reveal::UserFacing)
22402240
}
22412241

22422242
fn assoc_item_kind_str(impl_item: &ty::AssocItem) -> &'static str {

compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
123123
.into_iter()
124124
.chain(tcx.predicates_of(trait_m.def_id).instantiate_own(tcx, trait_m_to_impl_m_args))
125125
.map(|(clause, _)| clause);
126-
let param_env = ty::ParamEnv::new(
126+
let param_env = ty::ParamEnv::from_elaborated_clauses(
127127
tcx.mk_clauses_from_iter(elaborate(tcx, hybrid_preds)),
128128
Reveal::UserFacing,
129129
);

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,8 @@ fn augment_param_env<'tcx>(
605605
let bounds = tcx.mk_clauses_from_iter(
606606
param_env.caller_bounds().iter().chain(new_predicates.iter().cloned()),
607607
);
608-
// FIXME(compiler-errors): Perhaps there is a case where we need to normalize this
609-
// i.e. traits::normalize_param_env_or_error
610-
ty::ParamEnv::new(bounds, param_env.reveal())
608+
609+
ty::ParamEnv::from_elaborated_clauses(bounds, param_env.reveal())
611610
}
612611

613612
/// We use the following trait as an example throughout this function.

compiler/rustc_middle/src/ty/codec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::ParamEnv<'tcx> {
323323
fn decode(d: &mut D) -> Self {
324324
let caller_bounds = Decodable::decode(d);
325325
let reveal = Decodable::decode(d);
326-
ty::ParamEnv::new(caller_bounds, reveal)
326+
ty::ParamEnv::from_elaborated_clauses(caller_bounds, reveal)
327327
}
328328
}
329329

compiler/rustc_middle/src/ty/mod.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ParamEnv<'tcx> {
10371037
self,
10381038
folder: &mut F,
10391039
) -> Result<Self, F::Error> {
1040-
Ok(ParamEnv::new(
1040+
Ok(ParamEnv::from_elaborated_clauses(
10411041
self.caller_bounds().try_fold_with(folder)?,
10421042
self.reveal().try_fold_with(folder)?,
10431043
))
@@ -1076,7 +1076,7 @@ impl<'tcx> ParamEnv<'tcx> {
10761076
/// are revealed. This is suitable for monomorphized, post-typeck
10771077
/// environments like codegen or doing optimizations.
10781078
///
1079-
/// N.B., if you want to have predicates in scope, use `ParamEnv::new`,
1079+
/// N.B., if you want to have predicates in scope, use `ParamEnv::from_elaborated_clauses`,
10801080
/// or invoke `param_env.with_reveal_all()`.
10811081
#[inline]
10821082
pub fn reveal_all() -> Self {
@@ -1085,7 +1085,10 @@ impl<'tcx> ParamEnv<'tcx> {
10851085

10861086
/// Construct a trait environment with the given set of predicates.
10871087
#[inline]
1088-
pub fn new(caller_bounds: &'tcx List<Clause<'tcx>>, reveal: Reveal) -> Self {
1088+
pub fn from_elaborated_clauses(
1089+
caller_bounds: &'tcx List<Clause<'tcx>>,
1090+
reveal: Reveal,
1091+
) -> Self {
10891092
ty::ParamEnv { packed: CopyTaggedPtr::new(caller_bounds, ParamTag { reveal }) }
10901093
}
10911094

@@ -1108,7 +1111,10 @@ impl<'tcx> ParamEnv<'tcx> {
11081111
return self;
11091112
}
11101113

1111-
ParamEnv::new(tcx.reveal_opaque_types_in_bounds(self.caller_bounds()), Reveal::All)
1114+
ParamEnv::from_elaborated_clauses(
1115+
tcx.reveal_opaque_types_in_bounds(self.caller_bounds()),
1116+
Reveal::All,
1117+
)
11121118
}
11131119

11141120
/// Returns this same environment but with no caller bounds.

compiler/rustc_trait_selection/src/traits/auto_trait.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,13 @@ impl<'tcx> AutoTraitFinder<'tcx> {
340340

341341
let normalized_preds =
342342
elaborate(tcx, computed_preds.clone().chain(user_computed_preds.iter().cloned()));
343-
new_env = ty::ParamEnv::new(
343+
new_env = ty::ParamEnv::from_elaborated_clauses(
344344
tcx.mk_clauses_from_iter(normalized_preds.filter_map(|p| p.as_clause())),
345345
param_env.reveal(),
346346
);
347347
}
348348

349-
let final_user_env = ty::ParamEnv::new(
349+
let final_user_env = ty::ParamEnv::from_elaborated_clauses(
350350
tcx.mk_clauses_from_iter(user_computed_preds.into_iter().filter_map(|p| p.as_clause())),
351351
user_env.reveal(),
352352
);

compiler/rustc_trait_selection/src/traits/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ pub fn normalize_param_env_or_error<'tcx>(
291291
debug!("normalize_param_env_or_error: elaborated-predicates={:?}", predicates);
292292

293293
let reveal = unnormalized_env.reveal();
294-
let eager_evaluated_env = ty::ParamEnv::new(tcx.mk_clauses(&predicates), reveal);
294+
let eager_evaluated_env =
295+
ty::ParamEnv::from_elaborated_clauses(tcx.mk_clauses(&predicates), reveal);
295296

296297
// HACK: we are trying to normalize the param-env inside *itself*. The problem is that
297298
// normalization expects its param-env to be already normalized, which means we have
@@ -335,7 +336,8 @@ pub fn normalize_param_env_or_error<'tcx>(
335336
// here. I believe they should not matter, because we are ignoring TypeOutlives param-env
336337
// predicates here anyway. Keeping them here anyway because it seems safer.
337338
let outlives_env = non_outlives_predicates.iter().chain(&outlives_predicates).cloned();
338-
let outlives_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(outlives_env), reveal);
339+
let outlives_env =
340+
ty::ParamEnv::from_elaborated_clauses(tcx.mk_clauses_from_iter(outlives_env), reveal);
339341
let Ok(outlives_predicates) =
340342
do_normalize_predicates(tcx, cause, outlives_env, outlives_predicates)
341343
else {
@@ -348,7 +350,7 @@ pub fn normalize_param_env_or_error<'tcx>(
348350
let mut predicates = non_outlives_predicates;
349351
predicates.extend(outlives_predicates);
350352
debug!("normalize_param_env_or_error: final predicates={:?}", predicates);
351-
ty::ParamEnv::new(tcx.mk_clauses(&predicates), reveal)
353+
ty::ParamEnv::from_elaborated_clauses(tcx.mk_clauses(&predicates), reveal)
352354
}
353355

354356
/// Normalize a type and process all resulting obligations, returning any errors.

compiler/rustc_trait_selection/src/traits/object_safety.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,10 @@ fn receiver_is_dispatchable<'tcx>(
767767
let caller_bounds =
768768
param_env.caller_bounds().iter().chain([unsize_predicate, trait_predicate]);
769769

770-
ty::ParamEnv::new(tcx.mk_clauses_from_iter(caller_bounds), param_env.reveal())
770+
ty::ParamEnv::from_elaborated_clauses(
771+
tcx.mk_clauses_from_iter(caller_bounds),
772+
param_env.reveal(),
773+
)
771774
};
772775

773776
// Receiver: DispatchFromDyn<Receiver[Self => U]>

compiler/rustc_ty_utils/src/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
146146

147147
let local_did = def_id.as_local();
148148

149-
let unnormalized_env = ty::ParamEnv::new(
149+
let unnormalized_env = ty::ParamEnv::from_elaborated_clauses(
150150
tcx.mk_clauses_from_iter(traits::elaborate(tcx, predicates)),
151151
traits::Reveal::UserFacing,
152152
);

src/tools/clippy/clippy_lints/src/derive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
497497
}
498498
}
499499

500-
ParamEnv::new(
500+
ParamEnv::from_elaborated_clauses(
501501
tcx.mk_clauses_from_iter(ty_predicates.iter().map(|&(p, _)| p).chain(
502502
params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| {
503503
ClauseKind::Trait(TraitPredicate {

0 commit comments

Comments
 (0)