From c434b1914623a55518fd37f68c2ce4c733e2cd52 Mon Sep 17 00:00:00 2001 From: Martin Kuntz Jacobsen Date: Sat, 14 Nov 2026 04:38:59 +0100 Subject: [PATCH 1/2] bazelrc: deny clippy::panic and unsafe_code repo-wide (part of #12395) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Xut2hws3L7Tg4oUvpSvuYD --- .bazelrc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.bazelrc b/.bazelrc index b02f88eece..6587c87a45 100644 --- a/.bazelrc +++ b/.bazelrc @@ -37,6 +37,7 @@ build --@rules_rust//rust/settings:clippy.toml=//tools/workspace:clippy.toml # Strict tier lints rules_dx enforces. common --@rules_dx//config:clippy_flag=-Dclippy::unwrap_used common --@rules_dx//config:clippy_flag=-Dclippy::expect_used +common --@rules_dx//config:clippy_flag=-Dclippy::panic common --@rules_dx//config:clippy_flag=-Dclippy::unreachable common --@rules_dx//config:clippy_flag=-Dclippy::exit common --@rules_dx//config:clippy_flag=-Dclippy::todo @@ -47,6 +48,7 @@ common --@rules_dx//config:clippy_flag=-Dclippy::unwrap_in_result common --@rules_dx//config:clippy_flag=-Dclippy::panic_in_result_fn common --@rules_dx//config:clippy_flag=-Dclippy::allow_attributes common --@rules_dx//config:clippy_flag=-Dclippy::allow_attributes_without_reason +common --@rules_dx//config:clippy_flag=-Dunsafe_code common --@rules_dx//config:clippy_flag=-Dunsafe_op_in_unsafe_fn common --@rules_dx//config:clippy_flag=-Dunused_must_use build:linux --@rules_rust//rust/settings:pipelined_compilation=true From 280d4eb3589be0e6574ca82fa2b7e37a1ec3b1f5 Mon Sep 17 00:00:00 2001 From: Martin Kuntz Jacobsen Date: Sat, 14 Nov 2026 05:33:44 +0100 Subject: [PATCH 2/2] fixtures: expect unsafe_code where FFI is the point (part of #12395) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Xut2hws3L7Tg4oUvpSvuYD --- apple/tests/fixtures/macos_bundle/ledger.rs | 3 +++ apple/tests/fixtures/shared_core/core.rs | 3 +++ apple/tests/fixtures/swift_app/ledger.rs | 3 +++ apple/tests/fixtures/xcframework_share/share.rs | 3 +++ deploy/tests/fixtures/consumer_archive/app.rs | 2 ++ rust/tests/fixtures/consumer_abi/src/lib.rs | 2 ++ rust/tests/fixtures/consumer_native/src/lib.rs | 2 ++ rust/tests/fixtures/hello/src/cdylib.rs | 2 ++ rust/tests/fixtures/hello/src/staticlib.rs | 2 ++ rust/tests/fixtures/native_call/src/lib.rs | 2 ++ rust/tests/fixtures/native_call/src/native_cc.rs | 2 ++ rust/tests/fixtures/wasm_bindgen/src/lib.rs | 2 ++ 12 files changed, 28 insertions(+) diff --git a/apple/tests/fixtures/macos_bundle/ledger.rs b/apple/tests/fixtures/macos_bundle/ledger.rs index c6c676793c..b7f68ca9e1 100644 --- a/apple/tests/fixtures/macos_bundle/ledger.rs +++ b/apple/tests/fixtures/macos_bundle/ledger.rs @@ -1,3 +1,5 @@ +#![expect(unsafe_code, reason = "exports an unmangled C symbol for the native linker fixture")] + use std::ffi::{c_char, CStr}; #[unsafe(no_mangle)] @@ -5,6 +7,7 @@ pub extern "C" fn ledger_total(text: *const c_char) -> i64 { if text.is_null() { return -1; } + // SAFETY: the caller passes a non-null NUL-terminated string. let Ok(text) = unsafe { CStr::from_ptr(text) }.to_str() else { return -1; }; diff --git a/apple/tests/fixtures/shared_core/core.rs b/apple/tests/fixtures/shared_core/core.rs index 37cc8a8fc2..ad60d0c333 100644 --- a/apple/tests/fixtures/shared_core/core.rs +++ b/apple/tests/fixtures/shared_core/core.rs @@ -1,3 +1,5 @@ +#![expect(unsafe_code, reason = "exports an unmangled C symbol for the native linker fixture")] + use std::ffi::{c_char, CStr}; use shared_tasks::{reply, Board}; @@ -7,6 +9,7 @@ pub extern "C" fn shared_core_open(board: *const c_char) -> i32 { if board.is_null() { return -1; } + // SAFETY: the caller passes a non-null NUL-terminated string. let Ok(text) = unsafe { CStr::from_ptr(board) }.to_str() else { return -1; }; diff --git a/apple/tests/fixtures/swift_app/ledger.rs b/apple/tests/fixtures/swift_app/ledger.rs index c6c676793c..b7f68ca9e1 100644 --- a/apple/tests/fixtures/swift_app/ledger.rs +++ b/apple/tests/fixtures/swift_app/ledger.rs @@ -1,3 +1,5 @@ +#![expect(unsafe_code, reason = "exports an unmangled C symbol for the native linker fixture")] + use std::ffi::{c_char, CStr}; #[unsafe(no_mangle)] @@ -5,6 +7,7 @@ pub extern "C" fn ledger_total(text: *const c_char) -> i64 { if text.is_null() { return -1; } + // SAFETY: the caller passes a non-null NUL-terminated string. let Ok(text) = unsafe { CStr::from_ptr(text) }.to_str() else { return -1; }; diff --git a/apple/tests/fixtures/xcframework_share/share.rs b/apple/tests/fixtures/xcframework_share/share.rs index 598773c85a..8b1a6d8a98 100644 --- a/apple/tests/fixtures/xcframework_share/share.rs +++ b/apple/tests/fixtures/xcframework_share/share.rs @@ -1,3 +1,5 @@ +#![expect(unsafe_code, reason = "exports an unmangled C symbol for the native linker fixture")] + use std::ffi::{c_char, CStr}; #[unsafe(no_mangle)] @@ -5,6 +7,7 @@ pub extern "C" fn share_total(text: *const c_char) -> i64 { if text.is_null() { return -1; } + // SAFETY: the caller passes a non-null NUL-terminated string. let Ok(text) = unsafe { CStr::from_ptr(text) }.to_str() else { return -1; }; diff --git a/deploy/tests/fixtures/consumer_archive/app.rs b/deploy/tests/fixtures/consumer_archive/app.rs index 1ea3cbbb4b..62cb753e2b 100644 --- a/deploy/tests/fixtures/consumer_archive/app.rs +++ b/deploy/tests/fixtures/consumer_archive/app.rs @@ -1,3 +1,5 @@ +#![expect(unsafe_code, reason = "the fixture exists to call across the C FFI boundary")] + use std::path::PathBuf; unsafe extern "C" { diff --git a/rust/tests/fixtures/consumer_abi/src/lib.rs b/rust/tests/fixtures/consumer_abi/src/lib.rs index 47242404a5..199ba0d5cb 100644 --- a/rust/tests/fixtures/consumer_abi/src/lib.rs +++ b/rust/tests/fixtures/consumer_abi/src/lib.rs @@ -1,3 +1,5 @@ +#![expect(unsafe_code, reason = "the fixture exists to call across the C FFI boundary")] + use std::ffi::{c_char, CStr}; pub const API_VERSION: i32 = 1; diff --git a/rust/tests/fixtures/consumer_native/src/lib.rs b/rust/tests/fixtures/consumer_native/src/lib.rs index e1b5a4f78c..608cd68eb3 100644 --- a/rust/tests/fixtures/consumer_native/src/lib.rs +++ b/rust/tests/fixtures/consumer_native/src/lib.rs @@ -1,3 +1,5 @@ +#![expect(unsafe_code, reason = "the fixture exists to call across the C FFI boundary")] + include!(concat!(env!("OUT_DIR"), "/bindings.rs")); include!(concat!(env!("OUT_DIR"), "/build_probe.rs")); diff --git a/rust/tests/fixtures/hello/src/cdylib.rs b/rust/tests/fixtures/hello/src/cdylib.rs index 5600515070..f76dee22bb 100644 --- a/rust/tests/fixtures/hello/src/cdylib.rs +++ b/rust/tests/fixtures/hello/src/cdylib.rs @@ -1,2 +1,4 @@ +#![expect(unsafe_code, reason = "exports an unmangled C symbol for the native linker fixture")] + #[unsafe(no_mangle)] pub extern "C" fn hello_cdylib() {} diff --git a/rust/tests/fixtures/hello/src/staticlib.rs b/rust/tests/fixtures/hello/src/staticlib.rs index b188e69056..5371414990 100644 --- a/rust/tests/fixtures/hello/src/staticlib.rs +++ b/rust/tests/fixtures/hello/src/staticlib.rs @@ -1,2 +1,4 @@ +#![expect(unsafe_code, reason = "exports an unmangled C symbol for the native linker fixture")] + #[unsafe(no_mangle)] pub extern "C" fn hello_staticlib() {} diff --git a/rust/tests/fixtures/native_call/src/lib.rs b/rust/tests/fixtures/native_call/src/lib.rs index 44e10a7987..c8a9d123a9 100644 --- a/rust/tests/fixtures/native_call/src/lib.rs +++ b/rust/tests/fixtures/native_call/src/lib.rs @@ -1,3 +1,5 @@ +#![expect(unsafe_code, reason = "the fixture exists to call across the C FFI boundary")] + include!(concat!(env!("OUT_DIR"), "/bindings.rs")); include!(concat!(env!("OUT_DIR"), "/build_probe.rs")); diff --git a/rust/tests/fixtures/native_call/src/native_cc.rs b/rust/tests/fixtures/native_call/src/native_cc.rs index 144a631745..95b316a119 100644 --- a/rust/tests/fixtures/native_call/src/native_cc.rs +++ b/rust/tests/fixtures/native_call/src/native_cc.rs @@ -1,3 +1,5 @@ +#![expect(unsafe_code, reason = "the fixture exists to call across the C FFI boundary")] + include!(concat!(env!("OUT_DIR"), "/cc_probe.rs")); unsafe extern "C" { diff --git a/rust/tests/fixtures/wasm_bindgen/src/lib.rs b/rust/tests/fixtures/wasm_bindgen/src/lib.rs index 7e4bdb7f3f..6cba5bf5f8 100644 --- a/rust/tests/fixtures/wasm_bindgen/src/lib.rs +++ b/rust/tests/fixtures/wasm_bindgen/src/lib.rs @@ -1,3 +1,5 @@ +#![expect(unsafe_code, reason = "the fixture exists to call across the C FFI boundary")] + use wasm_bindgen::prelude::*; pub fn greeting(name: &str) -> String {