diff options
author | Christian Poveda <31802960+pvdrz@users.noreply.github.com> | 2022-09-28 21:35:50 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-28 21:35:50 -0500 |
commit | e68b8c0e2b2ceeb42c35e74bd9344a1a99ec2e0c (patch) | |
tree | 2824f04e8e5600b7fd0f533e845e76070ded5bc0 /src | |
parent | b5ec18e37447467e158180bc189e8caa8a861156 (diff) | |
parent | 70115a08631f6928efbe5d685043676bf68e3123 (diff) |
Merge pull request #2287 from goffrie/dont-traverse-stdint
Don't traverse through special-cased <stdint.h> types.
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/context.rs | 34 | ||||
-rw-r--r-- | src/ir/ty.rs | 7 |
2 files changed, 27 insertions, 14 deletions
diff --git a/src/ir/context.rs b/src/ir/context.rs index 7837e594..d470efa9 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -2250,24 +2250,27 @@ If you encounter an error missing from this list, please file an issue or a PR!" // Sized integer types from <stdint.h> get mapped to Rust primitive // types regardless of whether they are blocklisted, so ensure that // standard traits are considered derivable for them too. - None => match name { - "int8_t" | "uint8_t" | "int16_t" | "uint16_t" | - "int32_t" | "uint32_t" | "int64_t" | - "uint64_t" | "uintptr_t" | "intptr_t" | - "ptrdiff_t" => Some(CanDerive::Yes), - "size_t" if self.options.size_t_is_usize => { - Some(CanDerive::Yes) - } - "ssize_t" if self.options.size_t_is_usize => { - Some(CanDerive::Yes) - } - _ => Some(CanDerive::No), - }, + None => Some(if self.is_stdint_type(name) { + CanDerive::Yes + } else { + CanDerive::No + }), }) .unwrap_or(CanDerive::No) }) } + /// Is the given type a type from <stdint.h> that corresponds to a Rust primitive type? + pub fn is_stdint_type(&self, name: &str) -> bool { + match name { + "int8_t" | "uint8_t" | "int16_t" | "uint16_t" | "int32_t" | + "uint32_t" | "int64_t" | "uint64_t" | "uintptr_t" | + "intptr_t" | "ptrdiff_t" => true, + "size_t" | "ssize_t" => self.options.size_t_is_usize, + _ => false, + } + } + /// Get a reference to the set of items we should generate. pub fn codegen_items(&self) -> &ItemSet { 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!" TypeKind::Opaque | TypeKind::TypeParam => return true, _ => {} - }; + } + if self.is_stdint_type(&name) { + return true; + } } // Unnamed top-level enums are special and we diff --git a/src/ir/ty.rs b/src/ir/ty.rs index c85bc687..6a3fd0e8 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -1206,6 +1206,13 @@ impl Trace for Type { where T: Tracer, { + if self + .name() + .map_or(false, |name| context.is_stdint_type(name)) + { + // These types are special-cased in codegen and don't need to be traversed. + return; + } match *self.kind() { TypeKind::Pointer(inner) | TypeKind::Reference(inner) | |