Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

miri-unleashed: test that we detect heap allocations #71276

Merged
merged 2 commits into from
Apr 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/check_consts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::fmt;

pub use self::qualifs::Qualif;

pub mod ops;
mod ops;
pub mod qualifs;
mod resolver;
pub mod validation;
Expand Down
2 changes: 0 additions & 2 deletions src/librustc_mir/transform/check_consts/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ impl NonConstOp for FnCallUnstable {
#[derive(Debug)]
pub struct HeapAllocation;
impl NonConstOp for HeapAllocation {
const IS_SUPPORTED_IN_MIRI: bool = false;

fn emit_error(&self, item: &Item<'_, '_>, span: Span) {
let mut err = struct_span_err!(
item.tcx.sess,
Expand Down
14 changes: 14 additions & 0 deletions src/test/ui/consts/miri_unleashed/box.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// compile-flags: -Zunleash-the-miri-inside-of-you
#![feature(const_mut_refs, box_syntax)]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was quite surprised that I had to add const_mut_refs here, given that I unleashed miri. Is that expected?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. That was an explicit choice:

// If an operation is supported in miri (and is not already controlled by a feature gate) it
// can be turned on with `-Zunleash-the-miri-inside-of-you`.
let is_unleashable = O::IS_SUPPORTED_IN_MIRI && O::feature_gate().is_none();

#![deny(const_err)]

use std::mem::ManuallyDrop;

fn main() {}

static TEST_BAD: &mut i32 = {
&mut *(box 0)
//~^ WARN skipping const check
//~| ERROR could not evaluate static initializer
//~| NOTE heap allocations
};
15 changes: 15 additions & 0 deletions src/test/ui/consts/miri_unleashed/box.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
warning: skipping const checks
--> $DIR/box.rs:10:11
|
LL | &mut *(box 0)
| ^^^^^^^

error[E0080]: could not evaluate static initializer
--> $DIR/box.rs:10:11
|
LL | &mut *(box 0)
| ^^^^^^^ "heap allocations via `box` keyword" needs an rfc before being allowed inside constants

error: aborting due to previous error; 1 warning emitted

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