Skip to content

Warn on pointer cast with type inference #7028

Open
@tiago-lqt

Description

@tiago-lqt

What it does

Lint should warn when casts using type inference are being used on pointers types.

Recently we had a bug on a FFI boundary where a *const T was being cast with self.inner() as *mut _ when calling a C function with signature sys::foo(T**), but inner function is defined as fn inner() -> *const T.
This lead to passing a pointer as pointer to pointer, and the application crashing at runtime.

Categories (optional)

  • Kind: clippy::correctness, clippy::pedantic

Original code might be buggy. Intent is to have a mechanism that warns or errors when such a code is found on particular scenarios, specifically for our case in code involving the FFI boundary.

Drawbacks

Might get annoying for most use cases, thats why it was suggested also as pedantic linter.

Example

sys::foo(self.inner() as *mut _);

Could be written as:

sys::foo(self.inner() as *mut T);

In this case code would fail to compile, but provides us the chance to catch and fix the error at compile time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions