Skip to content

Commit 95879dd

Browse files
committed
Ensure all derive analyses check array limit on bitfields
1 parent 4842973 commit 95879dd

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

src/ir/analysis/derive_copy.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,14 @@ impl<'ctx> MonotoneFramework for CannotDeriveCopy<'ctx> {
266266
self.is_not_copy(data.ty())
267267
}
268268
Field::Bitfields(ref bfu) => {
269+
if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
270+
trace!(
271+
" we cannot derive Copy for a bitfield larger then \
272+
the limit"
273+
);
274+
return true;
275+
}
276+
269277
bfu.bitfields().iter().any(|b| {
270278
self.is_not_copy(b.ty())
271279
})

src/ir/analysis/derive_debug.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,14 @@ impl<'ctx> MonotoneFramework for CannotDeriveDebug<'ctx> {
268268
self.is_not_debug(data.ty())
269269
}
270270
Field::Bitfields(ref bfu) => {
271+
if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
272+
trace!(
273+
" we cannot derive Debug for a bitfield larger then \
274+
the limit"
275+
);
276+
return true;
277+
}
278+
271279
bfu.bitfields().iter().any(|b| {
272280
self.is_not_debug(b.ty())
273281
})

src/ir/analysis/derive_default.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,14 @@ impl<'ctx> MonotoneFramework for CannotDeriveDefault<'ctx> {
308308
self.is_not_default(data.ty())
309309
}
310310
Field::Bitfields(ref bfu) => {
311+
if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
312+
trace!(
313+
" we cannot derive Default for a bitfield larger then \
314+
the limit"
315+
);
316+
return true;
317+
}
318+
311319
bfu.bitfields().iter().any(|b| {
312320
!self.ctx.whitelisted_items().contains(
313321
&b.ty(),

src/ir/analysis/derive_hash.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,14 @@ impl<'ctx> MonotoneFramework for CannotDeriveHash<'ctx> {
283283
self.cannot_derive_hash.contains(&data.ty())
284284
}
285285
Field::Bitfields(ref bfu) => {
286+
if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
287+
trace!(
288+
" we cannot derive Hash for a bitfield larger then \
289+
the limit"
290+
);
291+
return true;
292+
}
293+
286294
bfu.bitfields().iter().any(|b| {
287295
!self.ctx.whitelisted_items().contains(
288296
&b.ty(),

src/ir/analysis/derive_partial_eq_or_partial_ord.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,14 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> {
292292
)
293293
}
294294
Field::Bitfields(ref bfu) => {
295+
if bfu.layout().align > RUST_DERIVE_IN_ARRAY_LIMIT {
296+
trace!(
297+
" we cannot derive PartialEq for a bitfield larger then \
298+
the limit"
299+
);
300+
return true;
301+
}
302+
295303
bfu.bitfields().iter().any(|b| {
296304
!self.ctx.whitelisted_items().contains(
297305
&b.ty(),

0 commit comments

Comments
 (0)