Skip to content

parameter only used in recursion false positive #8629

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.

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

Closed
hellow554 opened this issue Apr 4, 2022 · 6 comments · Fixed by #8804
Closed

parameter only used in recursion false positive #8629

hellow554 opened this issue Apr 4, 2022 · 6 comments · Fixed by #8804
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@hellow554
Copy link
Contributor

Summary

The lint triggers even when there's no recursion and it is "used"

Lint Name

only_used_in_recursion

Reproducer

I tried this code:

pub fn k(num_chunks: u64)
{
    let num_bytes = 98989;
    let _chunk_size = num_bytes * num_chunks;
}

I saw this happen:

warning: parameter is only used in recursion
 --> src/main.rs:1:10
  |
1 | pub fn k(num_chunks: u64)
  |          ^^^^^^^^^^ help: if this is intentional, prefix with an underscore: `_num_chunks`
  |
  = note: `#[warn(clippy::only_used_in_recursion)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#only_used_in_recursion

Version

rustc 1.61.0-nightly (6af09d250 2022-04-03)
binary: rustc
commit-hash: 6af09d2505f38e4f1df291df56d497fb2ad935ed
commit-date: 2022-04-03
host: x86_64-unknown-linux-gnu
release: 1.61.0-nightly
LLVM version: 14.0.0

Additional Labels

No response

@hellow554 hellow554 added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Apr 4, 2022
@tony84727
Copy link

Maybe another similar false-positive example:

fn doing_thing(x: i32, y: i32) -> i32 {
    let mut diff = x ^ y;
    let mut distance = 0;
    for _ in 0..32 {
        if diff & 1 > 0 {
            distance += 1;
        }
        diff >>= 1;
    }
    distance
}
fn main() {
    println!("{}", doing_thing(100, 100));
}

Clippy returned:

warning: parameter is only used in recursion
 --> src/main.rs:1:16
  |
1 | fn doing_thing(x: i32, y: i32) -> i32 {
  |                ^ help: if this is intentional, prefix with an underscore: `_x`
  |
  = note: `#[warn(clippy::only_used_in_recursion)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#only_used_in_recursion

warning: parameter is only used in recursion
 --> src/main.rs:1:24
  |
1 | fn doing_thing(x: i32, y: i32) -> i32 {
  |                        ^ help: if this is intentional, prefix with an underscore: `_y`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#only_used_in_recursion

@hellow554
Copy link
Contributor Author

@tony84727 this is somewhat the same pattern as mine:

pub fn doing_thing(x: i32, y: i32) {
    let _diff = x ^ y;
}
warning: parameter is only used in recursion
 --> src/lib.rs:1:20
  |
1 | pub fn doing_thing(x: i32, y: i32) {
  |                    ^ help: if this is intentional, prefix with an underscore: `_x`
  |
  = note: `#[warn(clippy::only_used_in_recursion)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#only_used_in_recursion

warning: parameter is only used in recursion
 --> src/lib.rs:1:28
  |
1 | pub fn doing_thing(x: i32, y: i32) {
  |                            ^ help: if this is intentional, prefix with an underscore: `_y`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#only_used_in_recursion

But yeah, that should be fixed to. I try to investigate this a little bit further.

@hellow554
Copy link
Contributor Author

@buttercrab can you help us here? :)

@buttercrab
Copy link
Contributor

@hellow554 I'll change the algorithm as soon as I can.

@hellow554
Copy link
Contributor Author

No need to hurry! Take your time. I just wanted to know, if you know what could cause this. Sorry for the scare

@danieleades
Copy link

this is causing a false positive in rust-base64 - marshallpierce/rust-base64#188

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants