Skip to content

Commit

Permalink
Update type size test
Browse files Browse the repository at this point in the history
This prevents future breakage due to improvements in the compiler.
  • Loading branch information
jhpratt committed May 6, 2023
1 parent 92cf8e7 commit 8757bef
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions tests/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,25 @@ fn alignment() {
fn size() {
macro_rules! assert_size {
($t:ty, $size:literal, $opt_size:literal) => {
assert_eq!(
::core::mem::size_of::<$t>(),
$size,
concat!("size of `{}` used to be ", $size),
assert!(
::core::mem::size_of::<$t>() <= $size,
concat!("size of `{}` used to be ", $size, ", but is now {}"),
stringify!($t),
::core::mem::size_of::<$t>(),
);
assert_eq!(
::core::mem::size_of::<Option<$t>>(),
$opt_size,
concat!("size of `Option<{}>` used to be ", $opt_size),
assert!(
::core::mem::size_of::<Option<$t>>() <= $opt_size,
concat!(
"size of `Option<{}>` used to be ",
$opt_size,
", but is now {}"
),
stringify!($t),
::core::mem::size_of::<Option<$t>>(),
);
};
}

// A couple structs have their size decrease from 56 to 48 thanks to a compiler change. This
// change looks like it will land in 1.64 (2022-09-22).

assert_size!(Date, 4, 8);
assert_size!(Duration, 16, 16);
assert_size!(OffsetDateTime, 16, 16);
Expand Down Expand Up @@ -150,13 +151,13 @@ fn size() {
assert_size!(Parsed, 56, 56);
assert_size!(Month, 1, 1);
assert_size!(Weekday, 1, 1);
// assert_size!(Error, 56, 56);
assert_size!(Error, 56, 56);
assert_size!(error::Format, 24, 24);
assert_size!(error::InvalidFormatDescription, 48, 48);
// assert_size!(error::Parse, 56, 56);
assert_size!(error::Parse, 48, 48);
assert_size!(error::ParseFromDescription, 16, 24);
assert_size!(error::TryFromParsed, 48, 48);
assert_size!(Component, 6, 6);
assert_size!(Component, 6, 6); // TODO Size is 4 starting with rustc 1.71.
assert_size!(FormatItem<'_>, 24, 24);
assert_size!(modifier::MonthRepr, 1, 1);
assert_size!(modifier::Padding, 1, 1);
Expand Down

0 comments on commit 8757bef

Please sign in to comment.