From db23a24b263a2ab2fb2498d9171b289185ea042c Mon Sep 17 00:00:00 2001 From: undivisible <136312656+undivisible@users.noreply.github.com> Date: Thu, 10 Sep 2026 15:27:20 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Remove=20dead=5Fcode=20allow=20f?= =?UTF-8?q?rom=20Rust=20probes=20and=20use=20pub=20structs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed the crate/file-level `#![allow(dead_code)]` attribute from the generated Rust layout probes in `in-cli/src/boundary_emit/probes.rs`. To prevent actual dead code warnings on the structs generated strictly for assertion checks (`size_of`, `align_of`, `offset_of`), the emitted types and their fields were changed to `pub`. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- in-cli/src/boundary_emit/probes.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/in-cli/src/boundary_emit/probes.rs b/in-cli/src/boundary_emit/probes.rs index 42b11921..f34d8f4c 100644 --- a/in-cli/src/boundary_emit/probes.rs +++ b/in-cli/src/boundary_emit/probes.rs @@ -22,7 +22,6 @@ pub fn emit_layout_probes(module: &BoundaryModule) -> Result Result { let mut out = String::new(); - out.push_str("#![allow(dead_code)]\n"); out.push_str("use std::mem::{align_of, offset_of, size_of};\n\n"); emit_rust_abi_types(&mut out); @@ -34,10 +33,14 @@ fn emit_rust_probes(module: &BoundaryModule) -> Result { } fn emit_rust_abi_types(out: &mut String) { - out.push_str("#[repr(C)]\nstruct InSliceU8 {\n ptr: *const u8,\n len: u64,\n}\n\n"); - out.push_str("#[repr(C)]\nstruct InBufU8 {\n ptr: *mut u8,\n len: u64,\n cap: u64,\n allocator_id: u64,\n}\n\n"); - out.push_str("#[repr(C)]\nstruct InBorrowToken {\n arena_id: u64,\n generation: u64,\n start: u64,\n len: u64,\n flags: u64,\n}\n\n"); - out.push_str("#[repr(C)]\nstruct InArenaHandle {\n id: u64,\n generation: u64,\n}\n\n"); + out.push_str( + "#[repr(C)]\npub struct InSliceU8 {\n pub ptr: *const u8,\n pub len: u64,\n}\n\n", + ); + out.push_str("#[repr(C)]\npub struct InBufU8 {\n pub ptr: *mut u8,\n pub len: u64,\n pub cap: u64,\n pub allocator_id: u64,\n}\n\n"); + out.push_str("#[repr(C)]\npub struct InBorrowToken {\n pub arena_id: u64,\n pub generation: u64,\n pub start: u64,\n pub len: u64,\n pub flags: u64,\n}\n\n"); + out.push_str( + "#[repr(C)]\npub struct InArenaHandle {\n pub id: u64,\n pub generation: u64,\n}\n\n", + ); } fn emit_rust_layout(out: &mut String, layout: &BoundaryLayout) -> Result<(), String> { @@ -46,10 +49,10 @@ fn emit_rust_layout(out: &mut String, layout: &BoundaryLayout) -> Result<(), Str } let repr = super::repr_attribute(layout.repr.as_ref()); - out.push_str(&format!("#[repr({repr})]\nstruct {} {{\n", layout.name)); + out.push_str(&format!("#[repr({repr})]\npub struct {} {{\n", layout.name)); for field in &layout.fields { let rust_type = super::rust_type_name(&field.typ); - out.push_str(&format!(" {}: {},\n", field.name, rust_type)); + out.push_str(&format!(" pub {}: {},\n", field.name, rust_type)); } out.push_str("}\n\n"); @@ -179,9 +182,9 @@ mod tests { let mut out = String::new(); emit_rust_layout(&mut out, layout).expect("emit_rust_layout"); - assert!(out.contains("#[repr(c)]\nstruct Person {")); - assert!(out.contains("name: InSliceU8")); - assert!(out.contains("age: u32")); + assert!(out.contains("#[repr(c)]\npub struct Person {")); + assert!(out.contains("pub name: InSliceU8")); + assert!(out.contains("pub age: u32")); assert!(out.contains("assert!(size_of::() == 24);")); assert!(out.contains("assert!(align_of::() == 8);")); assert!(out.contains("assert!(offset_of!(Person, name) == 0);"));