Skip to content

Commit 5dabad6

Browse files
authored
reason inside #[allow] (#7049)
1 parent 23a8966 commit 5dabad6

19 files changed

Lines changed: 72 additions & 27 deletions

File tree

crates/codegen/src/compile.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5524,8 +5524,8 @@ impl Compiler {
55245524
"too many sub-patterns in mapping pattern".to_string(),
55255525
)));
55265526
}
5527-
#[allow(clippy::cast_possible_truncation)]
5528-
let size = size as u32; // checked right before
5527+
#[allow(clippy::cast_possible_truncation, reason = "checked right before")]
5528+
let size = size as u32;
55295529

55305530
// Step 2: If we have keys to match
55315531
if size > 0 {

crates/common/src/lock/cell_lock.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ pub struct RawCellMutex {
1010
}
1111

1212
unsafe impl RawMutex for RawCellMutex {
13-
#[allow(clippy::declare_interior_mutable_const)]
13+
#[allow(
14+
clippy::declare_interior_mutable_const,
15+
reason = "const lock initializer intentionally uses interior mutability"
16+
)]
1417
const INIT: Self = Self {
1518
locked: Cell::new(false),
1619
};
@@ -60,7 +63,10 @@ impl RawCellRwLock {
6063
}
6164

6265
unsafe impl RawRwLock for RawCellRwLock {
63-
#[allow(clippy::declare_interior_mutable_const)]
66+
#[allow(
67+
clippy::declare_interior_mutable_const,
68+
reason = "const rwlock initializer intentionally uses interior mutability"
69+
)]
6470
const INIT: Self = Self {
6571
state: Cell::new(0),
6672
};

crates/common/src/lock/thread_mutex.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ pub struct RawThreadMutex<R: RawMutex, G: GetThreadId> {
2020
}
2121

2222
impl<R: RawMutex, G: GetThreadId> RawThreadMutex<R, G> {
23-
#[allow(clippy::declare_interior_mutable_const)]
23+
#[allow(
24+
clippy::declare_interior_mutable_const,
25+
reason = "const initializer for lock primitive contains atomics by design"
26+
)]
2427
pub const INIT: Self = Self {
2528
owner: AtomicUsize::new(0),
2629
mutex: R::INIT,

crates/common/src/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ pub mod levenshtein {
491491

492492
pub fn levenshtein_distance(a: &[u8], b: &[u8], max_cost: usize) -> usize {
493493
thread_local! {
494-
#[allow(clippy::declare_interior_mutable_const)]
494+
#[allow(clippy::declare_interior_mutable_const, reason = "thread-local scratch buffer uses const initializer with RefCell")]
495495
static BUFFER: RefCell<[usize; MAX_STRING_SIZE]> = const {
496496
RefCell::new([0usize; MAX_STRING_SIZE])
497497
};

crates/derive-impl/src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl ItemNursery {
7676
impl ToTokens for ValidatedItemNursery {
7777
fn to_tokens(&self, tokens: &mut TokenStream) {
7878
let mut sorted = self.0.0.clone();
79-
sorted.sort_by(|a, b| a.sort_order.cmp(&b.sort_order));
79+
sorted.sort_by_key(|a| a.sort_order);
8080
tokens.extend(sorted.iter().map(|item| {
8181
let cfgs = &item.cfgs;
8282
let tokens = &item.tokens;

crates/sre_engine/src/engine.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,10 @@ fn _match<S: StrDrive>(req: &Request<'_, S>, state: &mut State, mut ctx: MatchCo
283283
let mut context_stack = vec![];
284284
let mut popped_result = false;
285285

286-
// NOTE: 'result loop is not an actual loop but break label
287-
#[allow(clippy::never_loop)]
286+
#[allow(
287+
clippy::never_loop,
288+
reason = "'result loop is not an actual loop but break label"
289+
)]
288290
'coro: loop {
289291
popped_result = 'result: loop {
290292
let yielded = 'context: loop {

crates/stdlib/build.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ fn main() {
44
println!(r#"cargo::rustc-check-cfg=cfg(osslconf, values("OPENSSL_NO_COMP"))"#);
55
println!(r#"cargo::rustc-check-cfg=cfg(openssl_vendored)"#);
66

7-
#[allow(clippy::unusual_byte_groupings)]
7+
#[allow(
8+
clippy::unusual_byte_groupings,
9+
reason = "hex groups follow OpenSSL version field boundaries"
10+
)]
811
let ossl_vers = [
912
(0x1_00_01_00_0, "ossl101"),
1013
(0x1_00_02_00_0, "ossl102"),
@@ -25,7 +28,10 @@ fn main() {
2528

2629
#[cfg(feature = "ssl-openssl")]
2730
{
28-
#[allow(clippy::unusual_byte_groupings)]
31+
#[allow(
32+
clippy::unusual_byte_groupings,
33+
reason = "OpenSSL version number is parsed with grouped hex fields"
34+
)]
2935
if let Ok(v) = std::env::var("DEP_OPENSSL_VERSION_NUMBER") {
3036
println!("cargo:rustc-env=OPENSSL_API_VERSION={v}");
3137
// cfg setup from openssl crate's build script

crates/stdlib/src/json/machinery.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ static ESCAPE_CHARS: [&str; 0x20] = [
4444
// And which one need to be escaped (1)
4545
// The characters that need escaping are 0x00 to 0x1F, 0x22 ("), 0x5C (\), 0x7F (DEL)
4646
// Non-ASCII unicode characters can be safely included in a JSON string
47-
#[allow(clippy::unusual_byte_groupings)] // it's groups of 16, come on clippy
47+
#[allow(
48+
clippy::unusual_byte_groupings,
49+
reason = "groups of 16 are intentional here"
50+
)]
4851
static NEEDS_ESCAPING_BITSET: [u64; 4] = [
4952
//fedcba9876543210_fedcba9876543210_fedcba9876543210_fedcba9876543210
5053
0b0000000000000000_0000000000000100_1111111111111111_1111111111111111, // 3_2_1_0

crates/stdlib/src/overlapped.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,10 @@ mod _overlapped {
11201120
}
11211121

11221122
// TransmitFile
1123-
#[allow(clippy::too_many_arguments)]
1123+
#[allow(
1124+
clippy::too_many_arguments,
1125+
reason = "mirrors Windows TransmitFile argument structure"
1126+
)]
11241127
#[pymethod]
11251128
fn TransmitFile(
11261129
zelf: &Py<Self>,

crates/stdlib/src/statistics.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ mod _statistics {
55
use crate::vm::{PyResult, VirtualMachine, function::ArgIntoFloat};
66

77
// See https://github.com/python/cpython/blob/6846d6712a0894f8e1a91716c11dd79f42864216/Modules/_statisticsmodule.c#L28-L120
8-
#[allow(clippy::excessive_precision)]
8+
#[allow(
9+
clippy::excessive_precision,
10+
reason = "constants are kept at CPython precision"
11+
)]
912
fn normal_dist_inv_cdf(p: f64, mu: f64, sigma: f64) -> Option<f64> {
1013
if p <= 0.0 || p >= 1.0 {
1114
return None;
@@ -53,7 +56,10 @@ mod _statistics {
5356
let r = (-(r.ln())).sqrt();
5457
let num;
5558
let den;
56-
#[allow(clippy::excessive_precision)]
59+
#[allow(
60+
clippy::excessive_precision,
61+
reason = "piecewise polynomial coefficients match CPython"
62+
)]
5763
if r <= 5.0 {
5864
let r = r - 1.6;
5965
// Hash sum-49.33206503301610289036

0 commit comments

Comments
 (0)