Skip to content

Commit

Permalink
Ensure all derive analyses check array limit on bitfields
Browse files Browse the repository at this point in the history
  • Loading branch information
aeleos committed Sep 20, 2017
1 parent 4842973 commit 95879dd
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/ir/analysis/derive_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,14 @@ impl<'ctx> MonotoneFramework for CannotDeriveCopy<'ctx> {
self.is_not_copy(data.ty())
}
Field::Bitfields(ref bfu) => {
if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
trace!(
" we cannot derive Copy for a bitfield larger then \
the limit"
);
return true;
}

bfu.bitfields().iter().any(|b| {
self.is_not_copy(b.ty())
})
Expand Down
8 changes: 8 additions & 0 deletions src/ir/analysis/derive_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@ impl<'ctx> MonotoneFramework for CannotDeriveDebug<'ctx> {
self.is_not_debug(data.ty())
}
Field::Bitfields(ref bfu) => {
if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
trace!(
" we cannot derive Debug for a bitfield larger then \
the limit"
);
return true;
}

bfu.bitfields().iter().any(|b| {
self.is_not_debug(b.ty())
})
Expand Down
8 changes: 8 additions & 0 deletions src/ir/analysis/derive_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ impl<'ctx> MonotoneFramework for CannotDeriveDefault<'ctx> {
self.is_not_default(data.ty())
}
Field::Bitfields(ref bfu) => {
if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
trace!(
" we cannot derive Default for a bitfield larger then \
the limit"
);
return true;
}

bfu.bitfields().iter().any(|b| {
!self.ctx.whitelisted_items().contains(
&b.ty(),
Expand Down
8 changes: 8 additions & 0 deletions src/ir/analysis/derive_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> {
self.cannot_derive_hash.contains(&data.ty())
}
Field::Bitfields(ref bfu) => {
if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
trace!(
" we cannot derive Hash for a bitfield larger then \
the limit"
);
return true;
}

bfu.bitfields().iter().any(|b| {
!self.ctx.whitelisted_items().contains(
&b.ty(),
Expand Down
8 changes: 8 additions & 0 deletions src/ir/analysis/derive_partial_eq_or_partial_ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,14 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> {
)
}
Field::Bitfields(ref bfu) => {
if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
trace!(
" we cannot derive PartialEq for a bitfield larger then \
the limit"
);
return true;
}

bfu.bitfields().iter().any(|b| {
!self.ctx.whitelisted_items().contains(
&b.ty(),
Expand Down

0 comments on commit 95879dd

Please sign in to comment.