Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improper ctypes: normalize return types and transparent structs #72890

Commits on Jun 9, 2020

  1. improper_ctypes: add test for rust-lang#66202

    This commit adds a test of the improper ctypes lint, checking that
    return type are normalized bethat return types are normalized before
    being checked for FFI-safety, and that transparent newtype wrappers
    are FFI-safe if the type being wrapped is FFI-safe.
    
    Signed-off-by: David Wood <david@davidtw.co>
    davidtwco committed Jun 9, 2020
    Configuration menu
    Copy the full SHA
    a8640cd View commit details
    Browse the repository at this point in the history
  2. lint: check for unit ret type after normalization

    This commit moves the check that skips unit return types to after
    where the return type has been normalized - therefore ensuring that
    FFI-safety lints are not emitted for types which normalize to unit.
    
    Signed-off-by: David Wood <david@davidtw.co>
    davidtwco committed Jun 9, 2020
    Configuration menu
    Copy the full SHA
    3e7aabb View commit details
    Browse the repository at this point in the history
  3. lint: transitive FFI-safety for transparent types

    This commit ensures that if a `repr(transparent)` newtype's only
    non-zero-sized field is FFI-safe then the newtype is also FFI-safe.
    
    Previously, ZSTs were ignored for the purposes of linting FFI-safety
    in transparent structs - thus, only the single non-ZST would be checked
    for FFI-safety. However, if the non-zero-sized field is a generic
    parameter, and is substituted for a ZST, then the type would be
    considered FFI-unsafe (as when every field is thought to be zero-sized,
    the type is considered to be "composed only of `PhantomData`" which is
    FFI-unsafe).
    
    In this commit, for transparent structs, the non-zero-sized field is
    identified (before any substitutions are applied, necessarily) and then
    that field's type (now with substitutions) is checked for FFI-safety
    (where previously it would have been skipped for being zero-sized in
    this case).
    
    To handle the case where the non-zero-sized field is a generic
    parameter, which is substituted for `()` (a ZST), and is being used
    as a return type - the `FfiUnsafe` result (previously `FfiPhantom`) is
    caught and silenced.
    
    Signed-off-by: David Wood <david@davidtw.co>
    davidtwco committed Jun 9, 2020
    Configuration menu
    Copy the full SHA
    d4d3d7d View commit details
    Browse the repository at this point in the history