validate_trivial_unsize in rustc_codegen_ssa::base - Rust
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.

Skip to main content

## validate_trivial_unsize

# 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.