Auto merge of #115699 - RalfJung:interpret-abi-compat, r=oli-obk

interpret: change ABI-compat test to be type-based

This makes the test consistent across targets. Otherwise the chances are very high that ABI mismatches get accepted on x86_64 but still fail on many other targets with more complicated ABIs.

This implements (most of) the rules described in https://github.com/rust-lang/rust/pull/115476.
This commit is contained in:
bors 2023-09-12 03:34:55 +00:00
commit 366dab13f7
13 changed files with 270 additions and 116 deletions

View file

@ -157,6 +157,14 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
let infcx = tcx.infer_ctxt().build();
let cause = ObligationCause::misc(span, impl_did);
// Later parts of the compiler rely on all DispatchFromDyn types to be ABI-compatible with raw
// pointers. This is enforced here: we only allow impls for references, raw pointers, and things
// that are effectively repr(transparent) newtypes around types that already hav a
// DispatchedFromDyn impl. We cannot literally use repr(transparent) on those tpyes since some
// of them support an allocator, but we ensure that for the cases where the type implements this
// trait, they *do* satisfy the repr(transparent) rules, and then we assume that everything else
// in the compiler (in particular, all the call ABI logic) will treat them as repr(transparent)
// even if they do not carry that attribute.
use rustc_type_ir::sty::TyKind::*;
match (source.kind(), target.kind()) {
(&Ref(r_a, _, mutbl_a), Ref(r_b, _, mutbl_b))