GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Enable some pedantic clippy lints by ShaharNaveh · Pull Request #7764 · RustPython/RustPython

Enable some pedantic clippy lints #7764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
youknowone merged 14 commits into RustPython:main from ShaharNaveh:clippy-lints-0
May 4, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

Enable some pedantic clippy lints #7764

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
b54c1aa
Set `#[must_use]` where possible
ShaharNaveh May 2, 2026
f3587f6
redundant_else
ShaharNaveh May 2, 2026
7e08309
Fix doc
ShaharNaveh May 2, 2026
938790a
Add some clippy rules
ShaharNaveh May 2, 2026
d2f0c6f
Enfore `cloned_instead_of_copied`
ShaharNaveh May 2, 2026
840fc07
Remove dup import
ShaharNaveh May 2, 2026
37418c5
Fix more
ShaharNaveh May 2, 2026
6326047
fix wasm
ShaharNaveh May 2, 2026
55444fc
more
ShaharNaveh May 2, 2026
3dd0fb5
more
ShaharNaveh May 2, 2026
b017713
fix
ShaharNaveh May 2, 2026
d01b279
Merge remote-tracking branch 'upstream/main' into clippy-lints-0
ShaharNaveh May 2, 2026
d293a25
Fix more
ShaharNaveh May 2, 2026
8a56ff1
Fix typo
ShaharNaveh May 2, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Next Next commit
Set #[must_use] where possible
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@ShaharNaveh
ShaharNaveh committed May 2, 2026
commit b54c1aafddb875e128a218576ac68eded23145b8

There are no files selected for viewing

2 changes: 2 additions & 0 deletions 2 crates/codegen/src/compile.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ impl Default for PatternContext {
}

impl PatternContext {
#[must_use]
pub const fn new() -> Self {
Self {
stores: Vec::new(),
Expand All @@ -426,6 +427,7 @@ impl PatternContext {
}
}

#[must_use]
pub fn fail_pop_size(&self) -> usize {
self.fail_pop.len()
}
Expand Down
5 changes: 5 additions & 0 deletions 5 crates/codegen/src/symboltable.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl SymbolTable {
builder.finish()
}

#[must_use]
pub fn lookup(&self, name: &str) -> Option<&Symbol> {
self.symbols.get(name)
}
Expand Down Expand Up @@ -226,17 +227,20 @@ impl Symbol {
}
}

#[must_use]
pub const fn is_global(&self) -> bool {
matches!(
self.scope,
SymbolScope::GlobalExplicit | SymbolScope::GlobalImplicit
)
}

#[must_use]
pub const fn is_local(&self) -> bool {
matches!(self.scope, SymbolScope::Local | SymbolScope::Cell)
}

#[must_use]
pub const fn is_bound(&self) -> bool {
self.flags.intersects(SymbolFlags::BOUND)
}
Expand All @@ -249,6 +253,7 @@ pub struct SymbolTableError {
}

impl SymbolTableError {
#[must_use]
pub fn into_codegen_error(self, source_path: String) -> CodegenError {
CodegenError {
location: self.location,
Expand Down
1 change: 1 addition & 0 deletions 1 crates/common/src/atomic.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ impl<T> Default for OncePtr<T> {

impl<T> OncePtr<T> {
#[inline]
#[must_use]
pub fn new() -> Self {
Self {
inner: Radium::new(ptr::null_mut()),
Expand Down
9 changes: 9 additions & 0 deletions 9 crates/common/src/boxvec.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ macro_rules! panic_oob {
}

impl<T> BoxVec<T> {
#[must_use]
pub fn new(n: usize) -> Self {
Self {
xs: Box::new_uninit_slice(n),
Expand All @@ -46,24 +47,29 @@ impl<T> BoxVec<T> {
}

#[inline]
#[must_use]
pub const fn len(&self) -> usize {
self.len
}

#[inline]
#[must_use]
pub const fn is_empty(&self) -> bool {
self.len() == 0
}

#[inline]
#[must_use]
pub const fn capacity(&self) -> usize {
self.xs.len()
}

#[must_use]
pub const fn is_full(&self) -> bool {
self.len() == self.capacity()
}

#[must_use]
pub const fn remaining_capacity(&self) -> usize {
self.capacity() - self.len()
}
Expand Down Expand Up @@ -312,6 +318,7 @@ impl<T> BoxVec<T> {
}

/// Return a slice containing all elements of the vector.
#[must_use]
pub fn as_slice(&self) -> &[T] {
self
}
Expand All @@ -323,6 +330,7 @@ impl<T> BoxVec<T> {

/// Return a raw pointer to the vector's buffer.
#[inline]
#[must_use]
pub fn as_ptr(&self) -> *const T {
self.xs.as_ptr().cast()
}
Expand Down Expand Up @@ -487,6 +495,7 @@ impl<T> DoubleEndedIterator for Drain<'_, T> {
impl<T> ExactSizeIterator for Drain<'_, T> {}

impl<'a, T> Drain<'a, T> {
#[must_use]
pub fn as_slice(&self) -> &'a [T] {
self.iter.as_slice()
}
Expand Down
6 changes: 6 additions & 0 deletions 6 crates/common/src/cformat.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ pub enum CFormatType {
}

impl CFormatType {
#[must_use]
pub const fn to_char(self) -> char {
match self {
Self::Number(x) => x as u8 as char,
Expand Down Expand Up @@ -137,6 +138,7 @@ bitflags! {

impl CConversionFlags {
#[inline]
#[must_use]
pub const fn sign_string(&self) -> &'static str {
if self.contains(Self::SIGN_CHAR) {
"+"
Expand Down Expand Up @@ -408,6 +410,7 @@ impl CFormatSpec {
)
}

#[must_use]
pub fn format_bytes(&self, bytes: &[u8]) -> Vec<u8> {
let bytes = if let Some(CFormatPrecision::Quantity(CFormatQuantity::Amount(precision))) =
self.precision
Expand All @@ -432,6 +435,7 @@ impl CFormatSpec {
}
}

#[must_use]
pub fn format_number(&self, num: &BigInt) -> String {
use CNumberType::*;
let CFormatType::Number(format_type) = self.format_type else {
Expand Down Expand Up @@ -492,6 +496,7 @@ impl CFormatSpec {
}
}

#[must_use]
pub fn format_float(&self, num: f64) -> String {
let sign_string = if num.is_sign_negative() && !num.is_nan() {
"-"
Expand Down Expand Up @@ -740,6 +745,7 @@ pub struct CFormatStrOrBytes<S> {
}

impl<S> CFormatStrOrBytes<S> {
#[must_use]
pub fn check_specifiers(&self) -> Option<(usize, bool)> {
let mut count = 0;
let mut mapping_required = false;
Expand Down
12 changes: 12 additions & 0 deletions 12 crates/common/src/float_ops.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use core::f64;
use malachite_bigint::{BigInt, ToBigInt};
use num_traits::{Float, Signed, ToPrimitive, Zero};

#[must_use]
pub const fn decompose_float(value: f64) -> (f64, i32) {
if 0.0 == value {
(0.0, 0i32)
Expand Down Expand Up @@ -29,6 +30,7 @@ pub const fn decompose_float(value: f64) -> (f64, i32) {
/// assert!(!eq_int(c, &b));
/// ```
///
#[must_use]
pub fn eq_int(value: f64, other: &BigInt) -> bool {
if let (Some(self_int), Some(other_float)) = (value.to_bigint(), other.to_f64()) {
value == other_float && self_int == *other
Expand All @@ -37,6 +39,7 @@ pub fn eq_int(value: f64, other: &BigInt) -> bool {
}
}

#[must_use]
pub fn lt_int(value: f64, other_int: &BigInt) -> bool {
match (value.to_bigint(), other_int.to_f64()) {
(Some(self_int), Some(other_float)) => value < other_float || self_int < *other_int,
Expand All @@ -50,6 +53,7 @@ pub fn lt_int(value: f64, other_int: &BigInt) -> bool {
}
}

#[must_use]
pub fn gt_int(value: f64, other_int: &BigInt) -> bool {
match (value.to_bigint(), other_int.to_f64()) {
(Some(self_int), Some(other_float)) => value > other_float || self_int > *other_int,
Expand All @@ -63,21 +67,25 @@ pub fn gt_int(value: f64, other_int: &BigInt) -> bool {
}
}

#[must_use]
pub const fn div(v1: f64, v2: f64) -> Option<f64> {
if v2 != 0.0 { Some(v1 / v2) } else { None }
}

#[must_use]
pub fn mod_(v1: f64, v2: f64) -> Option<f64> {
divmod(v1, v2).map(|(_, m)| m)
}

#[must_use]
pub fn floordiv(v1: f64, v2: f64) -> Option<f64> {
divmod(v1, v2).map(|(d, _)| d)
}

// Canonical (floordiv, mod) for floats matching CPython's _float_div_mod
// (Objects/floatobject.c). `mod_` and `floordiv` delegate here so that
// `divmod(a, b) == (a // b, a % b)` holds by construction.
#[must_use]
pub fn divmod(v1: f64, v2: f64) -> Option<(f64, f64)> {
if v2 == 0.0 {
return None;
Expand Down Expand Up @@ -108,6 +116,7 @@ pub fn divmod(v1: f64, v2: f64) -> Option<(f64, f64)> {

// nextafter algorithm based off of https://gitlab.com/bronsonbdevost/next_afterf
#[allow(clippy::float_cmp)]
#[must_use]
pub fn nextafter(x: f64, y: f64) -> f64 {
if x == y {
y
Expand All @@ -130,6 +139,7 @@ pub fn nextafter(x: f64, y: f64) -> f64 {
}

#[allow(clippy::float_cmp)]
#[must_use]
pub fn nextafter_with_steps(x: f64, y: f64, steps: u64) -> f64 {
if x == y {
y
Expand Down Expand Up @@ -192,6 +202,7 @@ pub fn nextafter_with_steps(x: f64, y: f64, steps: u64) -> f64 {
}
}

#[must_use]
pub fn ulp(x: f64) -> f64 {
if x.is_nan() {
return x;
Expand All @@ -207,6 +218,7 @@ pub fn ulp(x: f64) -> f64 {
}
}

#[must_use]
pub fn round_float_digits(x: f64, ndigits: i32) -> Option<f64> {
let float = if ndigits.is_zero() {
let fract = x.fract();
Expand Down
3 changes: 3 additions & 0 deletions 3 crates/common/src/format.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl FormatParse for FormatConversion {
}

impl FormatConversion {
#[must_use]
pub fn from_char(c: CodePoint) -> Option<Self> {
match c.to_char_lossy() {
's' => Some(Self::Str),
Expand Down Expand Up @@ -479,6 +480,7 @@ impl FormatSpec {
}

/// Returns true if this format spec uses the locale-aware 'n' format type.
#[must_use]
pub fn has_locale_format(&self) -> bool {
matches!(self.format_type, Some(FormatType::Number(Case::Lower)))
}
Expand All @@ -487,6 +489,7 @@ impl FormatSpec {
/// subject to `sys.get_int_max_str_digits()` (no spec, 'd', or 'n').
/// Binary bases ('b', 'o', 'x', 'X') are exempt per CPython. 'N' is rejected
/// later in `format_int` as `UnknownFormatCode`, so it is not included here.
#[must_use]
pub fn is_decimal_int_format(&self) -> bool {
matches!(
self.format_type,
Expand Down
12 changes: 12 additions & 0 deletions 12 crates/common/src/hash.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl BuildHasher for HashSecret {
}

impl HashSecret {
#[must_use]
pub fn new(seed: u32) -> Self {
let mut buf = [0u8; 16];
lcg_urandom(seed, &mut buf);
Expand Down Expand Up @@ -68,6 +69,7 @@ impl HashSecret {
Ok(fix_sentinel(mod_int(hasher.finish() as PyHash)))
}

#[must_use]
pub fn hash_bytes(&self, value: &[u8]) -> PyHash {
if value.is_empty() {
0
Expand All @@ -76,19 +78,22 @@ impl HashSecret {
}
}

#[must_use]
pub fn hash_str(&self, value: &str) -> PyHash {
self.hash_bytes(value.as_bytes())
}
}

#[inline]
#[must_use]
pub const fn hash_pointer(value: usize) -> PyHash {
// TODO: 32bit?
let hash = (value >> 4) | value;
hash as _
}

#[inline]
#[must_use]
pub fn hash_float(value: f64) -> Option<PyHash> {
// cpython _Py_HashDouble
if !value.is_finite() {
Expand Down Expand Up @@ -130,6 +135,7 @@ pub fn hash_float(value: f64) -> Option<PyHash> {
Some(fix_sentinel(x as PyHash * value.signum() as PyHash))
}

#[must_use]
pub fn hash_bigint(value: &BigInt) -> PyHash {
let ret = match value.to_i64() {
Some(i) => mod_int(i),
Expand All @@ -142,16 +148,19 @@ pub fn hash_bigint(value: &BigInt) -> PyHash {
}

#[inline]
#[must_use]
pub const fn hash_usize(data: usize) -> PyHash {
fix_sentinel(mod_int(data as i64))
}

#[inline(always)]
#[must_use]
pub const fn fix_sentinel(x: PyHash) -> PyHash {
if x == SENTINEL { -2 } else { x }
}

#[inline]
#[must_use]
pub const fn mod_int(value: i64) -> PyHash {
value % MODULUS as i64
}
Expand All @@ -165,6 +174,7 @@ pub fn lcg_urandom(mut x: u32, buf: &mut [u8]) {
}

#[inline]
#[must_use]
pub const fn hash_object_id_raw(p: usize) -> PyHash {
// TODO: Use commented logic when below issue resolved.
// Ref: https://github.com/RustPython/RustPython/pull/3951#issuecomment-1193108966
Expand All @@ -176,10 +186,12 @@ pub const fn hash_object_id_raw(p: usize) -> PyHash {
}

#[inline]
#[must_use]
pub const fn hash_object_id(p: usize) -> PyHash {
fix_sentinel(hash_object_id_raw(p))
}

#[must_use]
pub fn keyed_hash(key: u64, buf: &[u8]) -> u64 {
let mut hasher = SipHasher24::new_with_keys(key, 0);
buf.hash(&mut hasher);
Expand Down
3 changes: 3 additions & 0 deletions 3 crates/common/src/int.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use malachite_bigint::{BigInt, BigUint, Sign};
use malachite_q::Rational;
use num_traits::{One, ToPrimitive, Zero};

#[must_use]
pub fn true_div(numerator: &BigInt, denominator: &BigInt) -> f64 {
let rational = Rational::from_integers_ref(numerator.into(), denominator.into());
match rational.rounding_into(RoundingMode::Nearest) {
Expand All @@ -14,6 +15,7 @@ pub fn true_div(numerator: &BigInt, denominator: &BigInt) -> f64 {
}
}

#[must_use]
pub fn float_to_ratio(value: f64) -> Option<(BigInt, BigInt)> {
let sign = match core::cmp::PartialOrd::partial_cmp(&value, &0.0)? {
core::cmp::Ordering::Less => Sign::Minus,
Expand Down Expand Up @@ -146,6 +148,7 @@ pub fn bytes_to_int(

// num-bigint now returns Some(inf) for to_f64() in some cases, so just keep that the same for now
#[inline(always)]
#[must_use]
pub fn bigint_to_finite_float(int: &BigInt) -> Option<f64> {
int.to_f64().filter(|f| f.is_finite())
}
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.