From f63d1686ae947e5fb603402b0ae2e7b832b9384f Mon Sep 17 00:00:00 2001 From: "Jeong, YunWon" Date: Sun, 8 Feb 2026 16:36:42 +0900 Subject: [PATCH] reason inside #[allow] --- crates/codegen/src/compile.rs | 4 ++-- crates/common/src/lock/cell_lock.rs | 10 ++++++++-- crates/common/src/lock/thread_mutex.rs | 5 ++++- crates/common/src/str.rs | 2 +- crates/derive-impl/src/util.rs | 2 +- crates/sre_engine/src/engine.rs | 6 ++++-- crates/stdlib/build.rs | 10 ++++++++-- crates/stdlib/src/json/machinery.rs | 5 ++++- crates/stdlib/src/overlapped.rs | 5 ++++- crates/stdlib/src/statistics.rs | 10 ++++++++-- crates/vm/src/builtins/function.rs | 1 - crates/vm/src/builtins/module.rs | 5 ++++- crates/vm/src/builtins/str.rs | 5 ++++- crates/vm/src/exceptions.rs | 5 ++++- crates/vm/src/macros.rs | 6 +++--- crates/vm/src/object/core.rs | 3 +-- crates/vm/src/signal.rs | 5 ++++- crates/vm/src/stdlib/ctypes/base.rs | 5 ++++- crates/vm/src/stdlib/winapi.rs | 5 ++++- 19 files changed, 72 insertions(+), 27 deletions(-) diff --git a/crates/codegen/src/compile.rs b/crates/codegen/src/compile.rs index ac62043fa66..f218431da36 100644 --- a/crates/codegen/src/compile.rs +++ b/crates/codegen/src/compile.rs @@ -5524,8 +5524,8 @@ impl Compiler { "too many sub-patterns in mapping pattern".to_string(), ))); } - #[allow(clippy::cast_possible_truncation)] - let size = size as u32; // checked right before + #[allow(clippy::cast_possible_truncation, reason = "checked right before")] + let size = size as u32; // Step 2: If we have keys to match if size > 0 { diff --git a/crates/common/src/lock/cell_lock.rs b/crates/common/src/lock/cell_lock.rs index 9732b973aeb..ab9cfb08c84 100644 --- a/crates/common/src/lock/cell_lock.rs +++ b/crates/common/src/lock/cell_lock.rs @@ -10,7 +10,10 @@ pub struct RawCellMutex { } unsafe impl RawMutex for RawCellMutex { - #[allow(clippy::declare_interior_mutable_const)] + #[allow( + clippy::declare_interior_mutable_const, + reason = "const lock initializer intentionally uses interior mutability" + )] const INIT: Self = Self { locked: Cell::new(false), }; @@ -60,7 +63,10 @@ impl RawCellRwLock { } unsafe impl RawRwLock for RawCellRwLock { - #[allow(clippy::declare_interior_mutable_const)] + #[allow( + clippy::declare_interior_mutable_const, + reason = "const rwlock initializer intentionally uses interior mutability" + )] const INIT: Self = Self { state: Cell::new(0), }; diff --git a/crates/common/src/lock/thread_mutex.rs b/crates/common/src/lock/thread_mutex.rs index ec10ab1f181..2cabf7ea4cd 100644 --- a/crates/common/src/lock/thread_mutex.rs +++ b/crates/common/src/lock/thread_mutex.rs @@ -20,7 +20,10 @@ pub struct RawThreadMutex { } impl RawThreadMutex { - #[allow(clippy::declare_interior_mutable_const)] + #[allow( + clippy::declare_interior_mutable_const, + reason = "const initializer for lock primitive contains atomics by design" + )] pub const INIT: Self = Self { owner: AtomicUsize::new(0), mutex: R::INIT, diff --git a/crates/common/src/str.rs b/crates/common/src/str.rs index a250c5865d3..35588c5dc6d 100644 --- a/crates/common/src/str.rs +++ b/crates/common/src/str.rs @@ -491,7 +491,7 @@ pub mod levenshtein { pub fn levenshtein_distance(a: &[u8], b: &[u8], max_cost: usize) -> usize { thread_local! { - #[allow(clippy::declare_interior_mutable_const)] + #[allow(clippy::declare_interior_mutable_const, reason = "thread-local scratch buffer uses const initializer with RefCell")] static BUFFER: RefCell<[usize; MAX_STRING_SIZE]> = const { RefCell::new([0usize; MAX_STRING_SIZE]) }; diff --git a/crates/derive-impl/src/util.rs b/crates/derive-impl/src/util.rs index cdf18e65aef..a4bf7e6a8fe 100644 --- a/crates/derive-impl/src/util.rs +++ b/crates/derive-impl/src/util.rs @@ -76,7 +76,7 @@ impl ItemNursery { impl ToTokens for ValidatedItemNursery { fn to_tokens(&self, tokens: &mut TokenStream) { let mut sorted = self.0.0.clone(); - sorted.sort_by(|a, b| a.sort_order.cmp(&b.sort_order)); + sorted.sort_by_key(|a| a.sort_order); tokens.extend(sorted.iter().map(|item| { let cfgs = &item.cfgs; let tokens = &item.tokens; diff --git a/crates/sre_engine/src/engine.rs b/crates/sre_engine/src/engine.rs index f1f25a2d920..249b599b030 100644 --- a/crates/sre_engine/src/engine.rs +++ b/crates/sre_engine/src/engine.rs @@ -283,8 +283,10 @@ fn _match(req: &Request<'_, S>, state: &mut State, mut ctx: MatchCo let mut context_stack = vec![]; let mut popped_result = false; - // NOTE: 'result loop is not an actual loop but break label - #[allow(clippy::never_loop)] + #[allow( + clippy::never_loop, + reason = "'result loop is not an actual loop but break label" + )] 'coro: loop { popped_result = 'result: loop { let yielded = 'context: loop { diff --git a/crates/stdlib/build.rs b/crates/stdlib/build.rs index 83ebd81ead6..95c34c4fb3c 100644 --- a/crates/stdlib/build.rs +++ b/crates/stdlib/build.rs @@ -4,7 +4,10 @@ fn main() { println!(r#"cargo::rustc-check-cfg=cfg(osslconf, values("OPENSSL_NO_COMP"))"#); println!(r#"cargo::rustc-check-cfg=cfg(openssl_vendored)"#); - #[allow(clippy::unusual_byte_groupings)] + #[allow( + clippy::unusual_byte_groupings, + reason = "hex groups follow OpenSSL version field boundaries" + )] let ossl_vers = [ (0x1_00_01_00_0, "ossl101"), (0x1_00_02_00_0, "ossl102"), @@ -25,7 +28,10 @@ fn main() { #[cfg(feature = "ssl-openssl")] { - #[allow(clippy::unusual_byte_groupings)] + #[allow( + clippy::unusual_byte_groupings, + reason = "OpenSSL version number is parsed with grouped hex fields" + )] if let Ok(v) = std::env::var("DEP_OPENSSL_VERSION_NUMBER") { println!("cargo:rustc-env=OPENSSL_API_VERSION={v}"); // cfg setup from openssl crate's build script diff --git a/crates/stdlib/src/json/machinery.rs b/crates/stdlib/src/json/machinery.rs index f33a135ab20..2102d437396 100644 --- a/crates/stdlib/src/json/machinery.rs +++ b/crates/stdlib/src/json/machinery.rs @@ -44,7 +44,10 @@ static ESCAPE_CHARS: [&str; 0x20] = [ // And which one need to be escaped (1) // The characters that need escaping are 0x00 to 0x1F, 0x22 ("), 0x5C (\), 0x7F (DEL) // Non-ASCII unicode characters can be safely included in a JSON string -#[allow(clippy::unusual_byte_groupings)] // it's groups of 16, come on clippy +#[allow( + clippy::unusual_byte_groupings, + reason = "groups of 16 are intentional here" +)] static NEEDS_ESCAPING_BITSET: [u64; 4] = [ //fedcba9876543210_fedcba9876543210_fedcba9876543210_fedcba9876543210 0b0000000000000000_0000000000000100_1111111111111111_1111111111111111, // 3_2_1_0 diff --git a/crates/stdlib/src/overlapped.rs b/crates/stdlib/src/overlapped.rs index 2f266a94ee8..779fe31efe5 100644 --- a/crates/stdlib/src/overlapped.rs +++ b/crates/stdlib/src/overlapped.rs @@ -1120,7 +1120,10 @@ mod _overlapped { } // TransmitFile - #[allow(clippy::too_many_arguments)] + #[allow( + clippy::too_many_arguments, + reason = "mirrors Windows TransmitFile argument structure" + )] #[pymethod] fn TransmitFile( zelf: &Py, diff --git a/crates/stdlib/src/statistics.rs b/crates/stdlib/src/statistics.rs index 641d8864ed3..2f7eb85284a 100644 --- a/crates/stdlib/src/statistics.rs +++ b/crates/stdlib/src/statistics.rs @@ -5,7 +5,10 @@ mod _statistics { use crate::vm::{PyResult, VirtualMachine, function::ArgIntoFloat}; // See https://github.com/python/cpython/blob/6846d6712a0894f8e1a91716c11dd79f42864216/Modules/_statisticsmodule.c#L28-L120 - #[allow(clippy::excessive_precision)] + #[allow( + clippy::excessive_precision, + reason = "constants are kept at CPython precision" + )] fn normal_dist_inv_cdf(p: f64, mu: f64, sigma: f64) -> Option { if p <= 0.0 || p >= 1.0 { return None; @@ -53,7 +56,10 @@ mod _statistics { let r = (-(r.ln())).sqrt(); let num; let den; - #[allow(clippy::excessive_precision)] + #[allow( + clippy::excessive_precision, + reason = "piecewise polynomial coefficients match CPython" + )] if r <= 5.0 { let r = r - 1.6; // Hash sum-49.33206503301610289036 diff --git a/crates/vm/src/builtins/function.rs b/crates/vm/src/builtins/function.rs index 3a85e7d16fb..1a6d4520083 100644 --- a/crates/vm/src/builtins/function.rs +++ b/crates/vm/src/builtins/function.rs @@ -1067,7 +1067,6 @@ impl PyPayload for PyBoundMethod { impl Representable for PyBoundMethod { #[inline] fn repr_str(zelf: &Py, vm: &VirtualMachine) -> PyResult { - #[allow(clippy::needless_match)] // False positive on nightly let func_name = if let Some(qname) = vm.get_attribute_opt(zelf.function.clone(), "__qualname__")? { Some(qname) diff --git a/crates/vm/src/builtins/module.rs b/crates/vm/src/builtins/module.rs index 60ffb1487fa..805516b2d99 100644 --- a/crates/vm/src/builtins/module.rs +++ b/crates/vm/src/builtins/module.rs @@ -81,7 +81,10 @@ impl PyModuleDef { } } -#[allow(clippy::new_without_default)] // avoid Default implementation +#[allow( + clippy::new_without_default, + reason = "avoid a misleading Default implementation" +)] #[pyclass(module = false, name = "module")] #[derive(Debug)] pub struct PyModule { diff --git a/crates/vm/src/builtins/str.rs b/crates/vm/src/builtins/str.rs index e8ba6eb915e..1721f921fea 100644 --- a/crates/vm/src/builtins/str.rs +++ b/crates/vm/src/builtins/str.rs @@ -232,7 +232,10 @@ pub trait AsPyStr<'a> where Self: 'a, { - #[allow(clippy::wrong_self_convention)] // to implement on refs + #[allow( + clippy::wrong_self_convention, + reason = "this trait is intentionally implemented for references" + )] fn as_pystr(self, ctx: &Context) -> &'a Py; } diff --git a/crates/vm/src/exceptions.rs b/crates/vm/src/exceptions.rs index f751d0677a1..27dc45410f0 100644 --- a/crates/vm/src/exceptions.rs +++ b/crates/vm/src/exceptions.rs @@ -925,7 +925,10 @@ impl ExceptionZoo { } // TODO: remove it after fixing `errno` / `winerror` problem - #[allow(clippy::redundant_clone)] + #[allow( + clippy::redundant_clone, + reason = "temporary workaround until errno/winerror handling is fixed" + )] pub fn extend(ctx: &Context) { use self::types::*; diff --git a/crates/vm/src/macros.rs b/crates/vm/src/macros.rs index f5c912d89cf..32f3e4566ea 100644 --- a/crates/vm/src/macros.rs +++ b/crates/vm/src/macros.rs @@ -116,12 +116,12 @@ macro_rules! match_class { // The default arm, binding the original object to the specified identifier. (match ($obj:expr) { $binding:ident => $default:expr $(,)? }) => {{ - #[allow(clippy::redundant_locals)] + #[allow(clippy::redundant_locals, reason = "macro arm intentionally binds expression once to a local")] let $binding = $obj; $default }}; (match ($obj:expr) { ref $binding:ident => $default:expr $(,)? }) => {{ - #[allow(clippy::redundant_locals)] + #[allow(clippy::redundant_locals, reason = "macro arm intentionally binds expression once to a local reference")] let $binding = &$obj; $default }}; @@ -190,7 +190,7 @@ macro_rules! identifier( macro_rules! identifier_utf8( ($as_ctx:expr, $name:ident) => { // Safety: All known identifiers are ascii strings. - #[allow(clippy::macro_metavars_in_unsafe)] + #[allow(clippy::macro_metavars_in_unsafe, reason = "known identifiers are ASCII and downcast target is fixed")] unsafe { $as_ctx.as_ref().names.$name.as_object().downcast_unchecked_ref::<$crate::builtins::PyUtf8Str>() } }; ); diff --git a/crates/vm/src/object/core.rs b/crates/vm/src/object/core.rs index 55626a0d8d4..4d61a208241 100644 --- a/crates/vm/src/object/core.rs +++ b/crates/vm/src/object/core.rs @@ -550,7 +550,6 @@ pub struct PyWeak { cfg_if::cfg_if! { if #[cfg(feature = "threading")] { - #[allow(clippy::non_send_fields_in_send_ty)] // false positive? unsafe impl Send for PyWeak {} unsafe impl Sync for PyWeak {} } @@ -1631,7 +1630,7 @@ macro_rules! partially_init { ) => {{ // check all the fields are there but *don't* actually run it - #[allow(clippy::diverging_sub_expression)] // FIXME: better way than using `if false`? + #[allow(clippy::diverging_sub_expression, reason = "intentional compile-time field check in an unreachable branch")] if false { #[allow(invalid_value, dead_code, unreachable_code)] let _ = {$ty { diff --git a/crates/vm/src/signal.rs b/crates/vm/src/signal.rs index 3ad207b333d..42d9fa4c71c 100644 --- a/crates/vm/src/signal.rs +++ b/crates/vm/src/signal.rs @@ -10,7 +10,10 @@ use std::sync::mpsc; pub(crate) const NSIG: usize = 64; static ANY_TRIGGERED: AtomicBool = AtomicBool::new(false); // hack to get around const array repeat expressions, rust issue #79270 -#[allow(clippy::declare_interior_mutable_const)] +#[allow( + clippy::declare_interior_mutable_const, + reason = "workaround for const array repeat limitation (rust issue #79270)" +)] const ATOMIC_FALSE: AtomicBool = AtomicBool::new(false); pub(crate) static TRIGGERS: [AtomicBool; NSIG] = [ATOMIC_FALSE; NSIG]; diff --git a/crates/vm/src/stdlib/ctypes/base.rs b/crates/vm/src/stdlib/ctypes/base.rs index 058b19c59c3..0ef10ea6c73 100644 --- a/crates/vm/src/stdlib/ctypes/base.rs +++ b/crates/vm/src/stdlib/ctypes/base.rs @@ -2054,7 +2054,10 @@ pub(super) fn bytes_to_pyobject( let wchars = unsafe { core::slice::from_raw_parts(ptr as *const libc::wchar_t, len) }; // wchar_t is i32 on some platforms and u32 on others - #[allow(clippy::unnecessary_cast)] + #[allow( + clippy::unnecessary_cast, + reason = "wchar_t is i32 on some platforms and u32 on others" + )] let s: String = wchars .iter() .filter_map(|&c| char::from_u32(c as u32)) diff --git a/crates/vm/src/stdlib/winapi.rs b/crates/vm/src/stdlib/winapi.rs index 4c3849d1abc..c176568cfc5 100644 --- a/crates/vm/src/stdlib/winapi.rs +++ b/crates/vm/src/stdlib/winapi.rs @@ -120,7 +120,10 @@ mod _winapi { /// CreateFile - Create or open a file or I/O device. #[pyfunction] - #[allow(clippy::too_many_arguments)] + #[allow( + clippy::too_many_arguments, + reason = "matches Win32 CreateFile parameter structure" + )] fn CreateFile( file_name: PyStrRef, desired_access: u32,