1
Fork 0

Elaborate param-env built for checking DispatchFromDyn for dyn compat

This commit is contained in:
Michael Goulet 2025-03-11 16:32:35 +00:00
parent ebf0cf75d3
commit c170d0f12f
5 changed files with 105 additions and 12 deletions

View file

@ -24,7 +24,9 @@ use super::elaborate;
use crate::infer::TyCtxtInferExt;
pub use crate::traits::DynCompatibilityViolation;
use crate::traits::query::evaluate_obligation::InferCtxtExt;
use crate::traits::{MethodViolationCode, Obligation, ObligationCause, util};
use crate::traits::{
MethodViolationCode, Obligation, ObligationCause, normalize_param_env_or_error, util,
};
/// Returns the dyn-compatibility violations that affect HIR ty lowering.
///
@ -579,8 +581,8 @@ fn receiver_is_dispatchable<'tcx>(
let unsized_receiver_ty =
receiver_for_self_ty(tcx, receiver_ty, unsized_self_ty, method.def_id);
// create a modified param env, with `Self: Unsize<U>` and `U: Trait` added to caller bounds
// `U: ?Sized` is already implied here
// create a modified param env, with `Self: Unsize<U>` and `U: Trait` (and all of
// its supertraits) added to caller bounds. `U: ?Sized` is already implied here.
let param_env = {
let param_env = tcx.param_env(method.def_id);
@ -598,10 +600,13 @@ fn receiver_is_dispatchable<'tcx>(
ty::TraitRef::new_from_args(tcx, trait_def_id, args).upcast(tcx)
};
let caller_bounds =
param_env.caller_bounds().iter().chain([unsize_predicate, trait_predicate]);
ty::ParamEnv::new(tcx.mk_clauses_from_iter(caller_bounds))
normalize_param_env_or_error(
tcx,
ty::ParamEnv::new(tcx.mk_clauses_from_iter(
param_env.caller_bounds().iter().chain([unsize_predicate, trait_predicate]),
)),
ObligationCause::dummy_with_span(tcx.def_span(method.def_id)),
)
};
// Receiver: DispatchFromDyn<Receiver[Self => U]>