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

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

Closed
tmiasko opened this issue Sep 25, 2024 · 1 comment · Fixed by #130924
Closed

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

tmiasko opened this issue Sep 25, 2024 · 1 comment · Fixed by #130924
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lint 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.

Comments

@tmiasko
Copy link
Contributor

tmiasko commented Sep 25, 2024

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
@tmiasko tmiasko added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. labels Sep 25, 2024
@surechen
Copy link
Contributor

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Sep 28, 2024
…rors

Make clashing_extern_declarations considering generic args for ADT field

In following example, G<u16> should be recognized as different from G<u32> :

```rust
#[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>); } }
```

fixes rust-lang#130851
@bors bors closed this as completed in 0bf9289 Sep 28, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 28, 2024
Rollup merge of rust-lang#130924 - surechen:fix_130851, r=compiler-errors

Make clashing_extern_declarations considering generic args for ADT field

In following example, G<u16> should be recognized as different from G<u32> :

```rust
#[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>); } }
```

fixes rust-lang#130851
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lint 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants