Skip to content

Commit 8b06bb8

Browse files
authored
Unrolled build for rust-lang#130924
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
2 parents 150247c + 0bf9289 commit 8b06bb8

File tree

3 files changed

+76
-3
lines changed

3 files changed

+76
-3
lines changed

compiler/rustc_lint/src/foreign_modules.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ fn structurally_same_type_impl<'tcx>(
280280

281281
ensure_sufficient_stack(|| {
282282
match (a.kind(), b.kind()) {
283-
(&Adt(a_def, _), &Adt(b_def, _)) => {
283+
(&Adt(a_def, a_gen_args), &Adt(b_def, b_gen_args)) => {
284284
// Only `repr(C)` types can be compared structurally.
285285
if !(a_def.repr().c() && b_def.repr().c()) {
286286
return false;
@@ -304,8 +304,8 @@ fn structurally_same_type_impl<'tcx>(
304304
seen_types,
305305
tcx,
306306
param_env,
307-
tcx.type_of(a_did).instantiate_identity(),
308-
tcx.type_of(b_did).instantiate_identity(),
307+
tcx.type_of(a_did).instantiate(tcx, a_gen_args),
308+
tcx.type_of(b_did).instantiate(tcx, b_gen_args),
309309
ckind,
310310
)
311311
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//@ build-pass
2+
#![warn(clashing_extern_declarations)]
3+
4+
#[repr(C)]
5+
pub struct A {
6+
a: [u16; 4],
7+
}
8+
#[repr(C)]
9+
pub struct B {
10+
b: [u32; 4],
11+
}
12+
13+
pub mod a {
14+
extern "C" {
15+
pub fn foo(_: super::A);
16+
}
17+
}
18+
pub mod b {
19+
extern "C" {
20+
pub fn foo(_: super::B);
21+
//~^ WARN `foo` redeclared with a different signature
22+
}
23+
}
24+
25+
#[repr(C)]
26+
pub struct G<T> {
27+
g: [T; 4],
28+
}
29+
30+
pub mod x {
31+
extern "C" {
32+
pub fn bar(_: super::G<u16>);
33+
}
34+
}
35+
pub mod y {
36+
extern "C" {
37+
pub fn bar(_: super::G<u32>);
38+
//~^ WARN `bar` redeclared with a different signature
39+
}
40+
}
41+
42+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
warning: `foo` redeclared with a different signature
2+
--> $DIR/clashing-extern-fn-issue-130851.rs:20:9
3+
|
4+
LL | pub fn foo(_: super::A);
5+
| ------------------------ `foo` previously declared here
6+
...
7+
LL | pub fn foo(_: super::B);
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration
9+
|
10+
= note: expected `unsafe extern "C" fn(A)`
11+
found `unsafe extern "C" fn(B)`
12+
note: the lint level is defined here
13+
--> $DIR/clashing-extern-fn-issue-130851.rs:2:9
14+
|
15+
LL | #![warn(clashing_extern_declarations)]
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
18+
warning: `bar` redeclared with a different signature
19+
--> $DIR/clashing-extern-fn-issue-130851.rs:37:9
20+
|
21+
LL | pub fn bar(_: super::G<u16>);
22+
| ----------------------------- `bar` previously declared here
23+
...
24+
LL | pub fn bar(_: super::G<u32>);
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration
26+
|
27+
= note: expected `unsafe extern "C" fn(G<u16>)`
28+
found `unsafe extern "C" fn(G<u32>)`
29+
30+
warning: 2 warnings emitted
31+

0 commit comments

Comments
 (0)