Skip to content

Commit c3124c7

Browse files
authored
Unrolled build for rust-lang#122440
Rollup merge of rust-lang#122440 - RalfJung:required-consts, r=oli-obk const-eval: organize and extend tests for required-consts This includes some tests that are known-broken and hence disabled (due to rust-lang#107503). r? `````@oli-obk`````
2 parents e69f14b + 514b274 commit c3124c7

25 files changed

+447
-72
lines changed

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

-15
This file was deleted.

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

-19
This file was deleted.

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

-15
This file was deleted.

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

-11
This file was deleted.
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
@@ -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: noopt 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
}
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:12:19
3+
|
4+
LL | const C: () = panic!();
5+
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-drop.rs:12: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`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//@revisions: noopt opt
2+
//@[noopt] build-fail
3+
//@[opt] compile-flags: -O
4+
//FIXME: `opt` revision currently does not stop with an error due to
5+
//<https://github.com/rust-lang/rust/issues/107503>.
6+
//@[opt] build-pass
7+
//! Make sure we detect erroneous constants post-monomorphization even when they are unused. This is
8+
//! crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090)
9+
10+
struct Fail<T>(T);
11+
impl<T> Fail<T> {
12+
const C: () = panic!(); //[noopt]~ERROR evaluation of `Fail::<i32>::C` failed
13+
}
14+
15+
// This function is not actually called, but is mentioned implicitly as destructor in dead code in a
16+
// function that is called. Make sure we still find this error.
17+
impl<T> Drop for Fail<T> {
18+
fn drop(&mut self) {
19+
let _ = Fail::<T>::C;
20+
}
21+
}
22+
23+
#[inline(never)]
24+
fn called<T>(x: T) {
25+
if false {
26+
let v = Fail(x);
27+
// Now it gest dropped implicitly, at the end of this scope.
28+
}
29+
}
30+
31+
pub fn main() {
32+
called::<i32>(0);
33+
}
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:12:19
3+
|
4+
LL | const C: () = panic!();
5+
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-fn.rs:12: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:29: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`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//@revisions: noopt opt
2+
//@[noopt] build-fail
3+
//@[opt] compile-flags: -O
4+
//FIXME: `opt` revision currently does not stop with an error due to
5+
//<https://github.com/rust-lang/rust/issues/107503>.
6+
//@[opt] build-pass
7+
//! Make sure we detect erroneous constants post-monomorphization even when they are unused. This is
8+
//! crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090)
9+
10+
struct Fail<T>(T);
11+
impl<T> Fail<T> {
12+
const C: () = panic!(); //[noopt]~ERROR evaluation of `Fail::<i32>::C` failed
13+
}
14+
15+
// This function is not actually called, but it is mentioned in dead code in a function that is
16+
// called. Make sure we still find this error.
17+
// This relies on mono-item collection checking `required_consts` in functions that syntactically
18+
// are called in collected functions (even inside dead code).
19+
#[inline(never)]
20+
fn not_called<T>() {
21+
if false {
22+
let _ = Fail::<T>::C;
23+
}
24+
}
25+
26+
#[inline(never)]
27+
fn called<T>() {
28+
if false {
29+
not_called::<T>();
30+
}
31+
}
32+
33+
pub fn main() {
34+
called::<i32>();
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//@revisions: noopt opt
2+
//@build-pass
3+
//@[opt] compile-flags: -O
4+
//! Make sure we detect erroneous constants post-monomorphization even when they are unused. This is
5+
//! crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090)
6+
7+
struct Fail<T>(T);
8+
impl<T> Fail<T> {
9+
const C: () = panic!();
10+
}
11+
12+
// This function is not actually called, but is mentioned implicitly as destructor in dead code in a
13+
// function that is called. Make sure we still find this error.
14+
impl<T> Drop for Fail<T> {
15+
fn drop(&mut self) {
16+
let _ = Fail::<T>::C;
17+
}
18+
}
19+
20+
#[inline(never)]
21+
fn called<T>(x: T) {
22+
if false {
23+
let v = Fail(x);
24+
std::mem::forget(v);
25+
// Now the destructor never gets "mentioned" so this build should *not* fail.
26+
// IOW, this demonstrates that we are using a post-drop-elab notion of "mentioned".
27+
}
28+
}
29+
30+
pub fn main() {
31+
called::<i32>(0);
32+
}
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-move.rs:12:19
3+
|
4+
LL | const C: () = panic!();
5+
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-move.rs:12: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`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//@revisions: noopt opt
2+
//@[noopt] build-fail
3+
//@[opt] compile-flags: -O
4+
//FIXME: `opt` revision currently does not stop with an error due to
5+
//<https://github.com/rust-lang/rust/issues/107503>.
6+
//@[opt] build-pass
7+
//! Make sure we detect erroneous constants post-monomorphization even when they are unused. This is
8+
//! crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090)
9+
10+
struct Fail<T>(T);
11+
impl<T> Fail<T> {
12+
const C: () = panic!(); //[noopt]~ERROR evaluation of `Fail::<i32>::C` failed
13+
}
14+
15+
// This function is not actually called, but is mentioned implicitly as destructor in dead code in a
16+
// function that is called. Make sure we still find this error.
17+
impl<T> Drop for Fail<T> {
18+
fn drop(&mut self) {
19+
let _ = Fail::<T>::C;
20+
}
21+
}
22+
23+
#[inline(never)]
24+
fn called<T>(x: T) {
25+
if false {
26+
let v = Fail(x);
27+
drop(v); // move `v` away (and it then gets dropped there so build still fails)
28+
}
29+
}
30+
31+
pub fn main() {
32+
called::<i32>(0);
33+
}
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-vtable.rs:12:19
3+
|
4+
LL | const C: () = panic!();
5+
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-vtable.rs:12: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 <std::vec::Vec<i32> as MyTrait>::not_called`
10+
--> $DIR/collect-in-dead-vtable.rs:35:40
11+
|
12+
LL | let gen_vtable: &dyn MyTrait = &v; // vtable "appears" here
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
@@ -0,0 +1,41 @@
1+
//@revisions: noopt opt
2+
//@[noopt] build-fail
3+
//@[opt] compile-flags: -O
4+
//FIXME: `opt` revision currently does not stop with an error due to
5+
//<https://github.com/rust-lang/rust/issues/107503>.
6+
//@[opt] build-pass
7+
//! Make sure we detect erroneous constants post-monomorphization even when they are unused. This is
8+
//! crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090)
9+
10+
struct Fail<T>(T);
11+
impl<T> Fail<T> {
12+
const C: () = panic!(); //[noopt]~ERROR evaluation of `Fail::<i32>::C` failed
13+
}
14+
15+
trait MyTrait {
16+
fn not_called(&self);
17+
}
18+
19+
// This function is not actually called, but it is mentioned in a vtable in a function that is
20+
// called. Make sure we still find this error.
21+
// This relies on mono-item collection checking `required_consts` in functions that are referenced
22+
// in vtables that syntactically appear in collected functions (even inside dead code).
23+
impl<T> MyTrait for Vec<T> {
24+
fn not_called(&self) {
25+
if false {
26+
let _ = Fail::<T>::C;
27+
}
28+
}
29+
}
30+
31+
#[inline(never)]
32+
fn called<T>() {
33+
if false {
34+
let v: Vec<T> = Vec::new();
35+
let gen_vtable: &dyn MyTrait = &v; // vtable "appears" here
36+
}
37+
}
38+
39+
pub fn main() {
40+
called::<i32>();
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0080]: evaluation of `Fail::<i32>::C` failed
2+
--> $DIR/interpret-in-const-called-fn.rs:7:19
3+
|
4+
LL | const C: () = panic!();
5+
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/interpret-in-const-called-fn.rs:7: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: erroneous constant encountered
10+
--> $DIR/interpret-in-const-called-fn.rs:16:9
11+
|
12+
LL | Fail::<T>::C;
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)