11// check-pass 
22// aux-build:external_extern_fn.rs 
33#![ crate_type = "lib" ]  
4- #![ warn( clashing_extern_decl ) ]  
4+ #![ warn( clashing_extern_declarations ) ]  
55
66extern  crate  external_extern_fn; 
77
8- extern  { 
8+ extern  "C"   { 
99    fn  clash ( x :  u8 ) ; 
1010    fn  no_clash ( x :  u8 ) ; 
1111} 
1212
1313fn  redeclared_different_signature ( )  { 
14-     extern  { 
14+     extern  "C"   { 
1515        fn  clash ( x :  u64 ) ;  //~ WARN `clash` redeclared with a different signature 
1616    } 
1717
@@ -22,20 +22,20 @@ fn redeclared_different_signature() {
2222} 
2323
2424fn  redeclared_same_signature ( )  { 
25-     extern  { 
25+     extern  "C"   { 
2626        fn  no_clash ( x :  u8 ) ; 
2727    } 
2828    unsafe  { 
2929        no_clash ( 123 ) ; 
3030    } 
3131} 
3232
33- extern  { 
33+ extern  "C"   { 
3434    fn  extern_fn ( x :  u64 ) ; 
3535} 
3636
3737fn  extern_clash ( )  { 
38-     extern  { 
38+     extern  "C"   { 
3939        fn  extern_fn ( x :  u32 ) ;  //~ WARN `extern_fn` redeclared with a different signature 
4040    } 
4141    unsafe  { 
@@ -49,7 +49,7 @@ fn extern_no_clash() {
4949        crate :: extern_fn ( 123 ) ; 
5050    } 
5151} 
52- extern  { 
52+ extern  "C"   { 
5353    fn  some_other_new_name ( x :  i16 ) ; 
5454
5555    #[ link_name = "extern_link_name" ]  
@@ -60,7 +60,7 @@ extern {
6060} 
6161
6262fn  link_name_clash ( )  { 
63-     extern  { 
63+     extern  "C"   { 
6464        fn  extern_link_name ( x :  u32 ) ; 
6565        //~^ WARN `extern_link_name` redeclared with a different signature 
6666
@@ -75,85 +75,112 @@ fn link_name_clash() {
7575} 
7676
7777mod  a { 
78-     extern  { 
78+     extern  "C"   { 
7979        fn  different_mod ( x :  u8 ) ; 
8080    } 
8181} 
8282mod  b { 
83-     extern  { 
83+     extern  "C"   { 
8484        fn  different_mod ( x :  u64 ) ;  //~ WARN `different_mod` redeclared with a different signature 
8585    } 
8686} 
8787
88- extern  { 
88+ extern  "C"   { 
8989    fn  variadic_decl ( x :  u8 ,  ...) ; 
9090} 
9191
9292fn  variadic_clash ( )  { 
93-     extern  { 
93+     extern  "C"   { 
9494        fn  variadic_decl ( x :  u8 ) ;  //~ WARN `variadic_decl` redeclared with a different signature 
9595    } 
9696} 
9797
9898#[ no_mangle]  
99- fn  no_mangle_name ( x :  u8 )  {   } 
99+ fn  no_mangle_name ( x :  u8 )  { } 
100100
101- extern  { 
101+ extern  "C"   { 
102102    #[ link_name = "unique_link_name" ]  
103103    fn  link_name_specified ( x :  u8 ) ; 
104104} 
105105
106106fn  tricky_no_clash ( )  { 
107-     extern  { 
107+     extern  "C"   { 
108108        // Shouldn't warn, because the declaration above actually declares a different symbol (and 
109109        // Rust's name resolution rules around shadowing will handle this gracefully). 
110110        fn  link_name_specified ( )  -> u32 ; 
111111
112112        // 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. 
115115        fn  no_mangle_name ( )  -> u32 ; 
116116    } 
117117} 
118118
119119mod  banana { 
120120    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+         } 
123129    } 
124130
125131    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+         } 
130142    } 
131143
132144    mod  three { 
133145        // This _should_ trigger the lint, because repr(packed) should generate a struct that has a 
134146        // different layout. 
135-         #[ repr( packed) ]   struct  Banana  {  weight :  u32 ,  length :  u16  } 
147+         #[ repr( packed) ]  
148+         struct  Banana  { 
149+             weight :  u32 , 
150+             length :  u16 , 
151+         } 
136152        #[ 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+         } 
139157    } 
140158} 
141159
142160mod  sameish_members { 
143161    mod  a { 
144162        #[ repr( C ) ]  
145-         struct  Point  {  x :  i16 ,  y :  i16  } 
163+         struct  Point  { 
164+             x :  i16 , 
165+             y :  i16 , 
166+         } 
146167
147-         extern  "C"  {  fn  draw_point ( p :  Point ) ;  } 
168+         extern  "C"  { 
169+             fn  draw_point ( p :  Point ) ; 
170+         } 
148171    } 
149172    mod  b { 
150173        #[ repr( C ) ]  
151-         struct  Point  {  coordinates :  [ i16 ;  2 ]  } 
174+         struct  Point  { 
175+             coordinates :  [ i16 ;  2 ] , 
176+         } 
152177
153178        // It's possible we are overconservative for this case, as accessing the elements of the 
154179        // coordinates array might end up correctly accessing `.x` and `.y`. However, this may not 
155180        // always be the case, for every architecture and situation. This is also a really odd 
156181        // 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+         } 
158185    } 
159186} 
0 commit comments