1
1
// check-pass
2
2
// aux-build:external_extern_fn.rs
3
3
#![ crate_type = "lib" ]
4
- #![ warn( clashing_extern_decl ) ]
4
+ #![ warn( clashing_extern_declarations ) ]
5
5
6
6
extern crate external_extern_fn;
7
7
8
- extern {
8
+ extern "C" {
9
9
fn clash ( x : u8 ) ;
10
10
fn no_clash ( x : u8 ) ;
11
11
}
12
12
13
13
fn redeclared_different_signature ( ) {
14
- extern {
14
+ extern "C" {
15
15
fn clash ( x : u64 ) ; //~ WARN `clash` redeclared with a different signature
16
16
}
17
17
@@ -22,20 +22,20 @@ fn redeclared_different_signature() {
22
22
}
23
23
24
24
fn redeclared_same_signature ( ) {
25
- extern {
25
+ extern "C" {
26
26
fn no_clash ( x : u8 ) ;
27
27
}
28
28
unsafe {
29
29
no_clash ( 123 ) ;
30
30
}
31
31
}
32
32
33
- extern {
33
+ extern "C" {
34
34
fn extern_fn ( x : u64 ) ;
35
35
}
36
36
37
37
fn extern_clash ( ) {
38
- extern {
38
+ extern "C" {
39
39
fn extern_fn ( x : u32 ) ; //~ WARN `extern_fn` redeclared with a different signature
40
40
}
41
41
unsafe {
@@ -49,7 +49,7 @@ fn extern_no_clash() {
49
49
crate :: extern_fn ( 123 ) ;
50
50
}
51
51
}
52
- extern {
52
+ extern "C" {
53
53
fn some_other_new_name ( x : i16 ) ;
54
54
55
55
#[ link_name = "extern_link_name" ]
@@ -60,7 +60,7 @@ extern {
60
60
}
61
61
62
62
fn link_name_clash ( ) {
63
- extern {
63
+ extern "C" {
64
64
fn extern_link_name ( x : u32 ) ;
65
65
//~^ WARN `extern_link_name` redeclared with a different signature
66
66
@@ -75,85 +75,112 @@ fn link_name_clash() {
75
75
}
76
76
77
77
mod a {
78
- extern {
78
+ extern "C" {
79
79
fn different_mod ( x : u8 ) ;
80
80
}
81
81
}
82
82
mod b {
83
- extern {
83
+ extern "C" {
84
84
fn different_mod ( x : u64 ) ; //~ WARN `different_mod` redeclared with a different signature
85
85
}
86
86
}
87
87
88
- extern {
88
+ extern "C" {
89
89
fn variadic_decl ( x : u8 , ...) ;
90
90
}
91
91
92
92
fn variadic_clash ( ) {
93
- extern {
93
+ extern "C" {
94
94
fn variadic_decl ( x : u8 ) ; //~ WARN `variadic_decl` redeclared with a different signature
95
95
}
96
96
}
97
97
98
98
#[ no_mangle]
99
- fn no_mangle_name ( x : u8 ) { }
99
+ fn no_mangle_name ( x : u8 ) { }
100
100
101
- extern {
101
+ extern "C" {
102
102
#[ link_name = "unique_link_name" ]
103
103
fn link_name_specified ( x : u8 ) ;
104
104
}
105
105
106
106
fn tricky_no_clash ( ) {
107
- extern {
107
+ extern "C" {
108
108
// Shouldn't warn, because the declaration above actually declares a different symbol (and
109
109
// Rust's name resolution rules around shadowing will handle this gracefully).
110
110
fn link_name_specified ( ) -> u32 ;
111
111
112
112
// The case of a no_mangle name colliding with an extern decl (see #28179) is related but
113
- // shouldn't be reported by ClashingExternDecl , because this is an example of unmangled
114
- // name clash causing bad behaviour in functions with a defined body.
113
+ // shouldn't be reported by ClashingExternDeclarations , because this is an example of
114
+ // unmangled name clash causing bad behaviour in functions with a defined body.
115
115
fn no_mangle_name ( ) -> u32 ;
116
116
}
117
117
}
118
118
119
119
mod banana {
120
120
mod one {
121
- #[ repr( C ) ] struct Banana { weight : u32 , length : u16 }
122
- extern "C" { fn weigh_banana ( count : * const Banana ) -> u64 ; }
121
+ #[ repr( C ) ]
122
+ struct Banana {
123
+ weight : u32 ,
124
+ length : u16 ,
125
+ }
126
+ extern "C" {
127
+ fn weigh_banana ( count : * const Banana ) -> u64 ;
128
+ }
123
129
}
124
130
125
131
mod two {
126
- #[ repr( C ) ] struct Banana { weight : u32 , length : u16 } // note: distinct type
127
- // This should not trigger the lint because two::Banana is structurally equivalent to
128
- // one::Banana.
129
- extern "C" { fn weigh_banana ( count : * const Banana ) -> u64 ; }
132
+ #[ repr( C ) ]
133
+ struct Banana {
134
+ weight : u32 ,
135
+ length : u16 ,
136
+ } // note: distinct type
137
+ extern "C" {
138
+ // This should not trigger the lint because two::Banana is structurally equivalent to
139
+ // one::Banana.
140
+ fn weigh_banana ( count : * const Banana ) -> u64 ;
141
+ }
130
142
}
131
143
132
144
mod three {
133
145
// This _should_ trigger the lint, because repr(packed) should generate a struct that has a
134
146
// different layout.
135
- #[ repr( packed) ] struct Banana { weight : u32 , length : u16 }
147
+ #[ repr( packed) ]
148
+ struct Banana {
149
+ weight : u32 ,
150
+ length : u16 ,
151
+ }
136
152
#[ allow( improper_ctypes) ]
137
- extern "C" { fn weigh_banana ( count : * const Banana ) -> u64 ; }
138
- //~^ WARN `weigh_banana` redeclared with a different signature
153
+ extern "C" {
154
+ fn weigh_banana ( count : * const Banana ) -> u64 ;
155
+ //~^ WARN `weigh_banana` redeclared with a different signature
156
+ }
139
157
}
140
158
}
141
159
142
160
mod sameish_members {
143
161
mod a {
144
162
#[ repr( C ) ]
145
- struct Point { x : i16 , y : i16 }
163
+ struct Point {
164
+ x : i16 ,
165
+ y : i16 ,
166
+ }
146
167
147
- extern "C" { fn draw_point ( p : Point ) ; }
168
+ extern "C" {
169
+ fn draw_point ( p : Point ) ;
170
+ }
148
171
}
149
172
mod b {
150
173
#[ repr( C ) ]
151
- struct Point { coordinates : [ i16 ; 2 ] }
174
+ struct Point {
175
+ coordinates : [ i16 ; 2 ] ,
176
+ }
152
177
153
178
// It's possible we are overconservative for this case, as accessing the elements of the
154
179
// coordinates array might end up correctly accessing `.x` and `.y`. However, this may not
155
180
// always be the case, for every architecture and situation. This is also a really odd
156
181
// thing to do anyway.
157
- extern "C" { fn draw_point ( p : Point ) ; } //~ WARN `draw_point` redeclared with a different
182
+ extern "C" {
183
+ fn draw_point ( p : Point ) ; //~ WARN `draw_point` redeclared with a different
184
+ }
158
185
}
159
186
}
0 commit comments