Skip to content

Commit 0d6dc4a

Browse files
committed
Fix CI, again.
Make size tests take a range.
1 parent 63e209c commit 0d6dc4a

File tree

2 files changed

+12
-34
lines changed

2 files changed

+12
-34
lines changed

build.rs

-9
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,5 @@ mod codegen {
3737
}
3838

3939
fn main() {
40-
if std::mem::size_of::<Option<bool>>() == 1 {
41-
// https://github.com/rust-lang/rust/pull/45225
42-
println!("cargo:rustc-cfg=rustc_has_pr45225")
43-
}
44-
45-
if std::mem::size_of::<std::borrow::Cow<'static, str>>() == 24 {
46-
println!("cargo:rustc-cfg=rustc_has_better_cow_layout")
47-
}
48-
4940
codegen::main();
5041
}

src/size_of_tests.rs

+12-25
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,49 @@
44

55
use crate::cow_rc_str::CowRcStr;
66
use crate::tokenizer::Token;
7-
use std::borrow::Cow;
87

98
macro_rules! size_of_test {
10-
($testname: ident, $t: ty, $expected_size: expr) => {
9+
($testname: ident, $t: ty, $expected_min_size: expr, $expected_max_size: expr) => {
1110
#[test]
1211
fn $testname() {
1312
let new = ::std::mem::size_of::<$t>();
14-
let old = $expected_size;
15-
if new < old {
13+
if new < $expected_min_size {
1614
panic!(
1715
"Your changes have decreased the stack size of {} from {} to {}. \
1816
Good work! Please update the expected size in {}.",
1917
stringify!($t),
20-
old,
18+
$expected_min_size,
2119
new,
2220
file!()
2321
)
24-
} else if new > old {
22+
} else if new > $expected_max_size {
2523
panic!(
2624
"Your changes have increased the stack size of {} from {} to {}. \
2725
Please consider choosing a design which avoids this increase. \
2826
If you feel that the increase is necessary, update the size in {}.",
2927
stringify!($t),
30-
old,
28+
$expected_max_size,
3129
new,
3230
file!()
3331
)
3432
}
3533
}
3634
};
35+
($testname: ident, $t: ty, $expected_size: expr) => {
36+
size_of_test!($testname, $t, $expected_size, $expected_size);
37+
};
3738
}
3839

3940
// Some of these assume 64-bit
4041
size_of_test!(token, Token, 32);
41-
size_of_test!(std_cow_str, Cow<'static, str>, if cfg!(rustc_has_better_cow_layout) { 24 } else { 32 });
42+
size_of_test!(std_cow_str, std::borrow::Cow<'static, str>, 24, 32);
4243
size_of_test!(cow_rc_str, CowRcStr, 16);
4344

4445
size_of_test!(tokenizer, crate::tokenizer::Tokenizer, 72);
45-
size_of_test!(
46-
parser_input,
47-
crate::parser::ParserInput,
48-
if cfg!(rustc_has_pr45225) { 136 } else { 144 }
49-
);
46+
size_of_test!(parser_input, crate::parser::ParserInput, 136);
5047
size_of_test!(parser, crate::parser::Parser, 16);
5148
size_of_test!(source_position, crate::SourcePosition, 8);
5249
size_of_test!(parser_state, crate::ParserState, 24);
5350

54-
size_of_test!(basic_parse_error, crate::BasicParseError, if cfg!(rustc_has_better_cow_layout) { 40 } else { 48 });
55-
size_of_test!(
56-
parse_error_lower_bound,
57-
crate::ParseError<()>,
58-
if cfg!(rustc_has_better_cow_layout) {
59-
40
60-
} else if cfg!(rustc_has_pr45225) {
61-
48
62-
} else {
63-
56
64-
}
65-
);
51+
size_of_test!(basic_parse_error, crate::BasicParseError, 40, 48);
52+
size_of_test!(parse_error_lower_bound, crate::ParseError<()>, 40, 48);

0 commit comments

Comments
 (0)