@@ -2250,24 +2250,27 @@ If you encounter an error missing from this list, please file an issue or a PR!"
2250
2250
// Sized integer types from <stdint.h> get mapped to Rust primitive
2251
2251
// types regardless of whether they are blocklisted, so ensure that
2252
2252
// standard traits are considered derivable for them too.
2253
- None => match name {
2254
- "int8_t" | "uint8_t" | "int16_t" | "uint16_t" |
2255
- "int32_t" | "uint32_t" | "int64_t" |
2256
- "uint64_t" | "uintptr_t" | "intptr_t" |
2257
- "ptrdiff_t" => Some ( CanDerive :: Yes ) ,
2258
- "size_t" if self . options . size_t_is_usize => {
2259
- Some ( CanDerive :: Yes )
2260
- }
2261
- "ssize_t" if self . options . size_t_is_usize => {
2262
- Some ( CanDerive :: Yes )
2263
- }
2264
- _ => Some ( CanDerive :: No ) ,
2265
- } ,
2253
+ None => Some ( if self . is_stdint_type ( name) {
2254
+ CanDerive :: Yes
2255
+ } else {
2256
+ CanDerive :: No
2257
+ } ) ,
2266
2258
} )
2267
2259
. unwrap_or ( CanDerive :: No )
2268
2260
} )
2269
2261
}
2270
2262
2263
+ /// Is the given type a type from <stdint.h> that corresponds to a Rust primitive type?
2264
+ pub fn is_stdint_type ( & self , name : & str ) -> bool {
2265
+ match name {
2266
+ "int8_t" | "uint8_t" | "int16_t" | "uint16_t" | "int32_t" |
2267
+ "uint32_t" | "int64_t" | "uint64_t" | "uintptr_t" |
2268
+ "intptr_t" | "ptrdiff_t" => true ,
2269
+ "size_t" | "ssize_t" => self . options . size_t_is_usize ,
2270
+ _ => false ,
2271
+ }
2272
+ }
2273
+
2271
2274
/// Get a reference to the set of items we should generate.
2272
2275
pub fn codegen_items ( & self ) -> & ItemSet {
2273
2276
assert ! ( self . in_codegen_phase( ) ) ;
@@ -2355,7 +2358,10 @@ If you encounter an error missing from this list, please file an issue or a PR!"
2355
2358
TypeKind :: Opaque |
2356
2359
TypeKind :: TypeParam => return true ,
2357
2360
_ => { }
2358
- } ;
2361
+ }
2362
+ if self . is_stdint_type ( & name) {
2363
+ return true ;
2364
+ }
2359
2365
}
2360
2366
2361
2367
// Unnamed top-level enums are special and we
0 commit comments