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

lint/ctypes: fix () return type checks #113457

Merged
merged 3 commits into from
Jul 26, 2023

Commits on Jul 19, 2023

  1. lint/ctypes: stricter () return type checks

    `()` is normally FFI-unsafe, but is FFI-safe when used as a return type.
    It is also desirable that a transparent newtype for `()` is FFI-safe when
    used as a return type.
    
    In order to support this, when an type was deemed FFI-unsafe, because of
    a `()` type, and was used in return type - then the type was considered
    FFI-safe. However, this was the wrong approach - it didn't check that the
    `()` was part of a transparent newtype! The consequence of this is that
    the presence of a `()` type in a more complex return type would make it
    the entire type be considered safe (as long as the `()` type was the
    first that the lint found) - which is obviously incorrect.
    
    Instead, this logic is removed, and a unit return type or a transparent
    wrapper around a unit is checked for directly for functions and fn-ptrs.
    
    Signed-off-by: David Wood <[email protected]>
    davidtwco committed Jul 19, 2023
    Configuration menu
    Copy the full SHA
    f53cef3 View commit details
    Browse the repository at this point in the history
  2. lint: refactor check_variant_for_ffi

    Simplify this function a bit, it was quite hard to reason about.
    
    Signed-off-by: David Wood <[email protected]>
    davidtwco committed Jul 19, 2023
    Configuration menu
    Copy the full SHA
    99b1897 View commit details
    Browse the repository at this point in the history
  3. lint/ctypes: allow () within types

    Consider `()` within types to be FFI-safe, and `()` to be FFI-safe as a
    return type (incl. when in a transparent newtype).
    
    Signed-off-by: David Wood <[email protected]>
    davidtwco committed Jul 19, 2023
    Configuration menu
    Copy the full SHA
    24f90fd View commit details
    Browse the repository at this point in the history