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.
Rollup merge of rust-lang#64063 - JohnTitor:fix-const-err, r=oli-obk
Fix const_err with `-(-0.0)` Fixes rust-lang#64059 r? @oli-obk
- Loading branch information
Showing
14 changed files
with
477 additions
and
53 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
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// needed because negating int::MIN will behave differently between | ||
// optimized compilation and unoptimized compilation and thus would | ||
// lead to different lints being emitted | ||
// compile-flags: -C overflow-checks=on -O | ||
|
||
#![feature(rustc_attrs)] | ||
#![allow(exceeding_bitshifts)] | ||
|
||
#![deny(const_err)] | ||
|
||
fn black_box<T>(_: T) { | ||
unimplemented!() | ||
} | ||
|
||
fn main() { | ||
let a = -std::i8::MIN; | ||
//~^ ERROR const_err | ||
let b = 200u8 + 200u8 + 200u8; | ||
//~^ ERROR const_err | ||
let c = 200u8 * 4; | ||
//~^ ERROR const_err | ||
let d = 42u8 - (42u8 + 1); | ||
//~^ ERROR const_err | ||
let _e = [5u8][1]; | ||
//~^ ERROR const_err | ||
black_box(a); | ||
black_box(b); | ||
black_box(c); | ||
black_box(d); | ||
} |
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,38 @@ | ||
error: attempt to negate with overflow | ||
--> $DIR/const-err3.rs:16:13 | ||
| | ||
LL | let a = -std::i8::MIN; | ||
| ^^^^^^^^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/const-err3.rs:9:9 | ||
| | ||
LL | #![deny(const_err)] | ||
| ^^^^^^^^^ | ||
|
||
error: attempt to add with overflow | ||
--> $DIR/const-err3.rs:18:13 | ||
| | ||
LL | let b = 200u8 + 200u8 + 200u8; | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: attempt to multiply with overflow | ||
--> $DIR/const-err3.rs:20:13 | ||
| | ||
LL | let c = 200u8 * 4; | ||
| ^^^^^^^^^ | ||
|
||
error: attempt to subtract with overflow | ||
--> $DIR/const-err3.rs:22:13 | ||
| | ||
LL | let d = 42u8 - (42u8 + 1); | ||
| ^^^^^^^^^^^^^^^^^ | ||
|
||
error: index out of bounds: the len is 1 but the index is 1 | ||
--> $DIR/const-err3.rs:24:14 | ||
| | ||
LL | let _e = [5u8][1]; | ||
| ^^^^^^^^ | ||
|
||
error: aborting due to 5 previous errors | ||
|
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// compile-flags: -C overflow-checks=on -O | ||
|
||
#![deny(const_err)] | ||
|
||
fn main() { | ||
println!("{}", 0u32 - 1); | ||
//~^ ERROR attempt to subtract with overflow | ||
let _x = 0u32 - 1; | ||
//~^ ERROR attempt to subtract with overflow | ||
println!("{}", 1/(1-1)); | ||
//~^ ERROR attempt to divide by zero [const_err] | ||
//~| ERROR reaching this expression at runtime will panic or abort [const_err] | ||
let _x = 1/(1-1); | ||
//~^ ERROR const_err | ||
//~| ERROR const_err | ||
println!("{}", 1/(false as u32)); | ||
//~^ ERROR attempt to divide by zero [const_err] | ||
//~| ERROR reaching this expression at runtime will panic or abort [const_err] | ||
let _x = 1/(false as u32); | ||
//~^ ERROR const_err | ||
//~| ERROR const_err | ||
} |
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,68 @@ | ||
error: attempt to subtract with overflow | ||
--> $DIR/promoted_errors2.rs:6:20 | ||
| | ||
LL | println!("{}", 0u32 - 1); | ||
| ^^^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/promoted_errors2.rs:3:9 | ||
| | ||
LL | #![deny(const_err)] | ||
| ^^^^^^^^^ | ||
|
||
error: attempt to subtract with overflow | ||
--> $DIR/promoted_errors2.rs:8:14 | ||
| | ||
LL | let _x = 0u32 - 1; | ||
| ^^^^^^^^ | ||
|
||
error: attempt to divide by zero | ||
--> $DIR/promoted_errors2.rs:10:20 | ||
| | ||
LL | println!("{}", 1/(1-1)); | ||
| ^^^^^^^ | ||
|
||
error: reaching this expression at runtime will panic or abort | ||
--> $DIR/promoted_errors2.rs:10:20 | ||
| | ||
LL | println!("{}", 1/(1-1)); | ||
| ^^^^^^^ attempt to divide by zero | ||
|
||
error: attempt to divide by zero | ||
--> $DIR/promoted_errors2.rs:13:14 | ||
| | ||
LL | let _x = 1/(1-1); | ||
| ^^^^^^^ | ||
|
||
error: this expression will panic at runtime | ||
--> $DIR/promoted_errors2.rs:13:14 | ||
| | ||
LL | let _x = 1/(1-1); | ||
| ^^^^^^^ attempt to divide by zero | ||
|
||
error: attempt to divide by zero | ||
--> $DIR/promoted_errors2.rs:16:20 | ||
| | ||
LL | println!("{}", 1/(false as u32)); | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: reaching this expression at runtime will panic or abort | ||
--> $DIR/promoted_errors2.rs:16:20 | ||
| | ||
LL | println!("{}", 1/(false as u32)); | ||
| ^^^^^^^^^^^^^^^^ attempt to divide by zero | ||
|
||
error: attempt to divide by zero | ||
--> $DIR/promoted_errors2.rs:19:14 | ||
| | ||
LL | let _x = 1/(false as u32); | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: this expression will panic at runtime | ||
--> $DIR/promoted_errors2.rs:19:14 | ||
| | ||
LL | let _x = 1/(false as u32); | ||
| ^^^^^^^^^^^^^^^^ attempt to divide by zero | ||
|
||
error: aborting due to 10 previous errors | ||
|
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,6 @@ | ||
// compile-flags: -C overflow-checks=on -O | ||
// run-pass | ||
|
||
fn main() { | ||
let _ = -(-0.0); | ||
} |
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,5 @@ | ||
// run-pass | ||
|
||
fn main() { | ||
let _ = -(-0.0); | ||
} |
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,3 +1,5 @@ | ||
// compile-flags: -O | ||
|
||
#![deny(const_err)] | ||
|
||
use std::{isize, i8, i16, i32, i64}; | ||
|
Oops, something went wrong.