From 3ef863bfdfb9173a0ad55d24e20202948dda6bbe Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 2 Jul 2018 19:00:07 +0200 Subject: Place unions, pointer casts and pointer derefs behind extra feature gates --- src/test/ui/error-codes/E0396-fixed.rs | 19 +++++++++++++++++++ src/test/ui/error-codes/E0396-fixed.stderr | 12 ++++++++++++ src/test/ui/error-codes/E0396.rs | 3 ++- src/test/ui/error-codes/E0396.stderr | 10 ++++++---- 4 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 src/test/ui/error-codes/E0396-fixed.rs create mode 100644 src/test/ui/error-codes/E0396-fixed.stderr (limited to 'src/test/ui/error-codes') diff --git a/src/test/ui/error-codes/E0396-fixed.rs b/src/test/ui/error-codes/E0396-fixed.rs new file mode 100644 index 00000000000..08d20e7850d --- /dev/null +++ b/src/test/ui/error-codes/E0396-fixed.rs @@ -0,0 +1,19 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(const_raw_ptr_deref)] + +const REG_ADDR: *const u8 = 0x5f3759df as *const u8; + +const VALUE: u8 = unsafe { *REG_ADDR }; +//~^ ERROR this constant cannot be used + +fn main() { +} diff --git a/src/test/ui/error-codes/E0396-fixed.stderr b/src/test/ui/error-codes/E0396-fixed.stderr new file mode 100644 index 00000000000..7d3c98c8ea8 --- /dev/null +++ b/src/test/ui/error-codes/E0396-fixed.stderr @@ -0,0 +1,12 @@ +error: this constant cannot be used + --> $DIR/E0396-fixed.rs:15:1 + | +LL | const VALUE: u8 = unsafe { *REG_ADDR }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^---------^^^ + | | + | a memory access tried to interpret some bytes as a pointer + | + = note: #[deny(const_err)] on by default + +error: aborting due to previous error + diff --git a/src/test/ui/error-codes/E0396.rs b/src/test/ui/error-codes/E0396.rs index 7f34acdfb90..6434620d26a 100644 --- a/src/test/ui/error-codes/E0396.rs +++ b/src/test/ui/error-codes/E0396.rs @@ -10,7 +10,8 @@ const REG_ADDR: *const u8 = 0x5f3759df as *const u8; -const VALUE: u8 = unsafe { *REG_ADDR }; //~ ERROR E0396 +const VALUE: u8 = unsafe { *REG_ADDR }; +//~^ ERROR dereferencing raw pointers in constants is unstable fn main() { } diff --git a/src/test/ui/error-codes/E0396.stderr b/src/test/ui/error-codes/E0396.stderr index 87dfd50dc97..70331acc0e9 100644 --- a/src/test/ui/error-codes/E0396.stderr +++ b/src/test/ui/error-codes/E0396.stderr @@ -1,9 +1,11 @@ -error[E0396]: raw pointers cannot be dereferenced in constants +error[E0658]: dereferencing raw pointers in constants is unstable (see issue #51911) --> $DIR/E0396.rs:13:28 | -LL | const VALUE: u8 = unsafe { *REG_ADDR }; //~ ERROR E0396 - | ^^^^^^^^^ dereference of raw pointer in constant +LL | const VALUE: u8 = unsafe { *REG_ADDR }; + | ^^^^^^^^^ + | + = help: add #![feature(const_raw_ptr_deref)] to the crate attributes to enable error: aborting due to previous error -For more information about this error, try `rustc --explain E0396`. +For more information about this error, try `rustc --explain E0658`. -- cgit 1.4.1-3-g733a5