From 30d686ce1d003e020e28ccc04413b0eb69ca6211 Mon Sep 17 00:00:00 2001 From: The 8472 Date: Sat, 14 Jun 2025 14:52:34 +0200 Subject: [PATCH 1/2] move size assert from const to tests Struct layouts aren't guaranteed and -Zrandomize-layout exercises this right. To compile the whole rust-lang/rust repo with layout randomization we can't have static asserts like these. --- src/green/node.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/green/node.rs b/src/green/node.rs index 832915b..d056abb 100644 --- a/src/green/node.rs +++ b/src/green/node.rs @@ -12,7 +12,6 @@ use crate::{ GreenToken, NodeOrToken, TextRange, TextSize, arc::{Arc, HeaderSlice, ThinArc}, green::{GreenElement, GreenElementRef, SyntaxKind}, - utility_types::static_assert, }; #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -28,8 +27,6 @@ pub(crate) enum GreenChild { Node { rel_offset: TextSize, node: GreenNode }, Token { rel_offset: TextSize, token: GreenToken }, } -#[cfg(target_pointer_width = "64")] -static_assert!(mem::size_of::() == mem::size_of::() * 2); type Repr = HeaderSlice; type ReprThin = HeaderSlice; @@ -356,3 +353,16 @@ impl DoubleEndedIterator for Children<'_> { } impl FusedIterator for Children<'_> {} + +#[cfg(test)] +mod test { + + #[test] + #[cfg(target_pointer_width = "64")] + fn check_green_child_size() { + use super::GreenChild; + use std::mem; + + assert_eq!(mem::size_of::(), mem::size_of::() * 2); + } +} From e9813a6d60b0f6283b27ddc31dca1df724dbdf53 Mon Sep 17 00:00:00 2001 From: The 8472 Date: Sat, 14 Jun 2025 14:55:44 +0200 Subject: [PATCH 2/2] remove now-unusued macro --- src/utility_types.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/utility_types.rs b/src/utility_types.rs index f26dabf..656f9d4 100644 --- a/src/utility_types.rs +++ b/src/utility_types.rs @@ -149,14 +149,6 @@ impl Iterator for TokenAtOffset { impl ExactSizeIterator for TokenAtOffset {} -macro_rules! _static_assert { - ($expr:expr) => { - const _: i32 = 0 / $expr as i32; - }; -} - -pub(crate) use _static_assert as static_assert; - #[derive(Copy, Clone, Debug)] pub(crate) enum Delta { Add(T),