Skip to content

Commit e68e9d4

Browse files
committed
explain why DispatchFromDyn does the check it does
1 parent e001209 commit e68e9d4

File tree

1 file changed

+8
-0
lines changed
  • compiler/rustc_hir_analysis/src/coherence

1 file changed

+8
-0
lines changed

compiler/rustc_hir_analysis/src/coherence/builtin.rs

+8
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
157157
let infcx = tcx.infer_ctxt().build();
158158
let cause = ObligationCause::misc(span, impl_did);
159159

160+
// Later parts of the compiler rely on all DispatchFromDyn types to be ABI-compatible with raw
161+
// pointers. This is enforced here: we only allow impls for references, raw pointers, and things
162+
// that are effectively repr(transparent) newtypes around types that already hav a
163+
// DispatchedFromDyn impl. We cannot literally use repr(transparent) on those tpyes since some
164+
// of them support an allocator, but we ensure that for the cases where the type implements this
165+
// trait, they *do* satisfy the repr(transparent) rules, and then we assume that everything else
166+
// in the compiler (in particular, all the call ABI logic) will treat them as repr(transparent)
167+
// even if they do not carry that attribute.
160168
use rustc_type_ir::sty::TyKind::*;
161169
match (source.kind(), target.kind()) {
162170
(&Ref(r_a, _, mutbl_a), Ref(r_b, _, mutbl_b))

0 commit comments

Comments
 (0)