Skip to content

Commit f4085f0

Browse files
committed
also const-check FakeRead
1 parent bd2f1cb commit f4085f0

File tree

4 files changed

+40
-7
lines changed

4 files changed

+40
-7
lines changed

compiler/rustc_mir/src/transform/check_consts/validation.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -722,17 +722,16 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
722722
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
723723
trace!("visit_statement: statement={:?} location={:?}", statement, location);
724724

725-
match statement.kind {
726-
StatementKind::Assign(..) | StatementKind::SetDiscriminant { .. } => {
727-
self.super_statement(statement, location);
728-
}
725+
self.super_statement(statement, location);
729726

727+
match statement.kind {
730728
StatementKind::LlvmInlineAsm { .. } => {
731-
self.super_statement(statement, location);
732729
self.check_op(ops::InlineAsm);
733730
}
734731

735-
StatementKind::FakeRead(..)
732+
StatementKind::Assign(..)
733+
| StatementKind::SetDiscriminant { .. }
734+
| StatementKind::FakeRead(..)
736735
| StatementKind::StorageLive(_)
737736
| StatementKind::StorageDead(_)
738737
| StatementKind::Retag { .. }

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

+5
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ help: skipping check that does not even have a feature gate
146146
|
147147
LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
148148
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
149+
help: skipping check that does not even have a feature gate
150+
--> $DIR/const_refers_to_static_cross_crate.rs:32:20
151+
|
152+
LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
153+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
149154
help: skipping check for `const_panic` feature
150155
--> $DIR/const_refers_to_static_cross_crate.rs:32:77
151156
|

src/test/ui/error-codes/E0396.rs

+11
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,16 @@ const REG_ADDR: *const u8 = 0x5f3759df as *const u8;
55
const VALUE: u8 = unsafe { *REG_ADDR };
66
//~^ ERROR dereferencing raw pointers in constants is unstable
77

8+
const unsafe fn unreachable() -> ! {
9+
use std::convert::Infallible;
10+
11+
const INFALLIBLE: *const Infallible = [].as_ptr();
12+
match *INFALLIBLE {}
13+
//~^ ERROR dereferencing raw pointers in constant functions is unstable
14+
15+
const BAD: () = unsafe { match *INFALLIBLE {} };
16+
//~^ ERROR dereferencing raw pointers in constants is unstable
17+
}
18+
819
fn main() {
920
}

src/test/ui/error-codes/E0396.stderr

+19-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ LL | const VALUE: u8 = unsafe { *REG_ADDR };
77
= note: see issue #51911 <https://github.com/rust-lang/rust/issues/51911> for more information
88
= help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
99

10-
error: aborting due to previous error
10+
error[E0658]: dereferencing raw pointers in constant functions is unstable
11+
--> $DIR/E0396.rs:12:11
12+
|
13+
LL | match *INFALLIBLE {}
14+
| ^^^^^^^^^^^
15+
|
16+
= note: see issue #51911 <https://github.com/rust-lang/rust/issues/51911> for more information
17+
= help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
18+
19+
error[E0658]: dereferencing raw pointers in constants is unstable
20+
--> $DIR/E0396.rs:15:36
21+
|
22+
LL | const BAD: () = unsafe { match *INFALLIBLE {} };
23+
| ^^^^^^^^^^^
24+
|
25+
= note: see issue #51911 <https://github.com/rust-lang/rust/issues/51911> for more information
26+
= help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
27+
28+
error: aborting due to 3 previous errors
1129

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

0 commit comments

Comments
 (0)