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.
Ensure that unevaluated constants of type
!
are present in the MIR
- Loading branch information
1 parent
df26968
commit d2ed209
Showing
8 changed files
with
150 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Regression test for #66975 - ensure that we don't keep unevaluated | ||
// `!`-typed constants until codegen. | ||
|
||
// Force generation of optimized mir for functions that do not reach codegen. | ||
// compile-flags: --emit mir,link | ||
|
||
#![feature(const_panic)] | ||
|
||
struct PrintName<T>(T); | ||
|
||
impl<T> PrintName<T> { | ||
const VOID: ! = panic!(); | ||
} | ||
|
||
fn no_codegen<T>() { | ||
let _ = PrintName::<T>::VOID; | ||
} | ||
|
||
fn main() {} | ||
|
||
// END RUST SOURCE | ||
// START rustc.no_codegen.PreCodegen.after.mir | ||
// bb0: { | ||
// StorageLive(_1); | ||
// _1 = const PrintName::<T>::VOID; | ||
// unreachable; | ||
// } | ||
// END rustc.no_codegen.PreCodegen.after.mir |
18 changes: 18 additions & 0 deletions
18
src/test/ui/consts/const-eval/index-out-of-bounds-never-type.rs
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 @@ | ||
// Regression test for #66975 | ||
#![warn(const_err)] | ||
|
||
struct PrintName<T>(T); | ||
|
||
impl<T> PrintName<T> { | ||
const VOID: ! = { let x = 0 * std::mem::size_of::<T>(); [][x] }; | ||
//~^ WARN any use of this value will cause an error | ||
} | ||
|
||
fn f<T>() { | ||
let _ = PrintName::<T>::VOID; | ||
//~^ ERROR erroneous constant encountered | ||
} | ||
|
||
pub fn main() { | ||
f::<()>(); | ||
} |
22 changes: 22 additions & 0 deletions
22
src/test/ui/consts/const-eval/index-out-of-bounds-never-type.stderr
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 @@ | ||
warning: any use of this value will cause an error | ||
--> $DIR/index-out-of-bounds-never-type.rs:7:61 | ||
| | ||
LL | const VOID: ! = { let x = 0 * std::mem::size_of::<T>(); [][x] }; | ||
| --------------------------------------------------------^^^^^--- | ||
| | | ||
| index out of bounds: the len is 0 but the index is 0 | ||
| | ||
note: lint level defined here | ||
--> $DIR/index-out-of-bounds-never-type.rs:2:9 | ||
| | ||
LL | #![warn(const_err)] | ||
| ^^^^^^^^^ | ||
|
||
error: erroneous constant encountered | ||
--> $DIR/index-out-of-bounds-never-type.rs:12:13 | ||
| | ||
LL | let _ = PrintName::<T>::VOID; | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
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,15 @@ | ||
// Regression test for #66975 | ||
#![warn(const_err)] | ||
#![feature(const_panic)] | ||
|
||
struct PrintName; | ||
|
||
impl PrintName { | ||
const VOID: ! = panic!(); | ||
//~^ WARN any use of this value will cause an error | ||
} | ||
|
||
fn main() { | ||
let _ = PrintName::VOID; | ||
//~^ ERROR erroneous constant used | ||
} |
24 changes: 24 additions & 0 deletions
24
src/test/ui/consts/const-eval/panic-assoc-never-type.stderr
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,24 @@ | ||
warning: any use of this value will cause an error | ||
--> $DIR/panic-assoc-never-type.rs:8:21 | ||
| | ||
LL | const VOID: ! = panic!(); | ||
| ----------------^^^^^^^^- | ||
| | | ||
| the evaluated program panicked at 'explicit panic', $DIR/panic-assoc-never-type.rs:8:21 | ||
| | ||
note: lint level defined here | ||
--> $DIR/panic-assoc-never-type.rs:2:9 | ||
| | ||
LL | #![warn(const_err)] | ||
| ^^^^^^^^^ | ||
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) | ||
|
||
error[E0080]: erroneous constant used | ||
--> $DIR/panic-assoc-never-type.rs:13:13 | ||
| | ||
LL | let _ = PrintName::VOID; | ||
| ^^^^^^^^^^^^^^^ referenced constant has errors | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
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,11 @@ | ||
// Regression test for #66975 | ||
#![warn(const_err)] | ||
#![feature(const_panic)] | ||
|
||
const VOID: ! = panic!(); | ||
//~^ WARN any use of this value will cause an error | ||
|
||
fn main() { | ||
let _ = VOID; | ||
//~^ ERROR erroneous constant used | ||
} |
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,24 @@ | ||
warning: any use of this value will cause an error | ||
--> $DIR/panic-never-type.rs:5:17 | ||
| | ||
LL | const VOID: ! = panic!(); | ||
| ----------------^^^^^^^^- | ||
| | | ||
| the evaluated program panicked at 'explicit panic', $DIR/panic-never-type.rs:5:17 | ||
| | ||
note: lint level defined here | ||
--> $DIR/panic-never-type.rs:2:9 | ||
| | ||
LL | #![warn(const_err)] | ||
| ^^^^^^^^^ | ||
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) | ||
|
||
error[E0080]: erroneous constant used | ||
--> $DIR/panic-never-type.rs:9:13 | ||
| | ||
LL | let _ = VOID; | ||
| ^^^^ referenced constant has errors | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |