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

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

Closed
jumbatm opened this issue Jun 29, 2020 · 1 comment · Fixed by #73990
Closed

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

jumbatm opened this issue Jun 29, 2020 · 1 comment · Fixed by #73990
Assignees
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jumbatm
Copy link
Contributor

jumbatm commented Jun 29, 2020

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.

@jumbatm jumbatm added the C-bug Category: This is a bug. label Jun 29, 2020
@jumbatm
Copy link
Contributor Author

jumbatm commented Jun 29, 2020

@rustbot claim

@rustbot rustbot self-assigned this Jun 29, 2020
@JohnTitor JohnTitor added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 5, 2020
@bors bors closed this as completed in 6b09c37 Jul 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants