Skip to content

clashing_extern_declarations misses clashes of same-sized members of structs #73872

Closed
@jumbatm

Description

@jumbatm

The clashing_extern_declarations lint currently incorrectly misses clashing extern fn declarations if they clash on a struct with same-sized members.

In this example here:

#![crate_type = "lib"]
#![allow(unused)]

mod a {
    #[repr(C)]
    struct Point3 {
        x: f32,
        y: f32,
        z: f32,
    }
    extern "C" { fn origin() -> Point3; }
}
mod b {
    #[repr(C)]
    struct Point3 {
        x: i32,
        y: i32,
        z: i32, // NOTE: Incorrectly redeclared as i32
    }
    extern "C" { fn origin() -> Point3; }
}

(Playground)

The declaration of origin should clash, because a::Point3 and b::Point3 have members of different type. However, the lint currently misses that the return type of origin is inconsistently declared, even though ani32 and f32 clash is warned on its own:

mod a {
    extern "C" { fn clash(x: i32); }
}
mod b {
    extern "C" { fn clash(x: f32); } //~ WARN `clash` redeclared with a different signature
}

Note that this false negative only occurs for same-sized members -- the lint correctly fires for members of different sizes:

mod a {
    #[repr(C)]
    struct Point3 {
        x: f32,
        y: f32,
        z: f32,
    }
    extern "C" { fn origin() -> Point3; }
}
mod b {
    #[repr(C)]
    struct Point3 {
        x: i64,
        y: i64,
        z: i64,
    }
    extern "C" { fn origin() -> Point3; }
    //~^ WARN `origin` redeclared with a different signature
}

This issue has been assigned to @jumbatm via this comment.

Metadata

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions