Skip to content

dead_code lint warns about struct fields it can't actually know are dead due to C FFI #15101

Closed
@lilyball

Description

@lilyball

The dead_code lint has started warning about struct fields, in 9bb8f88. The problem is, it does this even if it can't guarantee the field is actually dead. Notably, it warns about struct fields for structs that are passed as *mut pointers to C FFI functions. In this case, my Rust code only zero-initializes the field, and never reads it because it's purely for use by the C FFI function.

This reproduces with lilyball/rust-lua@be46e268c with the lua_Debug struct (in raw.rs). It has a single private field that's used by the Lua C functions internally, and is intentionally not touched (beyond being zero-initialized) by the Rust code.

I think the solution here is for the dead_code lint to assume that any extern { fn } that takes a *mut pointer to a struct may potentially use every field of the struct, and therefore to treat any fields of structs with said C FFI functions as live regardless of whether the Rust code touches them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions