rustc_codegen_ssa::base

Function validate_trivial_unsize

source
pub fn validate_trivial_unsize<'tcx>(
    tcx: TyCtxt<'tcx>,
    source_data: &'tcx List<PolyExistentialPredicate<'tcx>>,
    target_data: &'tcx List<PolyExistentialPredicate<'tcx>>,
) -> bool
Expand description

Codegen takes advantage of the additional assumption, where if the principal trait def id of what’s being casted doesn’t change, then we don’t need to adjust the vtable at all. This corresponds to the fact that dyn Tr<A>: Unsize<dyn Tr<B>> requires that A = B; we don’t allow upcasting objects between the same trait with different args. If we, for some reason, were to relax the Unsize trait, it could become unsound, so let’s validate here that the trait refs are subtypes.