Skip to content

Commit

Permalink
expose default substs in param_env
Browse files Browse the repository at this point in the history
  • Loading branch information
b-naber committed Oct 25, 2021
1 parent aa5740c commit c6b6901
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions compiler/rustc_ty_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ fn trait_of_item(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
}

/// 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) {
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit c6b6901

Please sign in to comment.