Skip to content

arithmetic_overflow lint not triggered for overflowing shifts in promoteds #117949

Closed
@cchudant

Description

@cchudant

I tried this code:

format_args!("{}", 1 << 32)

I expected to see this happen:

Same output as

let a = 1 << 32;
format_args!("{}", a)

which would be

error: this arithmetic operation will overflow
 --> src/main.rs:3:9
  |
3 | let a = 1 << 32;
  |         ^^^^^^^ attempt to shift left by `32_i32`, which would overflow
  |
  = note: `#[deny(arithmetic_overflow)]` on by default

Instead, this happened:

The code compiles with no error, the lint is not produced.
When running it, it overflows: panics at debug mode, and gives the wrong output in release.

Meta

Tested with the current stable, nightly and beta from the playground.

I have tried finding whether this has already been reported, it seems it hasn't

Metadata

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions