Skip to content

arithmetic_side_effects not triggering on potential divison by zero #10583

Closed
@DrSloth

Description

@DrSloth

Summary

The arithmetic_side_effects lint triggers for operations that have potential side effects like overflows or panics. It seems like this catches cases of dividing a constant by a variable.

Lint Name

arithmetic_side_effects

Reproducer

I tried this code:

#![deny(clippy::arithmetic_side_effects)]
#![allow(dead_code)]

fn is_correctly_denied(a: u16, b: u16) -> u16 {
    a / b
}

fn is_correctly_allowed(a: u16) -> u16 {
    a / 10
}

fn is_incorrectly_allowed(a: u16) -> u16 {
    10 / a
}

fn main() {
    println!("{}", is_incorrectly_allowed(0))
}

Playground link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=9e16914751e8bb493a80cd8bb46415b6

I expected to see this happen:
The is_incorrectly_allowed function should be denied

Instead, this happened:
The function is not denied and the program panics with a division by zero

Version

rustc 1.68.1 (8460ca823 2023-03-20)
binary: rustc
commit-hash: 8460ca823e8367a30dda430efda790588b8c84d3
commit-date: 2023-03-20
host: x86_64-unknown-linux-gnu
release: 1.68.1
LLVM version: 15.0.6

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions