Skip to content

Missing clashing extern declaration warning when using generic data types #130851

Closed

Description

Code

#[repr(C)] pub struct A { a: [u16; 4] }
#[repr(C)] pub struct B { b: [u32; 4] }

pub mod a { extern "C" { pub fn f(_: super::A); } }
pub mod b { extern "C" { pub fn f(_: super::B); } }

#[repr(C)] pub struct G<T> { g: [T; 4] }

pub mod x { extern "C" { pub fn g(_: super::G<u16>); } }
pub mod y { extern "C" { pub fn g(_: super::G<u32>); } }

Current output

warning: `f` redeclared with a different signature
 --> a.rs:5:26
  |
4 | pub mod a { extern "C" { pub fn f(_: super::A); } }
  |                          ---------------------- `f` previously declared here
5 | pub mod b { extern "C" { pub fn f(_: super::B); } }
  |                          ^^^^^^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration
  |
  = note: expected `unsafe extern "C" fn(A)`
             found `unsafe extern "C" fn(B)`
  = note: `#[warn(clashing_extern_declarations)]` on by default

Desired output

warning: `f` redeclared with a different signature
 --> a.rs:5:26
  |
4 | pub mod a { extern "C" { pub fn f(_: super::A); } }
  |                          ---------------------- `f` previously declared here
5 | pub mod b { extern "C" { pub fn f(_: super::B); } }
  |                          ^^^^^^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration
  |
  = note: expected `unsafe extern "C" fn(A)`
             found `unsafe extern "C" fn(B)`
  = note: `#[warn(clashing_extern_declarations)]` on by default
warning: `g` redeclared with a different signature
 --> a.rs:5:26
  |
9 | pub mod a { extern "C" { pub fn g(_: super::G<u16>); } }
  |                          ---------------------- `g` previously declared here
10| pub mod b { extern "C" { pub fn g(_: super::G<u32>); } }
  |                          ^^^^^^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration
  |
  = note: expected `unsafe extern "C" fn(G<u16>)`
             found `unsafe extern "C" fn(G<u32>)`

Rust Version

$ rustc --version --verbose
rustc 1.83.0-nightly (363ae4188 2024-09-24)
binary: rustc
commit-hash: 363ae4188316b8b22cf6c1890bc73d84d05f70a4
commit-date: 2024-09-24
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintArea: Lints (warnings about flaws in source code) such as unused_mut.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