Skip to content

Commit 464c2eb

Browse files
authored
Merge pull request #461 from dtolnay/sizetest
Add additional size tests
2 parents abc7dff + 6f894e7 commit 464c2eb

File tree

3 files changed

+58
-10
lines changed

3 files changed

+58
-10
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
with:
5757
components: rust-src
5858
- name: Enable type layout randomization
59-
run: echo RUSTFLAGS=${RUSTFLAGS}\ -Zrandomize-layout >> $GITHUB_ENV
59+
run: echo RUSTFLAGS=${RUSTFLAGS}\ -Zrandomize-layout\ --cfg=randomize_layout >> $GITHUB_ENV
6060
- run: cargo check
6161
env:
6262
RUSTFLAGS: --cfg procmacro2_nightly_testing ${{env.RUSTFLAGS}}
@@ -78,6 +78,22 @@ jobs:
7878
env:
7979
RUSTFLAGS: -Z allow-features= --cfg procmacro2_backtrace ${{env.RUSTFLAGS}}
8080

81+
layout:
82+
name: Layout
83+
needs: pre_ci
84+
if: needs.pre_ci.outputs.continue
85+
runs-on: ubuntu-latest
86+
timeout-minutes: 45
87+
steps:
88+
- uses: actions/checkout@v4
89+
- uses: dtolnay/rust-toolchain@nightly
90+
with:
91+
components: rust-src
92+
- run: cargo test --test test_size
93+
- run: cargo test --test test_size --features span-locations
94+
- run: cargo test --test test_size --no-default-features
95+
- run: cargo test --test test_size --no-default-features --features span-locations
96+
8197
msrv:
8298
name: Rust 1.56.0
8399
needs: pre_ci

build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ fn main() {
5757
println!("cargo:rustc-check-cfg=cfg(procmacro2_backtrace)");
5858
println!("cargo:rustc-check-cfg=cfg(procmacro2_nightly_testing)");
5959
println!("cargo:rustc-check-cfg=cfg(procmacro2_semver_exempt)");
60+
println!("cargo:rustc-check-cfg=cfg(randomize_layout)");
6061
println!("cargo:rustc-check-cfg=cfg(span_locations)");
6162
println!("cargo:rustc-check-cfg=cfg(super_unstable)");
6263
println!("cargo:rustc-check-cfg=cfg(wrap_proc_macro)");

tests/test_size.rs

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,73 @@
1+
#![cfg(not(randomize_layout))]
2+
13
extern crate proc_macro;
24

35
use std::mem;
46

5-
#[rustversion::attr(before(1.32), ignore)]
7+
#[rustversion::attr(before(1.64), ignore)]
68
#[test]
7-
fn test_proc_macro_span_size() {
9+
fn test_proc_macro_size() {
810
assert_eq!(mem::size_of::<proc_macro::Span>(), 4);
911
assert_eq!(mem::size_of::<Option<proc_macro::Span>>(), 4);
12+
assert_eq!(mem::size_of::<proc_macro::Group>(), 20);
13+
assert_eq!(mem::size_of::<proc_macro::Ident>(), 12);
14+
assert_eq!(mem::size_of::<proc_macro::Punct>(), 8);
15+
assert_eq!(mem::size_of::<proc_macro::Literal>(), 16);
16+
assert_eq!(mem::size_of::<proc_macro::TokenStream>(), 4);
1017
}
1118

1219
#[cfg_attr(not(all(not(wrap_proc_macro), not(span_locations))), ignore)]
1320
#[test]
14-
fn test_proc_macro2_fallback_span_size_without_locations() {
21+
fn test_proc_macro2_fallback_size_without_locations() {
1522
assert_eq!(mem::size_of::<proc_macro2::Span>(), 0);
1623
assert_eq!(mem::size_of::<Option<proc_macro2::Span>>(), 1);
24+
assert_eq!(mem::size_of::<proc_macro2::Group>(), 16);
25+
assert_eq!(mem::size_of::<proc_macro2::Ident>(), 32);
26+
assert_eq!(mem::size_of::<proc_macro2::Punct>(), 8);
27+
assert_eq!(mem::size_of::<proc_macro2::Literal>(), 24);
28+
assert_eq!(mem::size_of::<proc_macro2::TokenStream>(), 8);
1729
}
1830

1931
#[cfg_attr(not(all(not(wrap_proc_macro), span_locations)), ignore)]
2032
#[test]
21-
fn test_proc_macro2_fallback_span_size_with_locations() {
33+
fn test_proc_macro2_fallback_size_with_locations() {
2234
assert_eq!(mem::size_of::<proc_macro2::Span>(), 8);
2335
assert_eq!(mem::size_of::<Option<proc_macro2::Span>>(), 12);
36+
assert_eq!(mem::size_of::<proc_macro2::Group>(), 24);
37+
assert_eq!(mem::size_of::<proc_macro2::Ident>(), 40);
38+
assert_eq!(mem::size_of::<proc_macro2::Punct>(), 16);
39+
assert_eq!(mem::size_of::<proc_macro2::Literal>(), 32);
40+
assert_eq!(mem::size_of::<proc_macro2::TokenStream>(), 8);
2441
}
2542

26-
#[rustversion::attr(before(1.32), ignore)]
43+
#[rustversion::attr(before(1.71), ignore)]
2744
#[rustversion::attr(
28-
since(1.32),
45+
since(1.71),
2946
cfg_attr(not(all(wrap_proc_macro, not(span_locations))), ignore)
3047
)]
3148
#[test]
32-
fn test_proc_macro2_wrapper_span_size_without_locations() {
49+
fn test_proc_macro2_wrapper_size_without_locations() {
3350
assert_eq!(mem::size_of::<proc_macro2::Span>(), 4);
3451
assert_eq!(mem::size_of::<Option<proc_macro2::Span>>(), 8);
52+
assert_eq!(mem::size_of::<proc_macro2::Group>(), 24);
53+
assert_eq!(mem::size_of::<proc_macro2::Ident>(), 32);
54+
assert_eq!(mem::size_of::<proc_macro2::Punct>(), 12);
55+
assert_eq!(mem::size_of::<proc_macro2::Literal>(), 24);
56+
assert_eq!(mem::size_of::<proc_macro2::TokenStream>(), 32);
3557
}
3658

37-
#[cfg_attr(not(all(wrap_proc_macro, span_locations)), ignore)]
59+
#[rustversion::attr(before(1.65), ignore)]
60+
#[rustversion::attr(
61+
since(1.65),
62+
cfg_attr(not(all(wrap_proc_macro, span_locations)), ignore)
63+
)]
3864
#[test]
39-
fn test_proc_macro2_wrapper_span_size_with_locations() {
65+
fn test_proc_macro2_wrapper_size_with_locations() {
4066
assert_eq!(mem::size_of::<proc_macro2::Span>(), 12);
4167
assert_eq!(mem::size_of::<Option<proc_macro2::Span>>(), 12);
68+
assert_eq!(mem::size_of::<proc_macro2::Group>(), 32);
69+
assert_eq!(mem::size_of::<proc_macro2::Ident>(), 40);
70+
assert_eq!(mem::size_of::<proc_macro2::Punct>(), 20);
71+
assert_eq!(mem::size_of::<proc_macro2::Literal>(), 32);
72+
assert_eq!(mem::size_of::<proc_macro2::TokenStream>(), 32);
4273
}

0 commit comments

Comments
 (0)