reason inside #[allow] (#7049)

This commit is contained in:
Jeong, YunWon authored and GitHub committed 2026-02-08 13:11:50 +00:00
1 parent fcc75a11b6
commit a5fc3a82de
19 files changed
+72 -27

No files matched your search

+2 -2
View File
@@ -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 {
+8 -2
View File
@@ -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),
};
+4 -1
View File
@@ -20,7 +20,10 @@ pub struct RawThreadMutex<R: RawMutex, G: GetThreadId> {
}
impl<R: RawMutex, G: GetThreadId> RawThreadMutex<R, G> {
#[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,
+1 -1
View File
@@ -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])
};
+1 -1
View File
@@ -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;
+4 -2
View File
@@ -283,8 +283,10 @@ fn _match<S: StrDrive>(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 {
+8 -2
View File
@@ -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
+4 -1
View File
@@ -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
+4 -1
View File
@@ -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<Self>,
+8 -2
View File
@@ -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<f64> {
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
-1
View File
@@ -1067,7 +1067,6 @@ impl PyPayload for PyBoundMethod {
impl Representable for PyBoundMethod {
#[inline]
fn repr_str(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<String> {
#[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)
+4 -1
View File
@@ -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 {
+4 -1
View File
@@ -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<PyStr>;
}
+4 -1
View File
@@ -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::*;
+3 -3
View File
@@ -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>() }
};
);
+1 -2
View File
@@ -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 {
+4 -1
View File
@@ -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];
+4 -1
View File
@@ -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))
+4 -1
View File
@@ -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,