Skip to content

Implement redundant idempotent calls lint#17187

Open
Francisco-Andre-Martins wants to merge 2 commits into
rust-lang:masterfrom
Francisco-Andre-Martins:feat#16099-remove-redundant-method-calls
Open

Implement redundant idempotent calls lint#17187
Francisco-Andre-Martins wants to merge 2 commits into
rust-lang:masterfrom
Francisco-Andre-Martins:feat#16099-remove-redundant-method-calls

Conversation

@Francisco-Andre-Martins

Copy link
Copy Markdown

When a method that is idempotent (calling it multiple times produces the same result as calling it once) is called on a value that has already had the same method applied with the same arguments, the second call is redundant and can be removed.

Examples of idempotent methods: 'to_lowercase', 'to_uppercase', 'trim', 'trim_start', 'trim_end', 'abs', 'floor', 'ceil', 'round', 'max', 'min', 'clamp', 'and', 'or', 'to_vec', 'to_ascii_lowercase', 'to_ascii_uppercase', 'signum'.

Some methods were left out as a possible follow-up, either because each call wraps the value in a new iterator adapter rather than being a true idempotent, because they have side effects, or because they are only idempotent under very specific conditions.

Closes #16099

changelog: implement redundant idempotent call lint

When a method that is idempotent (calling it multiple times
produces the same result as calling it once) is called on a value
that has already had the same method applied with the same arguments,
the second call is redundant and can be removed.

Examples of idempotent methods: 'to_lowercase', 'to_uppercase',
'trim', 'trim_start', 'trim_end', 'abs', 'floor', 'ceil', 'round',
'max', 'min', 'clamp', 'and', 'or', 'to_vec', 'to_ascii_lowercase',
'to_ascii_uppercase', 'signum'.

Some methods were left out as a possible follow-up, either because each
call wraps the value in a new iterator adapter rather than being a true
idempotent, because they have side effects, or because they are only
idempotent under very specific conditions.

Closes rust-lang#16099
Co-authored-by: Guilherme Silva <guilherme.d.silva@tecnico.ulisboa.pt>
@rustbot rustbot added needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jun 8, 2026
@rustbot

rustbot commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @samueltardieu (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue
Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 8 candidates
  • 8 candidates expanded to 8 candidates
  • Random selection from Jarcho, dswij, llogiq, samueltardieu

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

Lintcheck changes for 0b846fb

Lint Added Removed Changed
clippy::redundant_idempotent_calls 1 0 0

This comment will be updated if you push new changes

@samueltardieu

samueltardieu commented Jun 8, 2026

Copy link
Copy Markdown
Member

Tests need to pass (including "dogfood")

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jun 8, 2026
@rustbot

rustbot commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@S1gn3rs

S1gn3rs commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Yup, sorry for the inconvenient, it should be ready now.
@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

new lint to remove redundant method calls that have no effect

4 participants