Skip to content

False positive on only_used_in_recursion #9384

Closed
@didibear

Description

@didibear

Summary

The lint only_used_in_recursion is raising an error but I cannot figure out why.
You can check this Rust Playground here.

Lint Name

only_used_in_recursion

Reproducer

I tried this code (Rust Playground):

#![deny(clippy::only_used_in_recursion)]

struct Value(i32);

fn set_to_last(mut value: Value, values: &[i32]) {
    value.0 = *values.iter().last().unwrap(); 
}

I saw this happen:

error: parameter is only used in recursion
 --> src/lib.rs:6:16
  |
6 | fn set_to_last(mut value: Value, values: &[i32]) {
  |                ^^^^^^^^^ help: if this is intentional, prefix with an underscore: `_value`
  |
note: the lint level is defined here
 --> src/lib.rs:2:9
  |
2 | #![deny(clippy::only_used_in_recursion)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#only_used_in_recursion

I expected no error.

Version

rustc 1.63.0 (4b91a6ea7 2022-08-08)
binary: rustc
commit-hash: 4b91a6ea7258a947e59c6522cd5898e7c0a6a88f
commit-date: 2022-08-08
host: x86_64-apple-darwin
release: 1.63.0
LLVM version: 14.0.5

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions