Skip to content

New Lint: function argument only used in recursion #8390

@buttercrab

Description

@buttercrab

What it does

Arguments that are used only in recursion to itself.
Since it is used, the warning unused_variables does not come out, but it is useless.

Lint Name

only_used_in_recursion

Category

perf

Advantage

  • Lowers the complexity of the function.
  • Better performance when the useless argument have some operation (like below example)

Drawbacks

No response

Example

fn f(a: usize, b: usize) -> usize {
    if a == 0 {
        1
    } else {
        f(a - 1, b + 1)
    }
}

fn main() {
    print!("{}", f(1, 1));
}

Could be written as:

fn f(a: usize) -> usize {
    if a == 0 {
        1
    } else {
        f(a - 1)
    }
}

fn main() {
    print!("{}", f(1));
}

Metadata

Metadata

Assignees

Labels

A-lintArea: New lints

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions