Skip to content

clippy: fix or silence rust 1.92 signaled warnings#10245

Merged
kskalski merged 1 commit intoanza-xyz:masterfrom
kskalski:ks/clippy_weird
Jan 29, 2026
Merged

clippy: fix or silence rust 1.92 signaled warnings#10245
kskalski merged 1 commit intoanza-xyz:masterfrom
kskalski:ks/clippy_weird

Conversation

@kskalski
Copy link
Copy Markdown

@kskalski kskalski commented Jan 29, 2026

Problem

Some new warnings are emitted by clippy using rust 1.92 toolchain. They actually don't look correct, but we need to find a way to silence them for CI to pass.

Summary of Changes

  • use qualified macro name instead of import
  • convert u128::MAX constant to byte array and back to avoid identical equality assert error
  • silence unused variable warning in programs/sbf/rust/sanity/src/lib.rs

use $crate::with_mock_invoke_context_with_feature_set;
let feature_set = &solana_svm_feature_set::SVMFeatureSet::default();
with_mock_invoke_context_with_feature_set!(
$crate::with_mock_invoke_context_with_feature_set!(
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required due to

error: unused import: `$crate::with_mock_invoke_context_with_feature_set`
    --> program-runtime/src/invoke_context.rs:852:13
     |
 852 |         use $crate::with_mock_invoke_context_with_feature_set;
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
1140 |         with_mock_invoke_context!(invoke_context, transaction_context, transaction_accounts);
     |         ------------------------------------------------------------------------------------ in this macro invocation
     |
     = note: `-D unused-imports` implied by `-D warnings`
     = help: to override `-D warnings` add `#[allow(unused_imports)]`
     = note: this error originates in the macro `with_mock_invoke_context` (in Nightly builds, run with -Z macro-backtrace for more info)

seems like clippy can no longer recognize uses of import in macro that is use as invoke

Comment thread programs/sbf/rust/128bit/src/lib.rs Outdated
// Surface decimal value without triggering clippy::eq_op warning
assert_eq!(
u128::MAX,
u128::from_ne_bytes(u128::MAX.to_ne_bytes()),
Copy link
Copy Markdown
Author

@kskalski kskalski Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like now clippy treats u128::MAX as identical to 340_282_366_920_938_463_463_374_607_431_768_211_455, which is wrong, but maybe reasonable, so I hacked the value to avoid putting allow on the whole function:

error: identical args used in this `assert_eq!` macro call
  --> rust/128bit/src/lib.rs:14:9
   |
14 | /         u128::MAX,
15 | |         340_282_366_920_938_463_463_374_607_431_768_211_455
   | |___________________________________________________________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#eq_op
   = note: `#[deny(clippy::eq_op)]` on by default

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend

// explanation
#[expect(clippy::eq_op)]
{
    offending expression
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I think a block will be better than this masking, can't do expect, since in current CI won't allow it, but maybe I can turn it from allow to expect as part of toolchain bump

// Test - float math functions
let zero = accounts[0].try_borrow_mut_data()?.len() as f64;
let num = zero + 8.0f64;
let num = num.powf(0.333f64);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for some reason rust thinks now that this num is unused:


warning: unused variable: `zero`
  --> rust/sanity/src/lib.rs:88:13
   |
88 |         let zero = accounts[0].try_borrow_mut_data()?.len() as f64;
   |             ^^^^ help: if this is intentional, prefix it with an underscore: `_zero`
   |
   = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default

warning: unused variable: `val`
  --> rust/sanity/src/lib.rs:88:20
   |
88 |         let zero = accounts[0].try_borrow_mut_data()?.len() as f64;
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_val`


warning: unused variable: `num`
  --> rust/sanity/src/lib.rs:89:13
   |
89 |         let num = zero + 8.0f64;
   |             ^^^ help: if this is intentional, prefix it with an underscore: `_num`

warning: unused variable: `num`
  --> rust/sanity/src/lib.rs:90:13
   |
90 |         let num = num.powf(0.333f64);
   |             ^^^ help: if this is intentional, prefix it with an underscore: `_num`

no idea how to fix it other than putting allow on the whole function...

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably rust-lang/rust#142390 and rust-lang/rust#151514. Slap an #[expect] on this (in the PR that bumps the toolchain) and move on, I'd say.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yap, looks like actually it got fixed in 1.93, which now fails the "expect" on my local test ;)

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jan 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.8%. Comparing base (bc87918) to head (a43f3ab).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##           master   #10245     +/-   ##
=========================================
- Coverage    82.8%    82.8%   -0.1%     
=========================================
  Files         847      847             
  Lines      320391   320391             
=========================================
- Hits       265584   265578      -6     
- Misses      54807    54813      +6     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kskalski kskalski marked this pull request as ready for review January 29, 2026 05:41
@kskalski kskalski requested a review from a team as a code owner January 29, 2026 05:41
Comment thread programs/sbf/rust/sanity/src/lib.rs Outdated
}

solana_program_entrypoint::entrypoint_no_alloc!(process_instruction);
#[allow(unused_variables)]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[allow(unused_variables)]
#[expect(unused_variables)]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will turn it into expect after toolchain bump, for now I added comment and narrowed to the relevant block

nagisa
nagisa previously approved these changes Jan 29, 2026
@kskalski kskalski added this pull request to the merge queue Jan 29, 2026
Merged via the queue into anza-xyz:master with commit de37081 Jan 29, 2026
50 checks passed
@kskalski kskalski deleted the ks/clippy_weird branch January 29, 2026 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants