Skip to content

Commit 8f0f751

Browse files
committed
Don't traverse through special-cased <stdint.h> types.
1 parent b5ec18e commit 8f0f751

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

src/ir/context.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,24 +2250,28 @@ If you encounter an error missing from this list, please file an issue or a PR!"
22502250
// Sized integer types from <stdint.h> get mapped to Rust primitive
22512251
// types regardless of whether they are blocklisted, so ensure that
22522252
// 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+
}),
22662258
})
22672259
.unwrap_or(CanDerive::No)
22682260
})
22692261
}
22702262

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" |
2267+
"int32_t" | "uint32_t" | "int64_t" |
2268+
"uint64_t" | "uintptr_t" | "intptr_t" |
2269+
"ptrdiff_t" => true,
2270+
"size_t" | "ssize_t" => self.options.size_t_is_usize,
2271+
_ => false,
2272+
}
2273+
}
2274+
22712275
/// Get a reference to the set of items we should generate.
22722276
pub fn codegen_items(&self) -> &ItemSet {
22732277
assert!(self.in_codegen_phase());
@@ -2355,7 +2359,10 @@ If you encounter an error missing from this list, please file an issue or a PR!"
23552359
TypeKind::Opaque |
23562360
TypeKind::TypeParam => return true,
23572361
_ => {}
2358-
};
2362+
}
2363+
if self.is_stdint_type(&name) {
2364+
return true;
2365+
}
23592366
}
23602367

23612368
// Unnamed top-level enums are special and we

src/ir/ty.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,10 @@ impl Trace for Type {
12061206
where
12071207
T: Tracer,
12081208
{
1209+
if self.name().map_or(false, |name| context.is_stdint_type(name)) {
1210+
// These types are special-cased in codegen and don't need to be traversed.
1211+
return;
1212+
}
12091213
match *self.kind() {
12101214
TypeKind::Pointer(inner) |
12111215
TypeKind::Reference(inner) |

0 commit comments

Comments
 (0)