forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
properly fill a promoted's required_consts
then we can also make all_required_consts_are_checked a constant instead of a function
- Loading branch information
Showing
13 changed files
with
149 additions
and
54 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
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
37 changes: 37 additions & 0 deletions
37
tests/ui/consts/required-consts/collect-in-promoted-const.noopt.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,37 @@ | ||
error[E0080]: evaluation of `Fail::<i32>::C` failed | ||
--> $DIR/collect-in-promoted-const.rs:9:19 | ||
| | ||
LL | const C: () = panic!(); | ||
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-promoted-const.rs:9:19 | ||
| | ||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
note: erroneous constant encountered | ||
--> $DIR/collect-in-promoted-const.rs:20:21 | ||
| | ||
LL | let _val = &Fail::<T>::C; | ||
| ^^^^^^^^^^^^ | ||
|
||
note: erroneous constant encountered | ||
--> $DIR/collect-in-promoted-const.rs:20:20 | ||
| | ||
LL | let _val = &Fail::<T>::C; | ||
| ^^^^^^^^^^^^^ | ||
|
||
note: erroneous constant encountered | ||
--> $DIR/collect-in-promoted-const.rs:20:21 | ||
| | ||
LL | let _val = &Fail::<T>::C; | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
|
||
note: the above error was encountered while instantiating `fn f::<i32>` | ||
--> $DIR/collect-in-promoted-const.rs:25:5 | ||
| | ||
LL | f::<i32>(); | ||
| ^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
53 changes: 53 additions & 0 deletions
53
tests/ui/consts/required-consts/collect-in-promoted-const.opt.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,53 @@ | ||
error[E0080]: evaluation of `Fail::<T>::C` failed | ||
--> $DIR/collect-in-promoted-const.rs:9:19 | ||
| | ||
LL | const C: () = panic!(); | ||
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-promoted-const.rs:9:19 | ||
| | ||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
note: erroneous constant encountered | ||
--> $DIR/collect-in-promoted-const.rs:20:21 | ||
| | ||
LL | let _val = &Fail::<T>::C; | ||
| ^^^^^^^^^^^^ | ||
|
||
error[E0080]: evaluation of `Fail::<i32>::C` failed | ||
--> $DIR/collect-in-promoted-const.rs:9:19 | ||
| | ||
LL | const C: () = panic!(); | ||
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-promoted-const.rs:9:19 | ||
| | ||
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
note: erroneous constant encountered | ||
--> $DIR/collect-in-promoted-const.rs:20:21 | ||
| | ||
LL | let _val = &Fail::<T>::C; | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
|
||
note: erroneous constant encountered | ||
--> $DIR/collect-in-promoted-const.rs:20:20 | ||
| | ||
LL | let _val = &Fail::<T>::C; | ||
| ^^^^^^^^^^^^^ | ||
|
||
note: erroneous constant encountered | ||
--> $DIR/collect-in-promoted-const.rs:20:21 | ||
| | ||
LL | let _val = &Fail::<T>::C; | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
|
||
note: the above error was encountered while instantiating `fn f::<i32>` | ||
--> $DIR/collect-in-promoted-const.rs:25:5 | ||
| | ||
LL | f::<i32>(); | ||
| ^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
26 changes: 26 additions & 0 deletions
26
tests/ui/consts/required-consts/collect-in-promoted-const.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,26 @@ | ||
//@revisions: noopt opt | ||
//@ build-fail | ||
//@[noopt] compile-flags: -Copt-level=0 | ||
//@[opt] compile-flags: -O | ||
//! Make sure we error on erroneous consts even if they get promoted. | ||
struct Fail<T>(T); | ||
impl<T> Fail<T> { | ||
const C: () = panic!(); //~ERROR evaluation of `Fail::<i32>::C` failed | ||
//[opt]~^ ERROR evaluation of `Fail::<T>::C` failed | ||
// (Not sure why optimizations lead to this being emitted twice, but as long as compilation | ||
// fails either way it's fine.) | ||
} | ||
|
||
#[inline(never)] | ||
fn f<T>() { | ||
if false { | ||
// If promotion moved `C` from our required_consts to its own, without adding itself to | ||
// our required_consts, then we'd miss the const-eval failure here. | ||
let _val = &Fail::<T>::C; | ||
} | ||
} | ||
|
||
fn main() { | ||
f::<i32>(); | ||
} |
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