@@ -529,6 +529,7 @@ pub enum Stmt {
529
529
body : Option < ( ) > ,
530
530
safe : bool ,
531
531
must_use : bool ,
532
+ link_name : Option < String > ,
532
533
} ,
533
534
/// typedef Type TypedefName;
534
535
AliasDecl {
@@ -1059,7 +1060,10 @@ impl Stmt {
1059
1060
| EntityKind :: ParmDecl
1060
1061
| EntityKind :: EnumDecl
1061
1062
| EntityKind :: IntegerLiteral => { }
1062
- _ => error ! ( "unknown" ) ,
1063
+ EntityKind :: ObjCIndependentClass => {
1064
+ // TODO: Might be interesting?
1065
+ }
1066
+ _ => error ! ( "unknown typedef child" ) ,
1063
1067
} ) ;
1064
1068
1065
1069
let ty = entity
@@ -1212,7 +1216,19 @@ impl Stmt {
1212
1216
immediate_children ( & entity, |entity, _span| match entity. get_kind ( ) {
1213
1217
EntityKind :: UnexposedAttr => {
1214
1218
if let Some ( attr) = UnexposedAttr :: parse ( & entity, context) {
1215
- error ! ( ?attr, "unknown attribute on enum constant" ) ;
1219
+ match attr {
1220
+ UnexposedAttr :: Enum
1221
+ | UnexposedAttr :: Options
1222
+ | UnexposedAttr :: ClosedEnum
1223
+ | UnexposedAttr :: ErrorEnum => {
1224
+ if kind. as_ref ( ) != Some ( & attr) {
1225
+ error ! ( ?kind, ?attr, "enum child had attribute that parent did not" ) ;
1226
+ }
1227
+ }
1228
+ attr => {
1229
+ error ! ( ?attr, "unknown attribute on enum constant" )
1230
+ }
1231
+ }
1216
1232
}
1217
1233
}
1218
1234
EntityKind :: VisibilityAttr => { }
@@ -1367,6 +1383,7 @@ impl Stmt {
1367
1383
let result_type = Ty :: parse_function_return ( result_type, context) ;
1368
1384
let mut arguments = Vec :: new ( ) ;
1369
1385
let mut must_use = false ;
1386
+ let mut link_name = None ;
1370
1387
1371
1388
if entity. is_static_method ( ) {
1372
1389
warn ! ( "unexpected static method" ) ;
@@ -1402,10 +1419,20 @@ impl Stmt {
1402
1419
EntityKind :: WarnUnusedResultAttr => {
1403
1420
must_use = true ;
1404
1421
}
1405
- EntityKind :: PureAttr => {
1422
+ EntityKind :: PureAttr | EntityKind :: ConstAttr => {
1406
1423
// Ignore, we currently have no way of marking
1407
1424
// external functions as pure in Rust.
1408
1425
}
1426
+ EntityKind :: AsmLabelAttr => {
1427
+ let name = entity. get_name ( ) . expect ( "asm label to have name" ) ;
1428
+ let name = if let Some ( name) = name. strip_prefix ( '_' ) {
1429
+ name. to_string ( )
1430
+ } else {
1431
+ error ! ( ?name, "symbol did not start with _" ) ;
1432
+ name
1433
+ } ;
1434
+ link_name = Some ( name) ;
1435
+ }
1409
1436
EntityKind :: VisibilityAttr => {
1410
1437
// CG_EXTERN or UIKIT_EXTERN
1411
1438
}
@@ -1426,6 +1453,7 @@ impl Stmt {
1426
1453
body,
1427
1454
safe: !data. unsafe_,
1428
1455
must_use,
1456
+ link_name,
1429
1457
} ]
1430
1458
}
1431
1459
EntityKind :: UnionDecl => {
@@ -2360,6 +2388,7 @@ impl Stmt {
2360
2388
body : Some ( _) ,
2361
2389
safe : _,
2362
2390
must_use : _,
2391
+ link_name : _,
2363
2392
} => {
2364
2393
write ! ( f, "// TODO: " ) ?;
2365
2394
write ! ( f, "pub fn {}(" , id. name) ?;
@@ -2377,6 +2406,7 @@ impl Stmt {
2377
2406
body : None ,
2378
2407
safe : false ,
2379
2408
must_use,
2409
+ link_name,
2380
2410
} => {
2381
2411
// Functions are always C-unwind, since we don't know
2382
2412
// anything about them.
@@ -2387,6 +2417,9 @@ impl Stmt {
2387
2417
if * must_use {
2388
2418
writeln ! ( f, " #[must_use]" ) ?;
2389
2419
}
2420
+ if let Some ( link_name) = link_name {
2421
+ writeln ! ( f, " #[link_name = {link_name:?}]" ) ?;
2422
+ }
2390
2423
write ! ( f, " pub fn {}(" , id. name) ?;
2391
2424
for ( param, arg_ty) in arguments {
2392
2425
let param = handle_reserved ( & crate :: to_snake_case ( param) ) ;
@@ -2405,6 +2438,7 @@ impl Stmt {
2405
2438
body : None ,
2406
2439
safe : true ,
2407
2440
must_use,
2441
+ link_name,
2408
2442
} => {
2409
2443
write ! ( f, "{}" , self . cfg_gate_ln( config) ) ?;
2410
2444
write ! ( f, "{availability}" ) ?;
@@ -2421,6 +2455,9 @@ impl Stmt {
2421
2455
2422
2456
writeln ! ( f, " extern \" C-unwind\" {{" ) ?;
2423
2457
2458
+ if let Some ( link_name) = link_name {
2459
+ writeln ! ( f, " #[link_name = {link_name:?}]" ) ?;
2460
+ }
2424
2461
write ! ( f, " fn {}(" , id. name) ?;
2425
2462
for ( param, arg_ty) in arguments {
2426
2463
let param = handle_reserved ( & crate :: to_snake_case ( param) ) ;
0 commit comments