Skip to content

no warning for div by zero: let x = 1 / false as u8; #49760

Closed
@matthiaskrgr

Description

@matthiaskrgr

inlined inside a println!(), I get a warning:

fn main() {
    println!("{}", 1/false as u8);
}
error[E0080]: constant evaluation error
 --> src/main.rs:4:17
  |
4 |     println!("{}", 1/false as u8);
  |                    ^^^^^^^^^^^^^ attempted to do overflowing math
error: aborting due to previous error

however, when I involve a variable

fn main() {
	let x = 1 / false as u8;
	println!("{}", x);
}

there is no warning at all but looking at the generated code it is quite clear that this panics:
https://godbolt.org/g/NQmSFM

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions