forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#50841 - oli-obk:promote_errors_to_panics, r=e…
…ddyb Don't lint numeric overflows in promoteds in release mode r? @eddyb mitigates rust-lang#50814
- Loading branch information
Showing
9 changed files
with
134 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![allow(const_err)] | ||
|
||
// error-pattern: attempt to divide by zero | ||
|
||
fn main() { | ||
let x = &(1 / (1 - 1)); | ||
} |
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,18 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![allow(const_err)] | ||
|
||
// error-pattern: overflow | ||
// compile-flags: -C overflow-checks=yes | ||
|
||
fn main() { | ||
let x: &'static u32 = &(0u32 - 1); | ||
} |
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,18 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![allow(const_err)] | ||
|
||
// compile-flags: -O | ||
|
||
fn main() { | ||
let x = &(0u32 - 1); | ||
assert_eq!(*x, u32::max_value()) | ||
} |
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 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(const_fn)] | ||
|
||
#![deny(const_err)] | ||
|
||
union Bar { | ||
a: &'static u8, | ||
b: usize, | ||
} | ||
|
||
const fn bar() -> u8 { | ||
unsafe { | ||
// this will error as long as this test | ||
// is run on a system whose pointers need more | ||
// than 8 bits | ||
Bar { a: &42 }.b as u8 | ||
//~^ constant evaluation error | ||
//~| constant evaluation error | ||
} | ||
} | ||
|
||
fn main() { | ||
// FIXME(oli-obk): this should compile but panic at runtime | ||
// if we change the `const_err` lint to allow this will actually compile, but then | ||
// continue with undefined values. | ||
let x: &'static u8 = &(bar() + 1); | ||
let y = *x; | ||
unreachable!(); | ||
} |
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,31 @@ | ||
error: constant evaluation error | ||
--> $DIR/promoted_const_fn_fail.rs:25:9 | ||
| | ||
LL | Bar { a: &42 }.b as u8 | ||
| ^^^^^^^^^^^^^^^^^^^^^^ a raw memory access tried to access part of a pointer value as raw bytes | ||
| | ||
note: lint level defined here | ||
--> $DIR/promoted_const_fn_fail.rs:13:9 | ||
| | ||
LL | #![deny(const_err)] | ||
| ^^^^^^^^^ | ||
note: inside call to `bar` | ||
--> $DIR/promoted_const_fn_fail.rs:35:28 | ||
| | ||
LL | let x: &'static u8 = &(bar() + 1); | ||
| ^^^^^ | ||
|
||
error: constant evaluation error | ||
--> $DIR/promoted_const_fn_fail.rs:25:9 | ||
| | ||
LL | Bar { a: &42 }.b as u8 | ||
| ^^^^^^^^^^^^^^^^^^^^^^ a raw memory access tried to access part of a pointer value as raw bytes | ||
| | ||
note: inside call to `bar` | ||
--> $DIR/promoted_const_fn_fail.rs:35:28 | ||
| | ||
LL | let x: &'static u8 = &(bar() + 1); | ||
| ^^^^^ | ||
|
||
error: aborting due to 2 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