Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
bf62d59
Give `TRACK_DIAGNOSTIC` a return value.
nnethercote Feb 9, 2024
ecd3718
Inline and remove `Level::get_diagnostic_id`.
nnethercote Feb 13, 2024
272e60b
Move `DelayedBug` handling into the `match`.
nnethercote Feb 13, 2024
c81767e
Reorder `has_future_breakage` handling.
nnethercote Feb 13, 2024
aec4bdb
Move `Expect`/`ForceWarning` handling into the `match`.
nnethercote Feb 13, 2024
a7d9262
Add comments about `TRACK_DIAGNOSTIC` use.
nnethercote Feb 13, 2024
7ef605b
Make the `match` in `emit_diagnostic` complete.
nnethercote Mar 1, 2024
2d48a3a
Move generic `NonZero` `rustc_layout_scalar_valid_range_start` attrib…
reitermarkus Mar 2, 2024
85dfb47
Fix lint.
reitermarkus Mar 2, 2024
b5c11d1
Fix `miri` tests.
reitermarkus Mar 2, 2024
0b3a8a0
Hide implementation details for `NonZero` auto traits.
reitermarkus Mar 2, 2024
31fef34
Fix lint.
reitermarkus Mar 6, 2024
52fc093
Try fixing `debuginfo` test.
reitermarkus Mar 9, 2024
17924a0
Fix `StdNonZeroNumberSummaryProvider`.
reitermarkus Mar 10, 2024
5aeae7f
Deduplicate `lldb_commands`.
reitermarkus Mar 10, 2024
ec75906
Remove LLDB persistent results in `compiletest`.
reitermarkus Mar 10, 2024
e02cc56
Add comment about `NonZero` printing as character literal.
reitermarkus Mar 10, 2024
781ce7c
Fix `StdNonZeroNumberProvider` for `gdb`.
reitermarkus Mar 10, 2024
15b71f4
Add CStr::bytes iterator
clarfonthey Nov 13, 2022
c076509
Add methods to create constants
celinval Mar 1, 2024
893a910
Add a test to SMIR body transformation
celinval Mar 12, 2024
a38a556
Reduce unsafe code, use more NonNull APIs per @cuviper review
clarfonthey Mar 12, 2024
f2fcfe8
Various style improvements to `rustc_lint::levels`
Zalathar Mar 13, 2024
bf71825
CFI: Break tests into smaller files
rcvalle Mar 12, 2024
90acda1
Fix accidental re-addition of removed code in a previous PR
oli-obk Mar 13, 2024
f10ebfe
Generalize `eval_in_interpreter` with a helper trait
oli-obk Mar 11, 2024
44b1f8a
Move only usage of `take_static_root_alloc` to its definition and inl…
oli-obk Mar 11, 2024
31fa142
Move error handling into const_validate_mplace
oli-obk Mar 11, 2024
71ef9e2
Move InterpCx into eval_in_interpreter
oli-obk Mar 11, 2024
bd7580b
Move generate_stacktrace_from_stack away from InterpCx to avoid havin…
oli-obk Mar 11, 2024
7aee665
Directly pass in the stack instead of computing it from a machine
oli-obk Mar 11, 2024
ffaf082
Remove an argument that can be computed cheaply
oli-obk Mar 12, 2024
66a46bb
Share the `InterpCx` creation between static and const evaluation
oli-obk Mar 12, 2024
af59eec
Move validation into eval_body_using_ecx
oli-obk Mar 12, 2024
2a1a6fa
Move the entire success path into `eval_body_using_ecx`
oli-obk Mar 12, 2024
3393227
Rename some things around validation error reporting to signal that i…
oli-obk Mar 13, 2024
b6312eb
Create some minimal HIR for associated opaque types
petrochenkov Feb 11, 2024
12cd322
Make incremental sessions identity no longer depend on the crate name…
Zoxc Feb 28, 2024
514b274
const-eval: organize and extend tests for required-consts
RalfJung Mar 13, 2024
9403eb4
Rollup merge of #104353 - clarfonthey:cstr-bytes-iter, r=cuviper
matthiaskrgr Mar 13, 2024
5bf23d9
Rollup merge of #120699 - nnethercote:rm-useless-TRACK_DIAGNOSTIC-cal…
matthiaskrgr Mar 13, 2024
de9163a
Rollup merge of #120943 - petrochenkov:somehir3, r=oli-obk
matthiaskrgr Mar 13, 2024
6948dc6
Rollup merge of #121764 - Zoxc:incr-sess-no-source, r=oli-obk
matthiaskrgr Mar 13, 2024
c996d95
Rollup merge of #121885 - reitermarkus:generic-nonzero-inner, r=oli-o…
matthiaskrgr Mar 13, 2024
2a8600e
Rollup merge of #122375 - rcvalle:rust-cfi-break-tests-into-smaller-f…
matthiaskrgr Mar 13, 2024
2d61416
Rollup merge of #122397 - oli-obk:machine-read-hook2, r=RalfJung
matthiaskrgr Mar 13, 2024
e4f4e9a
Rollup merge of #122405 - celinval:smir-new-const, r=oli-obk
matthiaskrgr Mar 13, 2024
7325c2f
Rollup merge of #122416 - Zalathar:levels, r=petrochenkov
matthiaskrgr Mar 13, 2024
e8c661e
Rollup merge of #122440 - RalfJung:required-consts, r=oli-obk
matthiaskrgr Mar 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
const-eval: organize and extend tests for required-consts
  • Loading branch information
RalfJung committed Mar 13, 2024
commit 514b2745b35ecc8c8c0b8ec8c12bde3fa48cb464
15 changes: 0 additions & 15 deletions tests/ui/consts/const-eval/erroneous-const.stderr

This file was deleted.

19 changes: 0 additions & 19 deletions tests/ui/consts/const-eval/erroneous-const2.rs

This file was deleted.

15 changes: 0 additions & 15 deletions tests/ui/consts/const-eval/erroneous-const2.stderr

This file was deleted.

11 changes: 0 additions & 11 deletions tests/ui/consts/const-eval/unused-broken-const-late.stderr

This file was deleted.

17 changes: 17 additions & 0 deletions tests/ui/consts/required-consts/collect-in-called-fn.noopt.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0080]: evaluation of `Fail::<i32>::C` failed
--> $DIR/collect-in-called-fn.rs:9:19
|
LL | const C: () = panic!();
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-called-fn.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: the above error was encountered while instantiating `fn called::<i32>`
--> $DIR/collect-in-called-fn.rs:23:5
|
LL | called::<i32>();
| ^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0080`.
17 changes: 17 additions & 0 deletions tests/ui/consts/required-consts/collect-in-called-fn.opt.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0080]: evaluation of `Fail::<i32>::C` failed
--> $DIR/collect-in-called-fn.rs:9:19
|
LL | const C: () = panic!();
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-called-fn.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: the above error was encountered while instantiating `fn called::<i32>`
--> $DIR/collect-in-called-fn.rs:23:5
|
LL | called::<i32>();
| ^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0080`.
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
//@revisions: noopt opt
//@ build-fail
//@ compile-flags: -O
//@[opt] compile-flags: -O
//! Make sure we detect erroneous constants post-monomorphization even when they are unused. This is
//! crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090)

struct PrintName<T>(T);
impl<T> PrintName<T> {
const VOID: () = panic!(); //~ERROR evaluation of `PrintName::<i32>::VOID` failed
struct Fail<T>(T);
impl<T> Fail<T> {
const C: () = panic!(); //~ERROR evaluation of `Fail::<i32>::C` failed
}

fn no_codegen<T>() {
#[inline(never)]
fn called<T>() {
// Any function that is called is guaranteed to have all consts that syntactically
// appear in its body evaluated, even if they only appear in dead code.
// This relies on mono-item collection checking `required_consts` in collected functions.
if false {
let _ = PrintName::<T>::VOID;
let _ = Fail::<T>::C;
}
}

pub fn main() {
no_codegen::<i32>();
called::<i32>();
}
14 changes: 14 additions & 0 deletions tests/ui/consts/required-consts/collect-in-dead-drop.noopt.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0080]: evaluation of `Fail::<i32>::C` failed
--> $DIR/collect-in-dead-drop.rs:12:19
|
LL | const C: () = panic!();
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-drop.rs:12: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: the above error was encountered while instantiating `fn <Fail<i32> as std::ops::Drop>::drop`
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0080`.
33 changes: 33 additions & 0 deletions tests/ui/consts/required-consts/collect-in-dead-drop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//@revisions: noopt opt
//@[noopt] build-fail
//@[opt] compile-flags: -O
//FIXME: `opt` revision currently does not stop with an error due to
//<https://github.com/rust-lang/rust/issues/107503>.
//@[opt] build-pass
//! Make sure we detect erroneous constants post-monomorphization even when they are unused. This is
//! crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090)

struct Fail<T>(T);
impl<T> Fail<T> {
const C: () = panic!(); //[noopt]~ERROR evaluation of `Fail::<i32>::C` failed
}

// This function is not actually called, but is mentioned implicitly as destructor in dead code in a
// function that is called. Make sure we still find this error.
impl<T> Drop for Fail<T> {
fn drop(&mut self) {
let _ = Fail::<T>::C;
}
}

#[inline(never)]
fn called<T>(x: T) {
if false {
let v = Fail(x);
// Now it gest dropped implicitly, at the end of this scope.
}
}

pub fn main() {
called::<i32>(0);
}
17 changes: 17 additions & 0 deletions tests/ui/consts/required-consts/collect-in-dead-fn.noopt.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0080]: evaluation of `Fail::<i32>::C` failed
--> $DIR/collect-in-dead-fn.rs:12:19
|
LL | const C: () = panic!();
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-fn.rs:12: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: the above error was encountered while instantiating `fn not_called::<i32>`
--> $DIR/collect-in-dead-fn.rs:29:9
|
LL | not_called::<T>();
| ^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0080`.
35 changes: 35 additions & 0 deletions tests/ui/consts/required-consts/collect-in-dead-fn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//@revisions: noopt opt
//@[noopt] build-fail
//@[opt] compile-flags: -O
//FIXME: `opt` revision currently does not stop with an error due to
//<https://github.com/rust-lang/rust/issues/107503>.
//@[opt] build-pass
//! Make sure we detect erroneous constants post-monomorphization even when they are unused. This is
//! crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090)

struct Fail<T>(T);
impl<T> Fail<T> {
const C: () = panic!(); //[noopt]~ERROR evaluation of `Fail::<i32>::C` failed
}

// This function is not actually called, but it is mentioned in dead code in a function that is
// called. Make sure we still find this error.
// This relies on mono-item collection checking `required_consts` in functions that syntactically
// are called in collected functions (even inside dead code).
#[inline(never)]
fn not_called<T>() {
if false {
let _ = Fail::<T>::C;
}
}

#[inline(never)]
fn called<T>() {
if false {
not_called::<T>();
}
}

pub fn main() {
called::<i32>();
}
32 changes: 32 additions & 0 deletions tests/ui/consts/required-consts/collect-in-dead-forget.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//@revisions: noopt opt
//@build-pass
//@[opt] compile-flags: -O
//! Make sure we detect erroneous constants post-monomorphization even when they are unused. This is
//! crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090)

struct Fail<T>(T);
impl<T> Fail<T> {
const C: () = panic!();
}

// This function is not actually called, but is mentioned implicitly as destructor in dead code in a
// function that is called. Make sure we still find this error.
impl<T> Drop for Fail<T> {
fn drop(&mut self) {
let _ = Fail::<T>::C;
}
}

#[inline(never)]
fn called<T>(x: T) {
if false {
let v = Fail(x);
std::mem::forget(v);
// Now the destructor never gets "mentioned" so this build should *not* fail.
// IOW, this demonstrates that we are using a post-drop-elab notion of "mentioned".
}
}

pub fn main() {
called::<i32>(0);
}
14 changes: 14 additions & 0 deletions tests/ui/consts/required-consts/collect-in-dead-move.noopt.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0080]: evaluation of `Fail::<i32>::C` failed
--> $DIR/collect-in-dead-move.rs:12:19
|
LL | const C: () = panic!();
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-move.rs:12: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: the above error was encountered while instantiating `fn <Fail<i32> as std::ops::Drop>::drop`
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0080`.
33 changes: 33 additions & 0 deletions tests/ui/consts/required-consts/collect-in-dead-move.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//@revisions: noopt opt
//@[noopt] build-fail
//@[opt] compile-flags: -O
//FIXME: `opt` revision currently does not stop with an error due to
//<https://github.com/rust-lang/rust/issues/107503>.
//@[opt] build-pass
//! Make sure we detect erroneous constants post-monomorphization even when they are unused. This is
//! crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090)

struct Fail<T>(T);
impl<T> Fail<T> {
const C: () = panic!(); //[noopt]~ERROR evaluation of `Fail::<i32>::C` failed
}

// This function is not actually called, but is mentioned implicitly as destructor in dead code in a
// function that is called. Make sure we still find this error.
impl<T> Drop for Fail<T> {
fn drop(&mut self) {
let _ = Fail::<T>::C;
}
}

#[inline(never)]
fn called<T>(x: T) {
if false {
let v = Fail(x);
drop(v); // move `v` away (and it then gets dropped there so build still fails)
}
}

pub fn main() {
called::<i32>(0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0080]: evaluation of `Fail::<i32>::C` failed
--> $DIR/collect-in-dead-vtable.rs:12:19
|
LL | const C: () = panic!();
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/collect-in-dead-vtable.rs:12: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: the above error was encountered while instantiating `fn <std::vec::Vec<i32> as MyTrait>::not_called`
--> $DIR/collect-in-dead-vtable.rs:35:40
|
LL | let gen_vtable: &dyn MyTrait = &v; // vtable "appears" here
| ^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0080`.
41 changes: 41 additions & 0 deletions tests/ui/consts/required-consts/collect-in-dead-vtable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//@revisions: noopt opt
//@[noopt] build-fail
//@[opt] compile-flags: -O
//FIXME: `opt` revision currently does not stop with an error due to
//<https://github.com/rust-lang/rust/issues/107503>.
//@[opt] build-pass
//! Make sure we detect erroneous constants post-monomorphization even when they are unused. This is
//! crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090)

struct Fail<T>(T);
impl<T> Fail<T> {
const C: () = panic!(); //[noopt]~ERROR evaluation of `Fail::<i32>::C` failed
}

trait MyTrait {
fn not_called(&self);
}

// This function is not actually called, but it is mentioned in a vtable in a function that is
// called. Make sure we still find this error.
// This relies on mono-item collection checking `required_consts` in functions that are referenced
// in vtables that syntactically appear in collected functions (even inside dead code).
impl<T> MyTrait for Vec<T> {
fn not_called(&self) {
if false {
let _ = Fail::<T>::C;
}
}
}

#[inline(never)]
fn called<T>() {
if false {
let v: Vec<T> = Vec::new();
let gen_vtable: &dyn MyTrait = &v; // vtable "appears" here
}
}

pub fn main() {
called::<i32>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0080]: evaluation of `Fail::<i32>::C` failed
--> $DIR/interpret-in-const-called-fn.rs:7:19
|
LL | const C: () = panic!();
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/interpret-in-const-called-fn.rs:7: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/interpret-in-const-called-fn.rs:16:9
|
LL | Fail::<T>::C;
| ^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0080`.
Loading