|
4 | 4 |
|
5 | 5 | use crate::cow_rc_str::CowRcStr; |
6 | 6 | use crate::tokenizer::Token; |
7 | | -use std::borrow::Cow; |
8 | 7 |
|
9 | 8 | 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) => { |
11 | 10 | #[test] |
12 | 11 | fn $testname() { |
13 | 12 | let new = ::std::mem::size_of::<$t>(); |
14 | | - let old = $expected_size; |
15 | | - if new < old { |
| 13 | + if new < $expected_min_size { |
16 | 14 | panic!( |
17 | 15 | "Your changes have decreased the stack size of {} from {} to {}. \ |
18 | 16 | Good work! Please update the expected size in {}.", |
19 | 17 | stringify!($t), |
20 | | - old, |
| 18 | + $expected_min_size, |
21 | 19 | new, |
22 | 20 | file!() |
23 | 21 | ) |
24 | | - } else if new > old { |
| 22 | + } else if new > $expected_max_size { |
25 | 23 | panic!( |
26 | 24 | "Your changes have increased the stack size of {} from {} to {}. \ |
27 | 25 | Please consider choosing a design which avoids this increase. \ |
28 | 26 | If you feel that the increase is necessary, update the size in {}.", |
29 | 27 | stringify!($t), |
30 | | - old, |
| 28 | + $expected_max_size, |
31 | 29 | new, |
32 | 30 | file!() |
33 | 31 | ) |
34 | 32 | } |
35 | 33 | } |
36 | 34 | }; |
| 35 | + ($testname: ident, $t: ty, $expected_size: expr) => { |
| 36 | + size_of_test!($testname, $t, $expected_size, $expected_size); |
| 37 | + }; |
37 | 38 | } |
38 | 39 |
|
39 | 40 | // Some of these assume 64-bit |
40 | 41 | 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); |
42 | 43 | size_of_test!(cow_rc_str, CowRcStr, 16); |
43 | 44 |
|
44 | 45 | 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); |
50 | 47 | size_of_test!(parser, crate::parser::Parser, 16); |
51 | 48 | size_of_test!(source_position, crate::SourcePosition, 8); |
52 | 49 | size_of_test!(parser_state, crate::ParserState, 24); |
53 | 50 |
|
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