forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't panic if the lhs of a div by zero is not statically known
- Loading branch information
Showing
3 changed files
with
42 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
// check-pass | ||
|
||
// compile-flags: --crate-type lib | ||
|
||
#![warn(unconditional_panic)] | ||
|
||
pub struct Fixed64(i64); | ||
|
||
pub fn div(f: Fixed64) { | ||
f.0 / 0; | ||
// HACK: this test passes only because this is a const fn that is written to metadata | ||
pub const fn div(f: Fixed64) { | ||
f.0 / 0; //~ WARN will panic at runtime | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
warning: this operation will panic at runtime | ||
--> $DIR/ice-assert-fail-div-by-zero.rs:11:5 | ||
| | ||
LL | f.0 / 0; | ||
| ^^^^^^^ attempt to divide _ by zero | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/ice-assert-fail-div-by-zero.rs:5:9 | ||
| | ||
LL | #![warn(unconditional_panic)] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: 1 warning emitted | ||
|