Skip to content

Commit b163822

Browse files
committed
packed -> C,packed
1 parent 275f3f7 commit b163822

File tree

6 files changed

+28
-8
lines changed

6 files changed

+28
-8
lines changed

components/calendar/src/provider/chinese_based.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl<'data> ChineseBasedCacheV1<'data> {
143143
derive(databake::Bake),
144144
databake(path = icu_calendar::provider),
145145
)]
146-
#[repr(packed)]
146+
#[repr(C, packed)]
147147
pub struct PackedChineseBasedYearInfo(pub u8, pub u8, pub u8);
148148

149149
impl PackedChineseBasedYearInfo {

components/calendar/src/provider/islamic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl<'data> IslamicCacheV1<'data> {
156156
databake(path = icu_calendar::provider),
157157
)]
158158
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
159-
#[repr(packed)]
159+
#[repr(C, packed)]
160160
pub struct PackedIslamicYearInfo(pub u8, pub u8);
161161

162162
impl fmt::Debug for PackedIslamicYearInfo {

components/casemap/src/provider/exceptions_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl ExceptionHeader {
7171
/// In this struct the RESERVED bit is still allowed to be set, and it will produce a different
7272
/// exception header, but it will not have any other effects.
7373
#[derive(Copy, Clone, PartialEq, Eq, ULE)]
74-
#[repr(packed)]
74+
#[repr(C, packed)]
7575
pub struct ExceptionHeaderULE {
7676
slot_presence: SlotPresence,
7777
bits: ExceptionBitsULE,

utils/zerovec/derive/src/ule.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ use syn::spanned::Spanned;
1010
use syn::{Data, DeriveInput, Error};
1111

1212
pub fn derive_impl(input: &DeriveInput) -> TokenStream2 {
13-
if !utils::has_valid_repr(&input.attrs, |r| r == "packed" || r == "transparent") {
13+
if !utils::has_transparent_or_cpacked_repr(&input.attrs) {
1414
return Error::new(
1515
input.span(),
16-
"derive(ULE) must be applied to a #[repr(packed)] or #[repr(transparent)] type",
16+
"derive(ULE) must be applied to a #[repr(C, packed)] or #[repr(transparent)] type",
1717
)
1818
.to_compile_error();
1919
}

utils/zerovec/derive/src/utils.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,26 @@ pub fn has_valid_repr(attrs: &[Attribute], predicate: impl Fn(&Ident) -> bool +
2121
})
2222
}
2323

24+
pub fn has_transparent_or_cpacked_repr(attrs: &[Attribute]) -> bool {
25+
let mut found_transparent = false;
26+
let mut found_packed = false;
27+
let mut found_c = false;
28+
for attr in attrs.iter().filter(|a| a.path().is_ident("repr")) {
29+
if let Some(pieces) = attr.parse_args::<IdentListAttribute>().ok() {
30+
for piece in pieces.idents.iter() {
31+
if piece == "C" || piece == "c" {
32+
found_c = true;
33+
} else if piece == "transparent" {
34+
found_transparent = true;
35+
} else if piece == "packed" {
36+
found_packed = true;
37+
}
38+
}
39+
}
40+
}
41+
(found_c && found_packed) || found_transparent
42+
}
43+
2444
// An attribute that is a list of idents
2545
struct IdentListAttribute {
2646
idents: Punctuated<Ident, Token![,]>,
@@ -60,7 +80,7 @@ pub fn repr_for(f: &Fields) -> TokenStream2 {
6080
if f.len() == 1 {
6181
quote!(transparent)
6282
} else {
63-
quote!(packed)
83+
quote!(C, packed)
6484
}
6585
}
6686

utils/zerovec/derive/src/varule.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ pub fn derive_impl(
1515
input: &DeriveInput,
1616
custom_varule_validator: Option<TokenStream2>,
1717
) -> TokenStream2 {
18-
if !utils::has_valid_repr(&input.attrs, |r| r == "packed" || r == "transparent") {
18+
if !utils::has_transparent_or_cpacked_repr(&input.attrs) {
1919
return Error::new(
2020
input.span(),
21-
"derive(VarULE) must be applied to a #[repr(packed)] or #[repr(transparent)] type",
21+
"derive(VarULE) must be applied to a #[repr(C, packed)] or #[repr(transparent)] type",
2222
)
2323
.to_compile_error();
2424
}

0 commit comments

Comments
 (0)