Skip to content

Commit 2d1acd9

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

22 files changed

+365
-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:11:19
3+
|
4+
LL | const C: () = panic!();
5+
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-drop.rs:11: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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//@revisions: no-opt
2+
//FIXME: `opt` revision currently does not stop with an error due to
3+
//<https://github.com/rust-lang/rust/issues/107503>.
4+
//@ build-fail
5+
//@[opt] compile-flags: -O
6+
//! Make sure we detect erroneous constants post-monomorphization even when they are unused. This is
7+
//! crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090)
8+
9+
struct Fail<T>(T);
10+
impl<T> Fail<T> {
11+
const C: () = panic!(); //~ERROR evaluation of `Fail::<i32>::C` failed
12+
}
13+
14+
// This function is not actually called, but is mentioned implicitly as destructor in dead code in a
15+
// function that is called. Make sure we still find this error.
16+
impl<T> Drop for Fail<T> {
17+
fn drop(&mut self) {
18+
let _ = Fail::<T>::C;
19+
}
20+
}
21+
22+
#[inline(never)]
23+
fn called<T>(x: T) {
24+
if false {
25+
let v = Fail(x);
26+
drop(v);
27+
}
28+
}
29+
30+
pub fn main() {
31+
called::<i32>(0);
32+
}
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:11:19
3+
|
4+
LL | const C: () = panic!();
5+
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-fn.rs:11: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:28: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)