From c6b69017e21610b1ef491c028697728fbd3f581a Mon Sep 17 00:00:00 2001 From: b-naber Date: Mon, 25 Oct 2021 15:34:59 +0200 Subject: [PATCH] expose default substs in param_env --- compiler/rustc_ty_utils/src/ty.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index bc77c94809eb..af3706f886e9 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -247,6 +247,7 @@ fn trait_of_item(tcx: TyCtxt<'_>, def_id: DefId) -> Option { } /// See `ParamEnv` struct definition for details. +#[instrument(level = "debug", skip(tcx))] fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> { // The param_env of an impl Trait type is its defining function's param_env if let Some(parent) = ty::is_impl_trait_defn(tcx, def_id) { @@ -274,9 +275,20 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> { predicates.extend(environment); } + // It's important that we include the default substs in unevaluated + // constants, since `Unevaluated` instances in predicates whose substs are None + // can lead to "duplicate" caller bounds candidates during trait selection, + // duplicate in the sense that both have their default substs, but the + // candidate that resulted from a superpredicate still uses `None` in its + // `substs_` field of `Unevaluated` to indicate that it has its default substs, + // whereas the other candidate has `substs_: Some(default_substs)`, see + // issue #89334 + predicates = tcx.expose_default_const_substs(predicates); + let unnormalized_env = ty::ParamEnv::new(tcx.intern_predicates(&predicates), traits::Reveal::UserFacing); + debug!("unnormalized_env caller bounds: {:?}", unnormalized_env.caller_bounds()); let body_id = def_id .as_local() .map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))