From 2bcf255e47ac05f445a7008498b327e99ffce121 Mon Sep 17 00:00:00 2001 From: Alexey Zabelin Date: Tue, 19 Sep 2017 16:45:55 -0400 Subject: [PATCH] Fix PartialEq deriving with --no-partialeq --- src/ir/analysis/derive_partial_eq_or_partial_ord.rs | 8 ++++---- src/ir/context.rs | 3 +-- src/lib.rs | 1 + tests/expectations/tests/no-partialeq-opaque.rs | 2 +- tests/expectations/tests/no-partialeq-whitelisted.rs | 2 +- tests/headers/no-partialeq-opaque.hpp | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ir/analysis/derive_partial_eq_or_partial_ord.rs b/src/ir/analysis/derive_partial_eq_or_partial_ord.rs index 55ea733115..1d4a5939ee 100644 --- a/src/ir/analysis/derive_partial_eq_or_partial_ord.rs +++ b/src/ir/analysis/derive_partial_eq_or_partial_ord.rs @@ -128,6 +128,10 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> { } }; + if self.ctx.no_partialeq_by_name(&item) { + return self.insert(id) + } + trace!("ty: {:?}", ty); if item.is_opaque(self.ctx, &()) { let layout_can_derive = ty.layout(self.ctx).map_or(true, |l| { @@ -144,10 +148,6 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> { }; } - if self.ctx.no_partialeq_by_name(&item) { - return self.insert(id) - } - if ty.layout(self.ctx).map_or(false, |l| { l.align > RUST_DERIVE_IN_ARRAY_LIMIT }) diff --git a/src/ir/context.rs b/src/ir/context.rs index 6890298386..6a87ee8ee0 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -11,7 +11,6 @@ use super::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault, use super::int::IntKind; use super::item::{HasTypeParamInArray, IsOpaque, Item, ItemAncestors, ItemCanonicalPath, ItemSet}; -use ir::item::ItemCanonicalName; use super::item_kind::ItemKind; use super::module::{Module, ModuleKind}; use super::template::{TemplateInstantiation, TemplateParameters}; @@ -2209,7 +2208,7 @@ impl BindgenContext { /// Check if `--no-partialeq` flag is enabled for this item. pub fn no_partialeq_by_name(&self, item: &Item) -> bool { - let name = item.canonical_name(self); + let name = item.canonical_path(self)[1..].join("::"); self.options().no_partialeq_types.matches(&name) } } diff --git a/src/lib.rs b/src/lib.rs index 656f16e3f9..dcef26272b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1322,6 +1322,7 @@ impl BindgenOptions { self.bitfield_enums.build(); self.constified_enum_modules.build(); self.rustified_enums.build(); + self.no_partialeq_types.build(); } /// Update rust target version diff --git a/tests/expectations/tests/no-partialeq-opaque.rs b/tests/expectations/tests/no-partialeq-opaque.rs index dd496b1cc2..6287591a7d 100644 --- a/tests/expectations/tests/no-partialeq-opaque.rs +++ b/tests/expectations/tests/no-partialeq-opaque.rs @@ -1,7 +1,7 @@ /* automatically generated by rust-bindgen */ #[repr(C)] -#[derive(Debug, Copy, PartialEq)] +#[derive(Debug, Copy)] pub struct NoPartialEq { pub _bindgen_opaque_blob: u32, } diff --git a/tests/expectations/tests/no-partialeq-whitelisted.rs b/tests/expectations/tests/no-partialeq-whitelisted.rs index 99ee2ff027..0c83f7c9cb 100644 --- a/tests/expectations/tests/no-partialeq-whitelisted.rs +++ b/tests/expectations/tests/no-partialeq-whitelisted.rs @@ -1,7 +1,7 @@ /* automatically generated by rust-bindgen */ #[repr(C)] -#[derive(Debug, Copy, PartialEq)] +#[derive(Debug, Copy)] pub struct NoPartialEq { pub i: ::std::os::raw::c_int, } diff --git a/tests/headers/no-partialeq-opaque.hpp b/tests/headers/no-partialeq-opaque.hpp index 2b4e128370..a5a03cd287 100644 --- a/tests/headers/no-partialeq-opaque.hpp +++ b/tests/headers/no-partialeq-opaque.hpp @@ -1,4 +1,4 @@ -// bindgen-flags --with-derive-partialeq --opaque-type "NoPartialEq" --no-partialeq "NoPartialEq" +// bindgen-flags: --with-derive-partialeq --opaque-type "NoPartialEq" --no-partialeq "NoPartialEq" class NoPartialEq { int i;