Skip to content

Commit

Permalink
Fix PartialEq deriving with --no-partialeq
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyzab committed Sep 19, 2017
1 parent 557e861 commit 2bcf255
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/ir/analysis/derive_partial_eq_or_partial_ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand All @@ -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
})
Expand Down
3 changes: 1 addition & 2 deletions src/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/no-partialeq-opaque.rs
Original file line number Diff line number Diff line change
@@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/no-partialeq-whitelisted.rs
Original file line number Diff line number Diff line change
@@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion tests/headers/no-partialeq-opaque.hpp
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 2bcf255

Please sign in to comment.