Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 7a83694

Browse files
b-nabercuviper
authored andcommitted
expose default substs in param_env
(cherry picked from commit c6b6901)
1 parent 2039a92 commit 7a83694

File tree

1 file changed

+12
-0
lines changed
  • compiler/rustc_ty_utils/src

1 file changed

+12
-0
lines changed

compiler/rustc_ty_utils/src/ty.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ fn trait_of_item(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
248248
}
249249

250250
/// See `ParamEnv` struct definition for details.
251+
#[instrument(level = "debug", skip(tcx))]
251252
fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
252253
// The param_env of an impl Trait type is its defining function's param_env
253254
if let Some(parent) = ty::is_impl_trait_defn(tcx, def_id) {
@@ -275,9 +276,20 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
275276
predicates.extend(environment);
276277
}
277278

279+
// It's important that we include the default substs in unevaluated
280+
// constants, since `Unevaluated` instances in predicates whose substs are None
281+
// can lead to "duplicate" caller bounds candidates during trait selection,
282+
// duplicate in the sense that both have their default substs, but the
283+
// candidate that resulted from a superpredicate still uses `None` in its
284+
// `substs_` field of `Unevaluated` to indicate that it has its default substs,
285+
// whereas the other candidate has `substs_: Some(default_substs)`, see
286+
// issue #89334
287+
predicates = tcx.expose_default_const_substs(predicates);
288+
278289
let unnormalized_env =
279290
ty::ParamEnv::new(tcx.intern_predicates(&predicates), traits::Reveal::UserFacing);
280291

292+
debug!("unnormalized_env caller bounds: {:?}", unnormalized_env.caller_bounds());
281293
let body_id = def_id
282294
.as_local()
283295
.map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))

0 commit comments

Comments
 (0)