From ecfdd8d58b8e6e95546b37b6fce599c987be198f Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Tue, 1 Aug 2023 11:54:49 +0200 Subject: [PATCH] Add static assertions to nodes (#6228) --- Cargo.lock | 1 + crates/ruff_python_ast/Cargo.toml | 1 + crates/ruff_python_ast/src/nodes.rs | 13 +++++++++++++ 3 files changed, 15 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 70245d286e5c6..9e252ab60126e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2291,6 +2291,7 @@ dependencies = [ "rustc-hash", "serde", "smallvec", + "static_assertions", ] [[package]] diff --git a/crates/ruff_python_ast/Cargo.toml b/crates/ruff_python_ast/Cargo.toml index 21c7546c9209d..b85f740223267 100644 --- a/crates/ruff_python_ast/Cargo.toml +++ b/crates/ruff_python_ast/Cargo.toml @@ -28,6 +28,7 @@ once_cell = { workspace = true } rustc-hash = { workspace = true } serde = { workspace = true, optional = true } smallvec = { workspace = true } +static_assertions = "1.1.0" [dev-dependencies] insta = { workspace = true } diff --git a/crates/ruff_python_ast/src/nodes.rs b/crates/ruff_python_ast/src/nodes.rs index 2b8420c625325..f42f831c763a6 100644 --- a/crates/ruff_python_ast/src/nodes.rs +++ b/crates/ruff_python_ast/src/nodes.rs @@ -3044,3 +3044,16 @@ impl Ranged for crate::nodes::ArgWithDefault { self.range } } + +#[cfg(target_pointer_width = "64")] +mod size_assertions { + #[allow(clippy::wildcard_imports)] + use super::*; + use static_assertions::assert_eq_size; + + assert_eq_size!(Stmt, [u8; 168]); + assert_eq_size!(Expr, [u8; 80]); + assert_eq_size!(Constant, [u8; 32]); + assert_eq_size!(Pattern, [u8; 96]); + assert_eq_size!(Mod, [u8; 64]); +}