Skip to content

Check transmute restrictions in the crate where it is used #12898

Closed
@brson

Description

@brson

The transmute function is peculiar in that it has extra restrictions on its type parameters that are not checked until translation time. This can result in surprises for downstream users of code that uses transmute. Instead we should type check its instantiation when called or its value is taken. Doing this will require at least one new restriction.

During type check:

  • Validate that generic types are only transmuted through pointers
    • this ensures that all uses can be validated in the context of the local trait
    • todo: we have fat and thin pointers, so this would seem insufficient
  • Validate that both types are Sized or the same type
  • Record all pairs of transmuted types

During translation (of the crate where transmute is used):

  • Check that all instantiations used types with the same type
  • Warn if any instantiations used types with different alignment

@nikomatsakis Does this sound right? What about the fat/thin pointer issue?

Nominating.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions