Skip to main content

to_clang_disc_ty

Function to_clang_disc_ty 

Source
fn to_clang_disc_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ClangDiscTy<'tcx>
Expand description

Lowers a Rust type into a Clang-compatible discriminator type.

This is not a full semantic translation of Rust types. It is a lossy mapping that intentionally matches Clang’s function pointer authentication encoding rules where Rust has a direct language-level equivalent.

In particular C _Complex, without a canonical Rust equivalent, is not recognized. This avoids introducing heuristics for user-defined representations that may vary across codebases.

Important invariants:

  • All pointer-like types (Rust refs, raw pointers, fn pointers) collapse to Pointer.
  • Struct/union types are encoded using name only, not layout.
  • Enums are treated as integers.
  • SIMD types are encoded only by total byte size (no lane semantics).
  • No attempt is made to recognize user-defined representations of C _Complex types. This must remain in sync with Clang’s encodeTypeForFunctionPointerAuth.