Skip to content

Commit 219ce16

Browse files
committed
const-eval: organize and extend tests for required-consts
1 parent 7de1a1f commit 219ce16

22 files changed

+362
-72
lines changed

tests/ui/consts/const-eval/erroneous-const.stderr

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/ui/consts/const-eval/erroneous-const2.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/ui/consts/const-eval/erroneous-const2.stderr

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/ui/consts/const-eval/unused-broken-const-late.stderr

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0080]: evaluation of `Fail::<i32>::C` failed
2+
--> $DIR/collect-in-called-fn.rs:9:19
3+
|
4+
LL | const C: () = panic!();
5+
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-called-fn.rs:9:19
6+
|
7+
= 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)
8+
9+
note: the above error was encountered while instantiating `fn called::<i32>`
10+
--> $DIR/collect-in-called-fn.rs:23:5
11+
|
12+
LL | called::<i32>();
13+
| ^^^^^^^^^^^^^^^
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0080`.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0080]: evaluation of `Fail::<i32>::C` failed
2+
--> $DIR/collect-in-called-fn.rs:9:19
3+
|
4+
LL | const C: () = panic!();
5+
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-called-fn.rs:9:19
6+
|
7+
= 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)
8+
9+
note: the above error was encountered while instantiating `fn called::<i32>`
10+
--> $DIR/collect-in-called-fn.rs:23:5
11+
|
12+
LL | called::<i32>();
13+
| ^^^^^^^^^^^^^^^
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0080`.
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1+
//@revisions: opt no-opt
12
//@ build-fail
2-
//@ compile-flags: -O
3+
//@[opt] compile-flags: -O
34
//! Make sure we detect erroneous constants post-monomorphization even when they are unused. This is
45
//! crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090)
56
6-
struct PrintName<T>(T);
7-
impl<T> PrintName<T> {
8-
const VOID: () = panic!(); //~ERROR evaluation of `PrintName::<i32>::VOID` failed
7+
struct Fail<T>(T);
8+
impl<T> Fail<T> {
9+
const C: () = panic!(); //~ERROR evaluation of `Fail::<i32>::C` failed
910
}
1011

11-
fn no_codegen<T>() {
12+
#[inline(never)]
13+
fn called<T>() {
1214
// Any function that is called is guaranteed to have all consts that syntactically
1315
// appear in its body evaluated, even if they only appear in dead code.
16+
// This relies on mono-item collection checking `required_consts` in collected functions.
1417
if false {
15-
let _ = PrintName::<T>::VOID;
18+
let _ = Fail::<T>::C;
1619
}
1720
}
21+
1822
pub fn main() {
19-
no_codegen::<i32>();
23+
called::<i32>();
2024
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0080]: evaluation of `Fail::<i32>::C` failed
2+
--> $DIR/collect-in-dead-drop.rs:10:19
3+
|
4+
LL | const C: () = panic!();
5+
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-drop.rs:10:19
6+
|
7+
= 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)
8+
9+
note: the above error was encountered while instantiating `fn <Fail<i32> as std::ops::Drop>::drop`
10+
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0080`.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//@revisions: no-opt
2+
//FIXME: `opt` revision currently does not stop with an error due to <https://github.com/rust-lang/rust/issues/107503>
3+
//@ build-fail
4+
//@[opt] compile-flags: -O
5+
//! Make sure we detect erroneous constants post-monomorphization even when they are unused. This is
6+
//! crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090)
7+
8+
struct Fail<T>(T);
9+
impl<T> Fail<T> {
10+
const C: () = panic!(); //~ERROR evaluation of `Fail::<i32>::C` failed
11+
}
12+
13+
// This function is not actually called, but is mentioned implicitly as destructor in dead code in a
14+
// function that is called. Make sure we still find this error.
15+
impl<T> Drop for Fail<T> {
16+
fn drop(&mut self) {
17+
let _ = Fail::<T>::C;
18+
}
19+
}
20+
21+
#[inline(never)]
22+
fn called<T>(x: T) {
23+
if false {
24+
let v = Fail(x);
25+
drop(v);
26+
}
27+
}
28+
29+
pub fn main() {
30+
called::<i32>(0);
31+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0080]: evaluation of `Fail::<i32>::C` failed
2+
--> $DIR/collect-in-dead-fn.rs:10:19
3+
|
4+
LL | const C: () = panic!();
5+
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-fn.rs:10:19
6+
|
7+
= 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)
8+
9+
note: the above error was encountered while instantiating `fn not_called::<i32>`
10+
--> $DIR/collect-in-dead-fn.rs:27:9
11+
|
12+
LL | not_called::<T>();
13+
| ^^^^^^^^^^^^^^^^^
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)