rust-lang / rust-lang/rust-clippy

`arithmetic_side_effects` should trigger on `pow()`

Open
#17,540 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-negative
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

The .pow() method on integers is implicit about what happens on overflow and has each of the checked, overflowing, saturating, strict and wrapping variants, just like the other arithmetic operations. So it should be treated the same way in this lint.

Lint Name

arithmetic_side_effects

Reproducer

I tried this code:

#![deny(clippy::arithmetic_side_effects)]

fn foo(n: u32) -> u32 {
    n.pow(20)
}

I expected to see this happen: The lint should trigger, just like it does for n + 1.

Instead, this happened: Nothing.

Version

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the arithmetic_side_effects lint implementation and its tests, then compare how pow() is handled with the existing n + 1 case. The work is done when the reproducer triggers the lint and a regression test covers the expected diagnostic.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.