From cfbb1d667d1b5c6ce068c35ec2fff3f9d7ecc692 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Wed, 12 Aug 2026 14:06:15 +0000 Subject: [PATCH 01/34] clippy::manual_is_ascii_check --- library/core/src/char/methods.rs | 2 ++ library/core/src/num/mod.rs | 1 + 2 files changed, 3 insertions(+) diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index f6930e0a60d42..f59219c09dc28 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -1,5 +1,7 @@ //! impl char {} +#![expect(clippy::manual_is_ascii_check, reason = "this module implements various is_ascii checks")] + use super::*; use crate::panic::const_panic; use crate::slice; diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index 3fe7b95283446..59e470800dbd3 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -1,6 +1,7 @@ //! Numeric traits and functions for the built-in numeric types. #![stable(feature = "rust1", since = "1.0.0")] +#![expect(clippy::manual_is_ascii_check, reason = "this module implements various is_ascii checks")] use crate::convert::{BoundedCastFromInt, CheckedCastFromInt}; use crate::panic::const_panic; From e4f6415d71fb238afd51361ceec286f08390a599 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Wed, 12 Aug 2026 14:12:27 +0000 Subject: [PATCH 02/34] clippy::manual_ignore_case_cmp --- library/core/src/ascii/ascii_char.rs | 2 +- library/core/src/char/methods.rs | 1 + library/core/src/num/mod.rs | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/library/core/src/ascii/ascii_char.rs b/library/core/src/ascii/ascii_char.rs index de1adf9c9ec7c..801144826a2ed 100644 --- a/library/core/src/ascii/ascii_char.rs +++ b/library/core/src/ascii/ascii_char.rs @@ -635,7 +635,7 @@ impl AsciiChar { pub const fn eq_ignore_case(self, other: Self) -> bool { // FIXME(const-hack) `arg.to_u8().to_ascii_lowercase()` -> `arg.to_lowercase()` // once `PartialEq` is const for `Self`. - self.to_u8().to_ascii_lowercase() == other.to_u8().to_ascii_lowercase() + self.to_u8().eq_ignore_ascii_case(&other.to_u8()) } /// Converts this value to its upper case equivalent in-place. diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index f59219c09dc28..8009f6514945e 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -1987,6 +1987,7 @@ impl char { /// [to_ascii_lowercase]: #method.to_ascii_lowercase #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.52.0")] + #[expect(clippy::manual_ignore_case_cmp, reason = "implements eq_ignore_ascii_case")] #[inline] pub const fn eq_ignore_ascii_case(&self, other: &char) -> bool { self.to_ascii_lowercase() == other.to_ascii_lowercase() diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index 59e470800dbd3..db41d23770477 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -732,6 +732,7 @@ impl u8 { /// ``` #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.52.0")] + #[expect(clippy::manual_ignore_case_cmp, reason = "implements eq_ignore_ascii_case")] #[inline] pub const fn eq_ignore_ascii_case(&self, other: &u8) -> bool { self.to_ascii_lowercase() == other.to_ascii_lowercase() From 0f684e5dd9138654acff96d8cff9d2edcab93972 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Wed, 12 Aug 2026 15:25:02 +0000 Subject: [PATCH 03/34] clippy::manual_hash_one --- library/core/src/hash/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/core/src/hash/mod.rs b/library/core/src/hash/mod.rs index c7c8d57e1010d..f1a93a880e7f4 100644 --- a/library/core/src/hash/mod.rs +++ b/library/core/src/hash/mod.rs @@ -691,6 +691,7 @@ pub trait BuildHasher { /// ); /// ``` #[stable(feature = "build_hasher_simple_hash_one", since = "1.71.0")] + #[expect(clippy::manual_hash_one, reason = "implements hash_one")] fn hash_one(&self, x: T) -> u64 where Self: Sized, From cc299d706220ccf9499ebde99c3c923edb85d361 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Wed, 12 Aug 2026 15:53:51 +0000 Subject: [PATCH 04/34] clippy::excessive_precision --- library/core/src/num/f32.rs | 8 ++++---- library/core/src/num/f64.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index 723e64aa9ac54..3f7b33770fc08 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -438,7 +438,7 @@ impl f32 { /// [`MANTISSA_DIGITS`]: f32::MANTISSA_DIGITS #[stable(feature = "assoc_int_consts", since = "1.43.0")] #[rustc_diagnostic_item = "f32_epsilon"] - pub const EPSILON: f32 = 1.19209290e-07_f32; + pub const EPSILON: f32 = 1.1920929e-07_f32; /// Smallest finite `f32` value. /// @@ -446,14 +446,14 @@ impl f32 { /// /// [`MAX`]: f32::MAX #[stable(feature = "assoc_int_consts", since = "1.43.0")] - pub const MIN: f32 = -3.40282347e+38_f32; + pub const MIN: f32 = -3.4028235e+38_f32; /// Smallest positive normal `f32` value. /// /// Equal to 2[`MIN_EXP`] − 1. /// /// [`MIN_EXP`]: f32::MIN_EXP #[stable(feature = "assoc_int_consts", since = "1.43.0")] - pub const MIN_POSITIVE: f32 = 1.17549435e-38_f32; + pub const MIN_POSITIVE: f32 = 1.1754944e-38_f32; /// Largest finite `f32` value. /// /// Equal to @@ -462,7 +462,7 @@ impl f32 { /// [`MANTISSA_DIGITS`]: f32::MANTISSA_DIGITS /// [`MAX_EXP`]: f32::MAX_EXP #[stable(feature = "assoc_int_consts", since = "1.43.0")] - pub const MAX: f32 = 3.40282347e+38_f32; + pub const MAX: f32 = 3.4028235e+38_f32; /// One greater than the minimum possible *normal* power of 2 exponent /// for a significand bounded by 1 ≤ x < 2 (i.e. the IEEE definition). diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index d23b3e5616302..5bc2f8d0feb32 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -437,7 +437,7 @@ impl f64 { /// [`MANTISSA_DIGITS`]: f64::MANTISSA_DIGITS #[stable(feature = "assoc_int_consts", since = "1.43.0")] #[rustc_diagnostic_item = "f64_epsilon"] - pub const EPSILON: f64 = 2.2204460492503131e-16_f64; + pub const EPSILON: f64 = 2.220446049250313e-16_f64; /// Smallest finite `f64` value. /// From fc3b63de1a60e5e6bd517cdba193a4c79d1bd7a4 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Wed, 12 Aug 2026 16:06:42 +0000 Subject: [PATCH 05/34] clippy::partialeq_ne_impl --- library/alloc/src/lib.rs | 1 + library/core/src/lib.rs | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 09b752491673e..f7aa47cfb17ac 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -59,6 +59,7 @@ #![allow(unused_features)] #![allow(incomplete_features)] #![allow(unused_attributes)] +#![expect(clippy::partialeq_ne_impl, reason = "we need to implement ne for a lot of alloc types")] #![stable(feature = "alloc", since = "1.36.0")] #![doc( html_playground_url = "https://play.rust-lang.org/", diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index f026434acbbc1..2aacd5d99b19b 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -187,6 +187,10 @@ #![feature(x86_amx_intrinsics)] // tidy-alphabetical-end +// tidy-alphabetical-start +#![expect(clippy::partialeq_ne_impl, reason = "we need to implement ne for a lot of core types")] +// tidy-alphabetical-end + // allow using `core::` in intra-doc links #[allow(unused_extern_crates)] extern crate self as core; From 71411ff301e06b4352119b3e1569f4495be1157c Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 13 Aug 2026 00:36:30 +0000 Subject: [PATCH 06/34] clippy::manual_contains --- library/core/src/slice/cmp.rs | 2 ++ library/std/src/sys/path/windows_prefix.rs | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/library/core/src/slice/cmp.rs b/library/core/src/slice/cmp.rs index 70d2392dfb3c6..acb74c9916dfd 100644 --- a/library/core/src/slice/cmp.rs +++ b/library/core/src/slice/cmp.rs @@ -386,6 +386,7 @@ impl SliceContains for T where T: PartialEq, { + #[expect(clippy::manual_contains, reason = "implements slice_contains")] default fn slice_contains(&self, x: &[Self]) -> bool { x.iter().any(|y| *y == *self) } @@ -393,6 +394,7 @@ where impl SliceContains for T { #[inline] + #[expect(clippy::manual_contains, reason = "implements slice_contains")] default fn slice_contains(&self, x: &[Self]) -> bool { if size_of::() == 1 { // SAFETY: `BytewiseEq` guarantees that values have no padding or provenance and diff --git a/library/std/src/sys/path/windows_prefix.rs b/library/std/src/sys/path/windows_prefix.rs index b9dfe754485ab..2e80b345cec8f 100644 --- a/library/std/src/sys/path/windows_prefix.rs +++ b/library/std/src/sys/path/windows_prefix.rs @@ -68,7 +68,7 @@ pub fn parse_prefix(path: &OsStr) -> Option> { // \\ // It's a POSIX path. - if cfg!(target_os = "cygwin") && !path.as_encoded_bytes().iter().any(|&x| x == b'\\') { + if cfg!(target_os = "cygwin") && !path.as_encoded_bytes().contains(&b'\\') { return None; } @@ -76,7 +76,7 @@ pub fn parse_prefix(path: &OsStr) -> Option> { // separator. if let Some(parser) = parser.strip_prefix(r"?\") // Cygwin allows `/` in verbatim paths. - && (cfg!(target_os = "cygwin") || !parser.prefix_bytes().iter().any(|&x| x == b'/')) + && (cfg!(target_os = "cygwin") || !parser.prefix_bytes().contains(&b'/')) { // \\?\ if let Some(parser) = parser.strip_prefix(r"UNC\") { From 1110bbb92ce95e7608f4de0a18aff283ecde0693 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 13 Aug 2026 01:25:04 +0000 Subject: [PATCH 07/34] clippy::single_match --- library/core/src/intrinsics/mod.rs | 11 +++-------- library/std/src/sys/process/unix/unix.rs | 5 ++--- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs index 2316fc4318918..673454abaf04f 100644 --- a/library/core/src/intrinsics/mod.rs +++ b/library/core/src/intrinsics/mod.rs @@ -2915,14 +2915,9 @@ pub const fn contract_check_ensures bool + Copy, Ret>( // Do nothing ret } else { - match cond { - crate::option::Option::Some(cond) => { - if !cond(&ret) { - // Emit no unwind panic in case this was a safety requirement. - crate::panicking::panic_nounwind("failed ensures check"); - } - }, - crate::option::Option::None => {}, + if let crate::option::Option::Some(cond) = cond && !cond(&ret) { + // Emit no unwind panic in case this was a safety requirement. + crate::panicking::panic_nounwind("failed ensures check"); } ret } diff --git a/library/std/src/sys/process/unix/unix.rs b/library/std/src/sys/process/unix/unix.rs index 6103fa3576f37..ba1286e0e5a09 100644 --- a/library/std/src/sys/process/unix/unix.rs +++ b/library/std/src/sys/process/unix/unix.rs @@ -928,9 +928,8 @@ impl Command { msg.msg_controllen = size_of::() as _; msg.msg_control = (&raw mut cmsg) as *mut _; - match cvt_r(|| libc::recvmsg(sock.as_raw(), &mut msg, libc::MSG_CMSG_CLOEXEC)) { - Err(_) => return -1, - Ok(_) => {} + if cvt_r(|| libc::recvmsg(sock.as_raw(), &mut msg, libc::MSG_CMSG_CLOEXEC)).is_err() { + return -1; } let hdr = CMSG_FIRSTHDR((&raw mut msg) as *mut _); From 6b058b4872891f130b0fccaefd8e8d80336cc398 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 13 Aug 2026 01:17:56 +0000 Subject: [PATCH 08/34] clippy::match_as_ref --- library/core/src/option.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 5d86f851dbd1d..9aaa80db055a4 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -737,6 +737,7 @@ impl Option { /// println!("still can print text: {text:?}"); /// ``` #[inline] + #[expect(clippy::match_as_ref, reason = "implements as_ref")] #[rustc_const_stable(feature = "const_option_basics", since = "1.48.0")] #[stable(feature = "rust1", since = "1.0.0")] pub const fn as_ref(&self) -> Option<&T> { @@ -759,6 +760,7 @@ impl Option { /// assert_eq!(x, Some(42)); /// ``` #[inline] + #[expect(clippy::match_as_ref, reason = "implements as_mut")] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_option", since = "1.83.0")] pub const fn as_mut(&mut self) -> Option<&mut T> { From 4ff5c855c304949f039204dd807c8df677949ebe Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 13 Aug 2026 13:53:55 +0000 Subject: [PATCH 09/34] clippy::default_constructed_unit_structs --- library/alloc/src/collections/btree/set.rs | 4 ++-- library/core/src/field.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/alloc/src/collections/btree/set.rs b/library/alloc/src/collections/btree/set.rs index d06daa7c6c1b7..fb98c30ae5e69 100644 --- a/library/alloc/src/collections/btree/set.rs +++ b/library/alloc/src/collections/btree/set.rs @@ -901,7 +901,7 @@ impl BTreeSet { where T: Ord, { - self.map.insert(value, SetValZST::default()).is_none() + self.map.insert(value, SetValZST).is_none() } /// Adds a value to the set, replacing the existing element, if any, that is @@ -1483,7 +1483,7 @@ impl FromIterator for BTreeSet { impl BTreeSet { fn from_sorted_iter>(iter: I, alloc: A) -> BTreeSet { - let iter = iter.map(|k| (k, SetValZST::default())); + let iter = iter.map(|k| (k, SetValZST)); let map = BTreeMap::bulk_build_from_sorted_iter(iter, alloc); BTreeSet { map } } diff --git a/library/core/src/field.rs b/library/core/src/field.rs index 915a4c07b9e23..5a8ae7759bc1e 100644 --- a/library/core/src/field.rs +++ b/library/core/src/field.rs @@ -78,7 +78,7 @@ impl Default for FieldRepresentingType { fn default() -> Self { - Self { _phantom: PhantomData::default() } + Self { _phantom: PhantomData } } } From fe7445a91454c9b35497bea2175965aae506bb27 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 13 Aug 2026 13:56:21 +0000 Subject: [PATCH 10/34] clippy::redundant_closure --- library/alloc/src/collections/vec_deque/mod.rs | 4 ++-- library/std/src/sys/fs/windows.rs | 2 +- library/std/src/sys/process/unix/unix.rs | 2 +- library/std/src/thread/spawnhook.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 9095fc0d4abf4..a24e4d72fe38e 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -3312,7 +3312,7 @@ impl VecDeque { F: FnMut(&'a T) -> Ordering, { let (front, back) = self.as_slices(); - let cmp_back = back.first().map(|elem| f(elem)); + let cmp_back = back.first().map(&mut f); if let Some(Ordering::Equal) = cmp_back { Ok(front.len()) @@ -3423,7 +3423,7 @@ impl VecDeque { { let (front, back) = self.as_slices(); - if let Some(true) = back.first().map(|v| pred(v)) { + if let Some(true) = back.first().map(&mut pred) { back.partition_point(pred) + front.len() } else { front.partition_point(pred) diff --git a/library/std/src/sys/fs/windows.rs b/library/std/src/sys/fs/windows.rs index c10b266ccb726..4446a4c3e3c8f 100644 --- a/library/std/src/sys/fs/windows.rs +++ b/library/std/src/sys/fs/windows.rs @@ -1114,7 +1114,7 @@ impl FileAttr { } pub fn changed_u64(&self) -> Option { - self.change_time.as_ref().map(|c| to_u64(c)) + self.change_time.as_ref().map(to_u64) } pub fn volume_serial_number(&self) -> Option { diff --git a/library/std/src/sys/process/unix/unix.rs b/library/std/src/sys/process/unix/unix.rs index ba1286e0e5a09..8729ab65b86db 100644 --- a/library/std/src/sys/process/unix/unix.rs +++ b/library/std/src/sys/process/unix/unix.rs @@ -1316,7 +1316,7 @@ mod linux_child_ext { self.handle .pidfd .take() - .map(|fd| >::from_inner(fd)) + .map(>::from_inner) .ok_or_else(|| self) } } diff --git a/library/std/src/thread/spawnhook.rs b/library/std/src/thread/spawnhook.rs index 92fb586d39dcf..1bf22e0b0ea52 100644 --- a/library/std/src/thread/spawnhook.rs +++ b/library/std/src/thread/spawnhook.rs @@ -21,7 +21,7 @@ struct SpawnHooks { impl Drop for SpawnHooks { fn drop(&mut self) { let mut next = self.first.take(); - while let Some(SpawnHook { hook, next: n }) = next.and_then(|n| Arc::into_inner(n)) { + while let Some(SpawnHook { hook, next: n }) = next.and_then(Arc::into_inner) { drop(hook); next = n; } From 4c99af2ccf80dacc06a5c7ca0ba725147ff9f7b7 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 13 Aug 2026 14:12:28 +0000 Subject: [PATCH 11/34] clippy::derivable_impls --- library/alloc/src/bstr.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/library/alloc/src/bstr.rs b/library/alloc/src/bstr.rs index 9aa3064da886f..f48b2d52e80c1 100644 --- a/library/alloc/src/bstr.rs +++ b/library/alloc/src/bstr.rs @@ -42,7 +42,7 @@ use crate::vec::Vec; /// showing invalid UTF-8 as hex escapes or the Unicode replacement character, respectively. #[unstable(feature = "bstr", issue = "134915")] #[repr(transparent)] -#[derive(Clone)] +#[derive(Clone, Default)] #[doc(alias = "BString")] pub struct ByteString(pub Vec); @@ -187,13 +187,6 @@ impl BorrowMut for ByteString { // `impl BorrowMut for Vec` omitted to avoid inference failures -#[unstable(feature = "bstr", issue = "134915")] -impl Default for ByteString { - fn default() -> Self { - ByteString(Vec::new()) - } -} - // Omitted due to inference failures // // #[unstable(feature = "bstr", issue = "134915")] From bf79c6f96168929b64d79ce8e8da5f5ac9c63680 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 13 Aug 2026 14:14:36 +0000 Subject: [PATCH 12/34] clippy::partialeq_to_none --- library/std/src/fs.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 1e46ddb99e010..d0aa6cacd351b 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -3590,7 +3590,7 @@ impl DirBuilder { fn create_dir_all(&self, path: &Path) -> io::Result<()> { // if path's parent is None, it is "/" path, which should // return Ok immediately - if path.is_empty() || path.parent() == None { + if path.is_empty() || path.parent().is_none() { return Ok(()); } @@ -3601,7 +3601,7 @@ impl DirBuilder { // for relative paths like "foo/bar", the parent of // "foo" will be "" which there's no need to invoke // a mkdir syscall on - if ancestor.is_empty() || ancestor.parent() == None { + if ancestor.is_empty() || ancestor.parent().is_none() { break; } From 3dc163b2021d10f9944425149f996c24f560e69d Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 13 Aug 2026 14:20:50 +0000 Subject: [PATCH 13/34] clippy::unnecessary_map_or --- library/core/src/option.rs | 2 +- library/std/src/collections/hash/map.rs | 2 +- library/std/src/sys/fs/windows.rs | 12 ++++++------ library/test/src/term/terminfo/mod.rs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 9aaa80db055a4..f91e9ffcc4567 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -1934,7 +1934,7 @@ impl Option { where P: [const] FnOnce(&mut T) -> bool + [const] Destruct, { - if self.as_mut().map_or(false, predicate) { self.take() } else { None } + if self.as_mut().is_some_and(predicate) { self.take() } else { None } } /// Replaces the actual value in the option by the value given in parameter, diff --git a/library/std/src/collections/hash/map.rs b/library/std/src/collections/hash/map.rs index fef0b1b4df88e..2858680a20a49 100644 --- a/library/std/src/collections/hash/map.rs +++ b/library/std/src/collections/hash/map.rs @@ -1457,7 +1457,7 @@ where return false; } - self.iter().all(|(key, value)| other.get(key).map_or(false, |v| *value == *v)) + self.iter().all(|(key, value)| other.get(key).is_some_and(|v| *value == *v)) } } diff --git a/library/std/src/sys/fs/windows.rs b/library/std/src/sys/fs/windows.rs index 4446a4c3e3c8f..c99524375113a 100644 --- a/library/std/src/sys/fs/windows.rs +++ b/library/std/src/sys/fs/windows.rs @@ -784,9 +784,9 @@ impl File { pub fn set_times(&self, times: FileTimes) -> io::Result<()> { let is_zero = |t: c::FILETIME| t.dwLowDateTime == 0 && t.dwHighDateTime == 0; - if times.accessed.map_or(false, is_zero) - || times.modified.map_or(false, is_zero) - || times.created.map_or(false, is_zero) + if times.accessed.is_some_and(is_zero) + || times.modified.is_some_and(is_zero) + || times.created.is_some_and(is_zero) { return Err(io::const_error!( io::ErrorKind::InvalidInput, @@ -794,9 +794,9 @@ impl File { )); } let is_max = |t: c::FILETIME| t.dwLowDateTime == u32::MAX && t.dwHighDateTime == u32::MAX; - if times.accessed.map_or(false, is_max) - || times.modified.map_or(false, is_max) - || times.created.map_or(false, is_max) + if times.accessed.is_some_and(is_max) + || times.modified.is_some_and(is_max) + || times.created.is_some_and(is_max) { return Err(io::const_error!( io::ErrorKind::InvalidInput, diff --git a/library/test/src/term/terminfo/mod.rs b/library/test/src/term/terminfo/mod.rs index 75fa594908d56..6f712231e9888 100644 --- a/library/test/src/term/terminfo/mod.rs +++ b/library/test/src/term/terminfo/mod.rs @@ -67,7 +67,7 @@ impl TermInfo { Err(..) => return Err(Error::TermUnset), }; - if term.is_err() && env::var("MSYSCON").map_or(false, |s| "mintty.exe" == s) { + if term.is_err() && env::var("MSYSCON").is_ok_and(|s| "mintty.exe" == s) { // msys terminal Ok(msys_terminfo()) } else { From 3b4a6dd35856391cba901eae4f25ad685e9c262a Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 13 Aug 2026 14:23:54 +0000 Subject: [PATCH 14/34] clippy::manual_clear --- library/alloc/src/collections/vec_deque/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index a24e4d72fe38e..b007e3054ee6a 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -2049,6 +2049,7 @@ impl VecDeque { /// assert!(deque.is_empty()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[expect(clippy::manual_clear, reason = "implements clear")] #[inline] pub fn clear(&mut self) { self.truncate(0); From 9ea8c6e863866c2ace1f8534aa861a2ea75cf17b Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 13 Aug 2026 14:29:55 +0000 Subject: [PATCH 15/34] clippy::bind_instead_of_map --- library/core/src/slice/iter.rs | 8 ++++---- library/std/src/path.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/library/core/src/slice/iter.rs b/library/core/src/slice/iter.rs index a054c9d742c88..1c721f2925eb5 100644 --- a/library/core/src/slice/iter.rs +++ b/library/core/src/slice/iter.rs @@ -1892,9 +1892,9 @@ impl<'a, T> Iterator for ChunksExact<'a, T> { #[inline] fn next(&mut self) -> Option<&'a [T]> { - self.v.split_at_checked(self.chunk_size).and_then(|(chunk, rest)| { + self.v.split_at_checked(self.chunk_size).map(|(chunk, rest)| { self.v = rest; - Some(chunk) + chunk }) } @@ -2048,9 +2048,9 @@ impl<'a, T> Iterator for ChunksExactMut<'a, T> { #[inline] fn next(&mut self) -> Option<&'a mut [T]> { // SAFETY: we have `&mut self`, so are allowed to temporarily materialize a mut slice - unsafe { &mut *self.v }.split_at_mut_checked(self.chunk_size).and_then(|(chunk, rest)| { + unsafe { &mut *self.v }.split_at_mut_checked(self.chunk_size).map(|(chunk, rest)| { self.v = rest; - Some(chunk) + chunk }) } diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 3052587389a91..dbfc00b2c2b47 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -2933,7 +2933,7 @@ impl Path { #[stable(feature = "path_file_prefix", since = "1.91.0")] #[must_use] pub fn file_prefix(&self) -> Option<&OsStr> { - self.file_name().map(split_file_at_dot).and_then(|(before, _after)| Some(before)) + self.file_name().map(split_file_at_dot).map(|(before, _after)| before) } /// Extracts the extension (without the leading dot) of [`self.file_name`], if possible. From 4f88014e819dfb22847bac86dfcf5e047d1b00b8 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 13 Aug 2026 14:57:26 +0000 Subject: [PATCH 16/34] clippy::redundant_slicing --- library/alloc/src/io/buffered/bufreader.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/io/buffered/bufreader.rs b/library/alloc/src/io/buffered/bufreader.rs index e8b3302e29b98..e8be1abc56e17 100644 --- a/library/alloc/src/io/buffered/bufreader.rs +++ b/library/alloc/src/io/buffered/bufreader.rs @@ -153,7 +153,7 @@ impl BufReader { let new = self.buf.read_more(&mut self.inner)?; if new == 0 { // end of file, no more bytes to read - return Ok(&self.buf.buffer()[..]); + return Ok(self.buf.buffer()); } debug_assert_eq!(self.buf.pos(), 0); } From 27eccc9019b58469fa10c36069ca2ded02174e6c Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 13 Aug 2026 15:03:21 +0000 Subject: [PATCH 17/34] clippy::transmutes_expressible_as_ptr_casts --- library/core/src/ptr/const_ptr.rs | 1 + library/core/src/ptr/mut_ptr.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 5601621f1408e..06e7bbb91bbab 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -149,6 +149,7 @@ impl *const T { #[doc = include_str!("./docs/addr.md")] #[must_use] #[inline(always)] + #[expect(clippy::transmutes_expressible_as_ptr_casts, reason = "implements pointer cast")] #[stable(feature = "strict_provenance", since = "1.84.0")] pub fn addr(self) -> usize { // A pointer-to-integer transmute currently has exactly the right semantics: it returns the diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 76eca86612a82..31e14fce4429a 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -140,6 +140,7 @@ impl *mut T { /// [without_provenance]: without_provenance_mut #[must_use] #[inline(always)] + #[expect(clippy::transmutes_expressible_as_ptr_casts, reason = "implements pointer cast")] #[stable(feature = "strict_provenance", since = "1.84.0")] pub fn addr(self) -> usize { // A pointer-to-integer transmute currently has exactly the right semantics: it returns the From b49b508a8b4afd07f59bea7f90e92f982cde620f Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 13 Aug 2026 15:10:50 +0000 Subject: [PATCH 18/34] clippy::manual_repeat_n --- library/std/src/sys/args/windows.rs | 4 ++-- library/test/src/term/terminfo/parm.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/library/std/src/sys/args/windows.rs b/library/std/src/sys/args/windows.rs index bd26db7fea553..3a86f80a76f0c 100644 --- a/library/std/src/sys/args/windows.rs +++ b/library/std/src/sys/args/windows.rs @@ -115,7 +115,7 @@ fn parse_lp_cmd_line<'a, F: Fn() -> OsString>( BACKSLASH => { let backslash_count = code_units.advance_while(|w| w == BACKSLASH) + 1; if code_units.peek() == Some(QUOTE) { - cur.extend(iter::repeat(BACKSLASH.get()).take(backslash_count / 2)); + cur.extend(iter::repeat_n(BACKSLASH.get(), backslash_count / 2)); // The quote is escaped if there are an odd number of backslashes. if backslash_count % 2 == 1 { code_units.next(); @@ -123,7 +123,7 @@ fn parse_lp_cmd_line<'a, F: Fn() -> OsString>( } } else { // If there is no quote on the end then there is no escaping. - cur.extend(iter::repeat(BACKSLASH.get()).take(backslash_count)); + cur.extend(iter::repeat_n(BACKSLASH.get(), backslash_count)); } } // If `in_quotes` and not backslash escaped (see above) then a quote either diff --git a/library/test/src/term/terminfo/parm.rs b/library/test/src/term/terminfo/parm.rs index 529ec0c36e4a5..7426c1e009f55 100644 --- a/library/test/src/term/terminfo/parm.rs +++ b/library/test/src/term/terminfo/parm.rs @@ -1,6 +1,6 @@ //! Parameterized string expansion -use std::iter::repeat; +use std::iter::repeat_n; use self::Param::*; use self::States::*; @@ -520,10 +520,10 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result, String> { if flags.width > s.len() { let n = flags.width - s.len(); if flags.left { - s.extend(repeat(b' ').take(n)); + s.extend(repeat_n(b' ', n)); } else { let mut s_ = Vec::with_capacity(flags.width); - s_.extend(repeat(b' ').take(n)); + s_.extend(repeat_n(b' ', n)); s_.extend(s); s = s_; } From 6cb5350ca849a162520a294f643615228f2e712f Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 18 Aug 2026 20:42:03 +0000 Subject: [PATCH 19/34] clippy::to_digit_is_some --- library/core/src/char/methods.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index 8009f6514945e..ad0ae512f0f72 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -345,6 +345,7 @@ impl char { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_char_classify", since = "1.87.0")] + #[expect(clippy::to_digit_is_some, reason = "implements is_digit")] #[inline] pub const fn is_digit(self, radix: u32) -> bool { self.to_digit(radix).is_some() From d5d51bbeee8fbb58fc8c15131b07298dc464c311 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 18 Aug 2026 20:49:51 +0000 Subject: [PATCH 20/34] clippy::double_must_use --- library/alloc/src/boxed.rs | 3 --- library/alloc/src/rc.rs | 1 - library/alloc/src/sync.rs | 1 - library/alloc/src/vec/mod.rs | 1 - library/core/src/io/error.rs | 1 - library/std/src/panicking.rs | 1 - 6 files changed, 8 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 019749c77ae66..8ef478a6aab7b 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -813,7 +813,6 @@ impl Box { /// ``` #[unstable(feature = "clone_from_ref", issue = "149075")] //#[unstable(feature = "allocator_api", issue = "32838")] - #[must_use] #[inline] pub fn try_clone_from_ref(src: &T) -> Result, AllocError> { Box::try_clone_from_ref_in(src, Global) @@ -865,7 +864,6 @@ impl Box { /// ``` #[unstable(feature = "clone_from_ref", issue = "149075")] //#[unstable(feature = "allocator_api", issue = "32838")] - #[must_use] #[inline] pub fn try_clone_from_ref_in(src: &T, alloc: A) -> Result, AllocError> { struct DeallocDropGuard<'a, A: Allocator>(Layout, &'a A, NonNull); @@ -1161,7 +1159,6 @@ impl Box<[T], A> { /// ``` #[unstable(feature = "alloc_slice_into_array", issue = "148082")] #[inline] - #[must_use] pub fn into_array(self) -> Result, Self> { if self.len() == N { let (ptr, alloc) = Self::into_raw_with_allocator(self); diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index e4a803f28e121..01de5841ba0bb 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -1257,7 +1257,6 @@ impl Rc<[T], A> { /// ``` #[unstable(feature = "alloc_slice_into_array", issue = "148082")] #[inline] - #[must_use] pub fn into_array(self) -> Result, Self> { if self.len() == N { let (ptr, alloc) = Self::into_raw_with_allocator(self); diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 625a29dd9b7a0..f73792016e3d3 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -1416,7 +1416,6 @@ impl Arc<[T], A> { /// ``` #[unstable(feature = "alloc_slice_into_array", issue = "148082")] #[inline] - #[must_use] pub fn into_array(self) -> Result, Self> { if self.len() == N { let (ptr, alloc) = Self::into_raw_with_allocator(self); diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 94b21334c120c..bd15ec798460f 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1749,7 +1749,6 @@ impl Vec { /// ``` #[cfg(not(no_global_oom_handling))] #[unstable(feature = "alloc_slice_into_array", issue = "148082")] - #[must_use] pub fn into_array(self) -> Result, Self> { if self.len() == N { // SAFETY: `Box::into_array` is guaranteed to return `Ok` if the diff --git a/library/core/src/io/error.rs b/library/core/src/io/error.rs index 8491a42537092..c0de8822b456b 100644 --- a/library/core/src/io/error.rs +++ b/library/core/src/io/error.rs @@ -234,7 +234,6 @@ impl Error { #[doc(hidden)] #[unstable(feature = "core_io_internals", reason = "exposed only for libstd", issue = "none")] - #[must_use] #[inline] pub fn into_custom_owner(self) -> result::Result { if matches!(self.repr.data(), ErrorData::Custom(..)) { diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index 356b7daa293f4..5a4684a973942 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -175,7 +175,6 @@ pub fn set_hook(hook: Box) + 'static + Sync + Send>) { /// /// panic!("Normal panic"); /// ``` -#[must_use] #[stable(feature = "panic_hooks", since = "1.10.0")] pub fn take_hook() -> Box) + 'static + Sync + Send> { if thread::panicking() { From fd522d7ecedcde82116f55493d67c4b00292ea46 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 18 Aug 2026 21:02:04 +0000 Subject: [PATCH 21/34] clippy::seek_from_current --- library/core/src/io/seek.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/core/src/io/seek.rs b/library/core/src/io/seek.rs index 4c242c761dfe6..d24bf5ffb4024 100644 --- a/library/core/src/io/seek.rs +++ b/library/core/src/io/seek.rs @@ -142,6 +142,7 @@ pub trait Seek { /// } /// ``` #[stable(feature = "seek_convenience", since = "1.51.0")] + #[expect(clippy::seek_from_current, reason = "implements stream_position")] fn stream_position(&mut self) -> Result { self.seek(SeekFrom::Current(0)) } From ba77379e36c21f21fdaa5c21baf5fa773c705e2e Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 18 Aug 2026 21:07:26 +0000 Subject: [PATCH 22/34] clippy::mem_replace_option_with_some --- library/core/src/option.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/core/src/option.rs b/library/core/src/option.rs index f91e9ffcc4567..14b60fd6d8a64 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -1825,7 +1825,7 @@ impl Option { // It could also be expressed as `unsafe { core::ptr::write(self, Some(f())) }`, but // no reason is currently known to use additional unsafe code here. - mem::forget(mem::replace(self, Some(f()))); + mem::forget(self.replace(f())); } // SAFETY: a `None` variant for `self` would have been replaced by a `Some` @@ -1957,6 +1957,7 @@ impl Option { #[inline] #[stable(feature = "option_replace", since = "1.31.0")] #[rustc_const_stable(feature = "const_option", since = "1.83.0")] + #[expect(clippy::mem_replace_option_with_some, reason = "implements Option::replace")] pub const fn replace(&mut self, value: T) -> Option { mem::replace(self, Some(value)) } From 17cac5aa4866afdfa4855b6877ed746ab95f9f2b Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 18 Aug 2026 21:12:42 +0000 Subject: [PATCH 23/34] clippy::mem_replace_option_with_none --- library/alloc/src/collections/btree/map.rs | 2 +- library/core/src/option.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index d8421d3c3f70a..b204732a673e3 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -670,7 +670,7 @@ impl BTreeMap { pub fn clear(&mut self) { // avoid moving the allocator drop(BTreeMap { - root: mem::replace(&mut self.root, None), + root: self.root.take(), length: mem::replace(&mut self.length, 0), alloc: self.alloc.clone(), _marker: PhantomData, diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 14b60fd6d8a64..f707c838a1175 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -1898,6 +1898,7 @@ impl Option { #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_option", since = "1.83.0")] + #[expect(clippy::mem_replace_option_with_none, reason = "implements Option::take")] pub const fn take(&mut self) -> Option { // FIXME(const-hack) replace `mem::replace` by `mem::take` when the latter is const ready mem::replace(self, None) From 0bce2cce49b3af87bc177c9512d8880899f11ea8 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 18 Aug 2026 21:18:21 +0000 Subject: [PATCH 24/34] clippy::map_clone --- library/core/src/option.rs | 3 ++- library/core/src/result.rs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/library/core/src/option.rs b/library/core/src/option.rs index f707c838a1175..201019037148d 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -2158,6 +2158,7 @@ impl Option<&T> { /// ``` #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "rust1", since = "1.0.0")] + #[expect(clippy::map_clone, reason = "implements Option::cloned")] pub fn cloned(self) -> Option where T: Clone, @@ -2210,7 +2211,7 @@ impl Option<&mut T> { where T: Clone, { - self.as_deref().map(T::clone) + self.as_deref().cloned() } } diff --git a/library/core/src/result.rs b/library/core/src/result.rs index b257cd8c82a0e..d8c5fa48742bc 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -1738,6 +1738,7 @@ impl Result<&T, E> { /// ``` #[inline] #[stable(feature = "result_cloned", since = "1.59.0")] + #[expect(clippy::map_clone, reason = "implements Result::cloned")] pub fn cloned(self) -> Result where T: Clone, From db388688bfb2b65624fcc1653d5ffd5a1f8e2bca Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 18 Aug 2026 21:23:42 +0000 Subject: [PATCH 25/34] clippy::declare_interior_mutable_const --- library/core/src/sync/atomic.rs | 3 +++ library/std/src/sync/once.rs | 1 + 2 files changed, 4 insertions(+) diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index e676a3851112d..12208b95307ee 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -534,6 +534,7 @@ pub enum Ordering { note = "the `new` function is now preferred", suggestion = "AtomicBool::new(false)" )] +#[expect(clippy::declare_interior_mutable_const, reason = "legacy atomic initializer")] pub const ATOMIC_BOOL_INIT: AtomicBool = AtomicBool::new(false); #[cfg(target_has_atomic_load_store = "8")] @@ -3939,6 +3940,7 @@ macro_rules! atomic_int_ptr_sized { note = "the `new` function is now preferred", suggestion = "AtomicIsize::new(0)", )] + #[expect(clippy::declare_interior_mutable_const, reason = "legacy atomic initializer")] pub const ATOMIC_ISIZE_INIT: AtomicIsize = AtomicIsize::new(0); /// An [`AtomicUsize`] initialized to `0`. @@ -3949,6 +3951,7 @@ macro_rules! atomic_int_ptr_sized { note = "the `new` function is now preferred", suggestion = "AtomicUsize::new(0)", )] + #[expect(clippy::declare_interior_mutable_const, reason = "legacy atomic initializer")] pub const ATOMIC_USIZE_INIT: AtomicUsize = AtomicUsize::new(0); )* }; } diff --git a/library/std/src/sync/once.rs b/library/std/src/sync/once.rs index 62cac6afee751..9b555c32df99d 100644 --- a/library/std/src/sync/once.rs +++ b/library/std/src/sync/once.rs @@ -72,6 +72,7 @@ pub(crate) enum OnceExclusiveState { note = "the `Once::new()` function is now preferred", suggestion = "Once::new()" )] +#[expect(clippy::declare_interior_mutable_const, reason = "legacy Once initializer")] pub const ONCE_INIT: Once = Once::new(); impl Once { From ec3e1eaac79b8371ffe32540e19907a41f401784 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 18 Aug 2026 21:27:30 +0000 Subject: [PATCH 26/34] clippy::assign_op_pattern --- library/alloc/src/collections/linked_list.rs | 2 +- library/core/src/slice/sort/select.rs | 2 +- library/core/src/time.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/alloc/src/collections/linked_list.rs b/library/alloc/src/collections/linked_list.rs index 8939b2f12f49c..a0542d2b5737c 100644 --- a/library/alloc/src/collections/linked_list.rs +++ b/library/alloc/src/collections/linked_list.rs @@ -369,7 +369,7 @@ impl LinkedList { // Fix the head ptr of the second part self.head = Some(split_node); - self.len = self.len - at; + self.len -= at; first_part } else { diff --git a/library/core/src/slice/sort/select.rs b/library/core/src/slice/sort/select.rs index fc31013caf88c..30058f516867e 100644 --- a/library/core/src/slice/sort/select.rs +++ b/library/core/src/slice/sort/select.rs @@ -116,7 +116,7 @@ fn partition_at_index_loop<'a, T, F>( } v = &mut v[mid..]; - index = index - mid; + index -= mid; ancestor_pivot = None; continue; } diff --git a/library/core/src/time.rs b/library/core/src/time.rs index 682a61a07d10f..816da7a2fb7f2 100644 --- a/library/core/src/time.rs +++ b/library/core/src/time.rs @@ -1361,7 +1361,7 @@ macro_rules! sum_durations { total_secs = total_secs .checked_add(total_nanos / NANOS_PER_SEC as u64) .expect("overflow in iter::sum over durations"); - total_nanos = total_nanos % NANOS_PER_SEC as u64; + total_nanos %= NANOS_PER_SEC as u64; Duration::new(total_secs, total_nanos as u32) }}; } From 3bd3106b0ffcaad43b8f0968292e23ac1043f95b Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 18 Aug 2026 21:36:39 +0000 Subject: [PATCH 27/34] clippy::chunks_exact_to_as_chunks --- library/core/src/slice/ascii.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/library/core/src/slice/ascii.rs b/library/core/src/slice/ascii.rs index 2b6037b2ee53e..07920a36e6eda 100644 --- a/library/core/src/slice/ascii.rs +++ b/library/core/src/slice/ascii.rs @@ -666,10 +666,9 @@ const fn is_ascii(bytes: &[u8]) -> bool { } else { // For small inputs, use usize-at-a-time processing to avoid SSE2 call overhead. if bytes.len() < SIMD_MIN_LEN { - let chunks = bytes.chunks_exact(USIZE_SIZE); - let remainder = chunks.remainder(); + let (chunks, remainder) = bytes.as_chunks::(); for chunk in chunks { - let word = usize::from_ne_bytes(chunk.try_into().unwrap()); + let word = usize::from_ne_bytes(*chunk); if (word & NONASCII_MASK) != 0 { return false; } From 167a56a5dc8018d16c09e16a5a33541f1ea103fa Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Wed, 19 Aug 2026 01:26:27 +0000 Subject: [PATCH 28/34] clippy::needless_raw_string_hashes --- library/core/src/panicking.rs | 8 ++++---- library/std/src/sys/args/windows.rs | 2 +- library/test/src/formatters/json.rs | 2 +- library/test/src/test_result.rs | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/library/core/src/panicking.rs b/library/core/src/panicking.rs index 46790b620127b..04722e4e2fc10 100644 --- a/library/core/src/panicking.rs +++ b/library/core/src/panicking.rs @@ -445,14 +445,14 @@ fn assert_failed_inner( match args { Some(args) => panic!( - r#"assertion `left {op} right` failed: {args} + r"assertion `left {op} right` failed: {args} left: {left:?} - right: {right:?}"# + right: {right:?}" ), None => panic!( - r#"assertion `left {op} right` failed + r"assertion `left {op} right` failed left: {left:?} - right: {right:?}"# + right: {right:?}" ), } } diff --git a/library/std/src/sys/args/windows.rs b/library/std/src/sys/args/windows.rs index 3a86f80a76f0c..4a450a72cdccd 100644 --- a/library/std/src/sys/args/windows.rs +++ b/library/std/src/sys/args/windows.rs @@ -295,7 +295,7 @@ pub(crate) fn make_bat_command_line( force_quotes: bool, ) -> io::Result> { const INVALID_ARGUMENT_ERROR: io::Error = - io::const_error!(io::ErrorKind::InvalidInput, r#"batch file arguments are invalid"#); + io::const_error!(io::ErrorKind::InvalidInput, r"batch file arguments are invalid"); // Set the start of the command line to `cmd.exe /c "` // It is necessary to surround the command in an extra pair of quotes, // hence the trailing quote here. It will be closed after all arguments diff --git a/library/test/src/formatters/json.rs b/library/test/src/formatters/json.rs index 4a101f00d74b6..df62d0fd7f435 100644 --- a/library/test/src/formatters/json.rs +++ b/library/test/src/formatters/json.rs @@ -48,7 +48,7 @@ impl JsonFormatter { String::from("") }; let extra_json = - if let Some(extra) = extra { format!(r#", {extra}"#) } else { String::from("") }; + if let Some(extra) = extra { format!(r", {extra}") } else { String::from("") }; let newline = "\n"; self.writeln_message(&format!( diff --git a/library/test/src/test_result.rs b/library/test/src/test_result.rs index 4cb43fc45fd6c..b2457e031fd19 100644 --- a/library/test/src/test_result.rs +++ b/library/test/src/test_result.rs @@ -60,15 +60,15 @@ pub(crate) fn calc_result( TestResult::TrOk } else if let Some(panic_str) = maybe_panic_str { TestResult::TrFailedMsg(format!( - r#"panic did not contain expected string + r"panic did not contain expected string panic message: {panic_str:?} - expected substring: {msg:?}"# + expected substring: {msg:?}" )) } else { TestResult::TrFailedMsg(format!( - r#"expected panic with string value, + r"expected panic with string value, found non-string value: `{:?}` - expected substring: {msg:?}"#, + expected substring: {msg:?}", (*err).type_id() )) } From 503192cfbda7ce8a610f34d04e1da723a2f062b2 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Wed, 19 Aug 2026 14:30:12 +0000 Subject: [PATCH 29/34] clippy::approx_constant --- library/core/src/num/f128.rs | 1 + library/core/src/num/f16.rs | 1 + library/core/src/num/f32.rs | 1 + library/core/src/num/f64.rs | 1 + 4 files changed, 4 insertions(+) diff --git a/library/core/src/num/f128.rs b/library/core/src/num/f128.rs index 45b4b80e9e268..994233186a193 100644 --- a/library/core/src/num/f128.rs +++ b/library/core/src/num/f128.rs @@ -10,6 +10,7 @@ //! defined directly on the `f128` type. #![unstable(feature = "f128", issue = "116909")] +#![expect(clippy::approx_constant, reason = "this module defines f128 constants")] use crate::convert::{FloatToFloat, FloatToInt}; use crate::num::FpCategory; diff --git a/library/core/src/num/f16.rs b/library/core/src/num/f16.rs index e8f2e37f93c67..c1a64fd7fb602 100644 --- a/library/core/src/num/f16.rs +++ b/library/core/src/num/f16.rs @@ -10,6 +10,7 @@ //! defined directly on the `f16` type. #![unstable(feature = "f16", issue = "116909")] +#![expect(clippy::approx_constant, reason = "this module defines f16 constants")] use crate::convert::{FloatToFloat, FloatToInt}; use crate::num::FpCategory; diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index 3f7b33770fc08..eb1da9c7c7c6e 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -10,6 +10,7 @@ //! defined directly on the `f32` type. #![stable(feature = "rust1", since = "1.0.0")] +#![expect(clippy::approx_constant, reason = "this module defines f32 constants")] use crate::convert::{FloatToFloat, FloatToInt}; use crate::num::FpCategory; diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index 5bc2f8d0feb32..0a3baf039e639 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -10,6 +10,7 @@ //! defined directly on the `f64` type. #![stable(feature = "rust1", since = "1.0.0")] +#![expect(clippy::approx_constant, reason = "this module defines f64 constants")] use crate::convert::{FloatToFloat, FloatToInt}; use crate::num::FpCategory; From 85e21525fb48a28d74d412c9023d99ce53153c38 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Wed, 12 Aug 2026 15:42:04 +0000 Subject: [PATCH 30/34] clippy::neg_cmp_op_on_partial_ord --- library/core/src/num/f128.rs | 4 +++- library/core/src/num/f16.rs | 4 +++- library/core/src/num/f32.rs | 4 +++- library/core/src/num/f64.rs | 4 +++- library/core/src/ops/range.rs | 2 ++ library/core/src/range.rs | 2 ++ 6 files changed, 16 insertions(+), 4 deletions(-) diff --git a/library/core/src/num/f128.rs b/library/core/src/num/f128.rs index 994233186a193..d52e817c9e3db 100644 --- a/library/core/src/num/f128.rs +++ b/library/core/src/num/f128.rs @@ -1500,6 +1500,7 @@ impl f128 { #[inline] #[unstable(feature = "f128", issue = "116909")] #[must_use = "method returns a new number and does not mutate the original value"] + #[expect(clippy::neg_cmp_op_on_partial_ord, reason = "NaN is also invalid")] pub const fn clamp(mut self, min: f128, max: f128) -> f128 { const_assert!( min <= max, @@ -1544,8 +1545,9 @@ impl f128 { #[inline] #[unstable(feature = "clamp_magnitude", issue = "148519")] #[must_use = "this returns the clamped value and does not modify the original"] + #[expect(clippy::neg_cmp_op_on_partial_ord, reason = "NaN is also invalid")] pub fn clamp_magnitude(self, limit: f128) -> f128 { - assert!(limit >= 0.0, "limit must be non-negative"); + assert!(limit >= 0.0, "limit must be non-negative and not NaN"); let limit = limit.abs(); // Canonicalises -0.0 to 0.0 self.clamp(-limit, limit) } diff --git a/library/core/src/num/f16.rs b/library/core/src/num/f16.rs index c1a64fd7fb602..186e83a9cd6b5 100644 --- a/library/core/src/num/f16.rs +++ b/library/core/src/num/f16.rs @@ -1486,6 +1486,7 @@ impl f16 { #[inline] #[unstable(feature = "f16", issue = "116909")] #[must_use = "method returns a new number and does not mutate the original value"] + #[expect(clippy::neg_cmp_op_on_partial_ord, reason = "NaN is also invalid")] pub const fn clamp(mut self, min: f16, max: f16) -> f16 { const_assert!( min <= max, @@ -1530,8 +1531,9 @@ impl f16 { #[inline] #[unstable(feature = "clamp_magnitude", issue = "148519")] #[must_use = "this returns the clamped value and does not modify the original"] + #[expect(clippy::neg_cmp_op_on_partial_ord, reason = "NaN is also invalid")] pub fn clamp_magnitude(self, limit: f16) -> f16 { - assert!(limit >= 0.0, "limit must be non-negative"); + assert!(limit >= 0.0, "limit must be non-negative and not NaN"); let limit = limit.abs(); // Canonicalises -0.0 to 0.0 self.clamp(-limit, limit) } diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index eb1da9c7c7c6e..3c6b58a2b4b25 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -1660,6 +1660,7 @@ impl f32 { #[stable(feature = "clamp", since = "1.50.0")] #[rustc_const_stable(feature = "const_float_methods", since = "1.85.0")] #[inline] + #[expect(clippy::neg_cmp_op_on_partial_ord, reason = "Nan is also invalid")] pub const fn clamp(mut self, min: f32, max: f32) -> f32 { const_assert!( min <= max, @@ -1701,8 +1702,9 @@ impl f32 { #[must_use = "this returns the clamped value and does not modify the original"] #[unstable(feature = "clamp_magnitude", issue = "148519")] #[inline] + #[expect(clippy::neg_cmp_op_on_partial_ord, reason = "NaN is also invalid")] pub fn clamp_magnitude(self, limit: f32) -> f32 { - assert!(limit >= 0.0, "limit must be non-negative"); + assert!(limit >= 0.0, "limit must be non-negative and not NaN"); let limit = limit.abs(); // Canonicalises -0.0 to 0.0 self.clamp(-limit, limit) } diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index 0a3baf039e639..8c433a5cf941d 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -1638,6 +1638,7 @@ impl f64 { #[stable(feature = "clamp", since = "1.50.0")] #[rustc_const_stable(feature = "const_float_methods", since = "1.85.0")] #[inline] + #[expect(clippy::neg_cmp_op_on_partial_ord, reason = "NaN is also invalid")] pub const fn clamp(mut self, min: f64, max: f64) -> f64 { const_assert!( min <= max, @@ -1679,8 +1680,9 @@ impl f64 { #[must_use = "this returns the clamped value and does not modify the original"] #[unstable(feature = "clamp_magnitude", issue = "148519")] #[inline] + #[expect(clippy::neg_cmp_op_on_partial_ord, reason = "NaN is also invalid")] pub fn clamp_magnitude(self, limit: f64) -> f64 { - assert!(limit >= 0.0, "limit must be non-negative"); + assert!(limit >= 0.0, "limit must be non-negative and not NaN"); let limit = limit.abs(); // Canonicalises -0.0 to 0.0 self.clamp(-limit, limit) } diff --git a/library/core/src/ops/range.rs b/library/core/src/ops/range.rs index ebb6c3ddb938c..19830365faa32 100644 --- a/library/core/src/ops/range.rs +++ b/library/core/src/ops/range.rs @@ -148,6 +148,7 @@ impl> Range { #[inline] #[stable(feature = "range_is_empty", since = "1.47.0")] #[rustc_const_unstable(feature = "const_range", issue = "none")] + #[expect(clippy::neg_cmp_op_on_partial_ord, reason = "incomparable ranges are empty")] pub const fn is_empty(&self) -> bool where Idx: [const] PartialOrd, @@ -568,6 +569,7 @@ impl> RangeInclusive { #[stable(feature = "range_is_empty", since = "1.47.0")] #[inline] #[rustc_const_unstable(feature = "const_range", issue = "none")] + #[expect(clippy::neg_cmp_op_on_partial_ord, reason = "incomparable ranges are empty")] pub const fn is_empty(&self) -> bool where Idx: [const] PartialOrd, diff --git a/library/core/src/range.rs b/library/core/src/range.rs index 557587b4e9a88..81f4b2ce78c9c 100644 --- a/library/core/src/range.rs +++ b/library/core/src/range.rs @@ -162,6 +162,7 @@ impl> Range { #[inline] #[stable(feature = "new_range_api", since = "1.96.0")] #[rustc_const_unstable(feature = "const_range", issue = "none")] + #[expect(clippy::neg_cmp_op_on_partial_ord, reason = "incomparable ranges are empty")] pub const fn is_empty(&self) -> bool where Idx: [const] PartialOrd, @@ -320,6 +321,7 @@ impl> RangeInclusive { #[stable(feature = "new_range_inclusive_api", since = "1.95.0")] #[inline] #[rustc_const_unstable(feature = "const_range", issue = "none")] + #[expect(clippy::neg_cmp_op_on_partial_ord, reason = "incomparable ranges are empty")] pub const fn is_empty(&self) -> bool where Idx: [const] PartialOrd, From 1cb99178f963abff8865e02771bef948c795ddf3 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 18 Aug 2026 21:42:25 +0000 Subject: [PATCH 31/34] Ignore clippy failures in stdarch submodule --- library/core/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 2aacd5d99b19b..ab47e7235bcc6 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -364,7 +364,9 @@ pub mod primitive; unsafe_op_in_unsafe_fn, ambiguous_glob_reexports, deprecated_in_future, - unreachable_pub + unreachable_pub, + // FIXME: stdach is a submodule so clippy lints should be fixed (and ideally enforced) there + clippy::all, )] #[allow(rustdoc::bare_urls)] mod core_arch; From 3df0d082f1b47989aa793338b9869ec37e71cbf5 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 18 Aug 2026 22:59:35 +0000 Subject: [PATCH 32/34] Enforce even more clippy lints in CI --- src/bootstrap/src/core/build_steps/clippy.rs | 51 +++++++++++++++----- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/clippy.rs b/src/bootstrap/src/core/build_steps/clippy.rs index dc3e3efb80ee5..9b8377f23ccd5 100644 --- a/src/bootstrap/src/core/build_steps/clippy.rs +++ b/src/bootstrap/src/core/build_steps/clippy.rs @@ -38,7 +38,6 @@ const IGNORED_RULES_FOR_STD_AND_RUSTC: &[&str] = &[ "too_many_arguments", "needless_lifetimes", // people want to keep the lifetimes "wrong_self_convention", - "approx_constant", // libcore is what defines those ]; fn lint_args(builder: &Builder<'_>, config: &LintConfig, ignored_rules: &[&str]) -> Vec { @@ -572,29 +571,57 @@ impl CommandLineStep for CI { allow: vec!["clippy::all".into()], warn: vec![], deny: vec![ + // the entire correctness group should always be enforced. "clippy::correctness".into(), + // tidy-alphabetic-start + "clippy::approx_constant".into(), + "clippy::assign_op_pattern".into(), + "clippy::bind_instead_of_map".into(), + "clippy::borrow_deref_ref".into(), "clippy::char_lit_as_u8".into(), + "clippy::chunks_exact_to_as_chunks".into(), + "clippy::declare_interior_mutable_const".into(), + "clippy::default_constructed_unit_structs".into(), + "clippy::derivable_impls".into(), + "clippy::double_must_use".into(), + "clippy::excessive_precision".into(), + "clippy::explicit_auto_deref".into(), + "clippy::filter_map_next".into(), "clippy::four_forward_slashes".into(), + "clippy::int_plus_one".into(), + "clippy::legacy_numeric_constants".into(), + "clippy::let_and_return".into(), + "clippy::manual_repeat_n".into(), + "clippy::map_clone".into(), + "clippy::match_as_ref".into(), + "clippy::mem_replace_option_with_none".into(), + "clippy::mem_replace_option_with_some".into(), + "clippy::needless_as_bytes".into(), "clippy::needless_bool".into(), "clippy::needless_bool_assign".into(), + "clippy::needless_borrow".into(), + "clippy::needless_raw_string_hashes".into(), + "clippy::needless_return".into(), + "clippy::neg_cmp_op_on_partial_ord".into(), "clippy::non_minimal_cfg".into(), + "clippy::op_ref".into(), + "clippy::partialeq_ne_impl".into(), + "clippy::partialeq_to_none".into(), "clippy::print_literal".into(), + "clippy::ptr_offset_with_cast".into(), + "clippy::redundant_closure".into(), + "clippy::redundant_pattern_matching".into(), + "clippy::redundant_slicing".into(), "clippy::same_item_push".into(), + "clippy::seek_from_current".into(), "clippy::single_char_add_str".into(), + "clippy::single_match".into(), + "clippy::to_digit_is_some".into(), "clippy::to_string_in_format_args".into(), "clippy::unconditional_recursion".into(), - "clippy::int_plus_one".into(), - "clippy::legacy_numeric_constants".into(), + "clippy::unnecessary_map_or".into(), "clippy::zero_divided_by_zero".into(), - "clippy::len_zero".into(), - "clippy::needless_as_bytes".into(), - "clippy::ptr_offset_with_cast".into(), - "clippy::let_and_return".into(), - "clippy::needless_return".into(), - "clippy::needless_borrow".into(), - "clippy::op_ref".into(), - "clippy::borrow_deref_ref".into(), - "clippy::explicit_auto_deref".into(), + // tidy-alphabetic-end ], forbid: vec![], }; From bc9565bc58b884dcd8370b98a346121a79fd8c79 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Wed, 19 Aug 2026 02:41:43 +0000 Subject: [PATCH 33/34] Allow lints on backtrace-rs --- library/std/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 980ec4416f04a..590c5e62557a0 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -739,7 +739,7 @@ mod panicking; #[path = "../../backtrace/src/lib.rs"] #[allow(dead_code, unused_attributes, implicit_provenance_casts, unsafe_op_in_unsafe_fn)] -#[allow(clippy::len_zero, clippy::needless_borrow)] // FIXME +#[allow(clippy::len_zero, clippy::needless_borrow, clippy::filter_map_next)] // FIXME mod backtrace_rs; #[stable(feature = "cfg_select", since = "1.95.0")] From d712c4ee33cdcb63131bee8b63e522ff58560a74 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Wed, 19 Aug 2026 11:53:24 +0000 Subject: [PATCH 34/34] ignore clippy::redundant_pattern_matching This can affect drop order --- src/bootstrap/src/core/build_steps/clippy.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/src/core/build_steps/clippy.rs b/src/bootstrap/src/core/build_steps/clippy.rs index 9b8377f23ccd5..99648425a8987 100644 --- a/src/bootstrap/src/core/build_steps/clippy.rs +++ b/src/bootstrap/src/core/build_steps/clippy.rs @@ -38,6 +38,7 @@ const IGNORED_RULES_FOR_STD_AND_RUSTC: &[&str] = &[ "too_many_arguments", "needless_lifetimes", // people want to keep the lifetimes "wrong_self_convention", + "redundant_pattern_matching", // can affect drop order ]; fn lint_args(builder: &Builder<'_>, config: &LintConfig, ignored_rules: &[&str]) -> Vec { @@ -610,7 +611,6 @@ impl CommandLineStep for CI { "clippy::print_literal".into(), "clippy::ptr_offset_with_cast".into(), "clippy::redundant_closure".into(), - "clippy::redundant_pattern_matching".into(), "clippy::redundant_slicing".into(), "clippy::same_item_push".into(), "clippy::seek_from_current".into(),