From a4c622c7ff850cb654d191f789105bfb666ebbef Mon Sep 17 00:00:00 2001 From: Youseok Yang Date: Wed, 21 Feb 2024 00:10:24 +0900 Subject: [PATCH] Filter out lookup_can_derive_copy for template type Template type in tagged union should not be copy fields as it requires ManuallyDrop. Filter out copy derive when the variable is resolved to template type. Fix: 2157 --- bindgen/ir/context.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 26247cdcc5..ef59e70880 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -2767,6 +2767,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" let id = id.into(); !self.lookup_has_type_param_in_array(id) && + !self.lookup_is_type_param_after_resolve(id) && !self.cannot_derive_copy.as_ref().unwrap().contains(&id) } @@ -2796,6 +2797,25 @@ If you encounter an error missing from this list, please file an issue or a PR!" .contains(&id.into()) } + /// Look up whether the item with `id` is type parameter after resolve. + fn lookup_is_type_param_after_resolve>( + &self, + id: Id, + ) -> bool { + if let Some(t) = id + .into() + .into_resolver() + .through_type_refs() + .resolve(self) + .kind() + .as_type() + { + t.is_type_param() + } else { + false + } + } + /// Compute whether the type has float. fn compute_has_float(&mut self) { let _t = self.timer("compute_has_float");