Skip to content

Commit 717c64e

Browse files
Silence "skipping const checks" if outside a const context
1 parent f3c8eba commit 717c64e

File tree

5 files changed

+6
-30
lines changed

5 files changed

+6
-30
lines changed

src/librustc_mir/transform/qualify_consts.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,9 @@ struct Checker<'a, 'tcx> {
678678
macro_rules! unleash_miri {
679679
($this:expr) => {{
680680
if $this.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you {
681-
$this.tcx.sess.span_warn($this.span, "skipping const checks");
681+
if $this.mode.requires_const_checking() {
682+
$this.tcx.sess.span_warn($this.span, "skipping const checks");
683+
}
682684
return;
683685
}
684686
}}

src/test/ui/consts/miri_unleashed/mutable_references.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ static OH_YES: &mut i32 = &mut 42;
2727

2828
fn main() {
2929
unsafe {
30-
*MEH.x.get() = 99; //~ WARN skipping const checks
31-
//~^ WARN skipping const checks
30+
*MEH.x.get() = 99;
3231
}
3332
*OH_YES = 99; //~ ERROR cannot assign to `*OH_YES`, as `OH_YES` is an immutable static item
34-
//~^ WARN skipping const checks
3533
}

src/test/ui/consts/miri_unleashed/mutable_references.stderr

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,5 @@
1-
warning: skipping const checks
2-
--> $DIR/mutable_references.rs:30:10
3-
|
4-
LL | *MEH.x.get() = 99;
5-
| ^^^^^
6-
7-
warning: skipping const checks
8-
--> $DIR/mutable_references.rs:30:9
9-
|
10-
LL | *MEH.x.get() = 99;
11-
| ^^^^^^^^^^^^^^^^^
12-
13-
warning: skipping const checks
14-
--> $DIR/mutable_references.rs:33:5
15-
|
16-
LL | *OH_YES = 99;
17-
| ^^^^^^^^^^^^
18-
191
error[E0594]: cannot assign to `*OH_YES`, as `OH_YES` is an immutable static item
20-
--> $DIR/mutable_references.rs:33:5
2+
--> $DIR/mutable_references.rs:32:5
213
|
224
LL | *OH_YES = 99;
235
| ^^^^^^^^^^^^ cannot assign

src/test/ui/consts/miri_unleashed/mutable_references_ice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ const MUH: Meh = Meh {
2424

2525
fn main() {
2626
unsafe {
27-
*MUH.x.get() = 99; //~ WARN skipping const checks
27+
*MUH.x.get() = 99;
2828
}
2929
}

src/test/ui/consts/miri_unleashed/mutable_references_ice.stderr

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
warning: skipping const checks
2-
--> $DIR/mutable_references_ice.rs:27:9
3-
|
4-
LL | *MUH.x.get() = 99;
5-
| ^^^^^^^^^^^^^^^^^
6-
71
thread 'rustc' panicked at 'assertion failed: `(left != right)`
82
left: `Const`,
93
right: `Const`: UnsafeCells are not allowed behind references in constants. This should have been prevented statically by const qualification. If this were allowed one would be able to change a constant at one use site and other use sites could observe that mutation.', src/librustc_mir/interpret/intern.rs:LL:CC

0 commit comments

Comments
 (0)