Place unions, pointer casts and pointer derefs behind extra feature gates
This commit is contained in:
parent
9e472c2ace
commit
3ef863bfdf
20 changed files with 118 additions and 131 deletions
|
|
@ -9,7 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
const X: u32 = main as u32; //~ ERROR E0018
|
||||
const X: u32 = main as u32; //~ ERROR casting pointers to integers in constants is unstable
|
||||
const Y: u32 = 0;
|
||||
const Z: u32 = &Y as *const u32 as u32; //~ ERROR E0018
|
||||
const Z: u32 = &Y as *const u32 as u32; //~ ERROR is unstable
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
// Check that you can't dereference raw pointers in constants.
|
||||
|
||||
fn main() {
|
||||
static C: u64 = unsafe {*(0xdeadbeef as *const u64)}; //~ ERROR E0396
|
||||
static C: u64 = unsafe {*(0xdeadbeef as *const u64)};
|
||||
//~^ ERROR dereferencing raw pointers in statics is unstable
|
||||
println!("{}", C);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
error[E0396]: raw pointers cannot be dereferenced in statics
|
||||
error[E0658]: dereferencing raw pointers in statics is unstable (see issue #51911)
|
||||
--> $DIR/const-deref-ptr.rs:14:29
|
||||
|
|
||||
LL | static C: u64 = unsafe {*(0xdeadbeef as *const u64)}; //~ ERROR E0396
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ dereference of raw pointer in constant
|
||||
LL | static C: u64 = unsafe {*(0xdeadbeef as *const u64)};
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= 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`.
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@
|
|||
// compile-pass
|
||||
// run-pass
|
||||
|
||||
#![feature(const_fn_union)]
|
||||
|
||||
union Transmute<T: Copy, U: Copy> {
|
||||
t: T,
|
||||
u: U,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
// compile-pass
|
||||
|
||||
#![feature(const_fn)]
|
||||
#![feature(const_fn, const_fn_union)]
|
||||
|
||||
#![deny(const_err)]
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
//compile-pass
|
||||
|
||||
#![feature(const_fn_union)]
|
||||
|
||||
fn main() {}
|
||||
|
||||
static FOO: u32 = 42;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(const_fn_union)]
|
||||
|
||||
fn main() {
|
||||
let n: Int = 40;
|
||||
match n {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error[E0030]: lower range bound must be less than or equal to upper
|
||||
--> $DIR/ref_to_int_match.rs:15:9
|
||||
--> $DIR/ref_to_int_match.rs:17:9
|
||||
|
|
||||
LL | 10..=BAR => {}, //~ ERROR lower range bound must be less than or equal to upper
|
||||
| ^^ lower bound larger than upper bound
|
||||
|
|
|
|||
11
src/test/ui/const-eval/union_promotion.nll.stderr
Normal file
11
src/test/ui/const-eval/union_promotion.nll.stderr
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
error: internal compiler error: unexpected region for local data ReStatic
|
||||
--> $DIR/union_promotion.rs:19:29
|
||||
|
|
||||
LL | let x: &'static bool = &unsafe { //~ borrowed value does not live long enough
|
||||
| _____________________________^
|
||||
LL | | Foo { a: &1 }.b == Foo { a: &2 }.b
|
||||
LL | | };
|
||||
| |_____^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
19
src/test/ui/error-codes/E0396-fixed.rs
Normal file
19
src/test/ui/error-codes/E0396-fixed.rs
Normal file
|
|
@ -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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() {
|
||||
}
|
||||
12
src/test/ui/error-codes/E0396-fixed.stderr
Normal file
12
src/test/ui/error-codes/E0396-fixed.stderr
Normal file
|
|
@ -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
|
||||
|
||||
|
|
@ -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() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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`.
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
static X: usize = 0 as *const usize as usize;
|
||||
//~^ ERROR: raw pointers cannot be cast to integers in statics
|
||||
//~^ ERROR: casting pointers to integers in statics is unstable
|
||||
|
||||
fn main() {
|
||||
assert_eq!(X, 0);
|
||||
|
|
|
|||
|
|
@ -10,6 +10,6 @@
|
|||
|
||||
fn main() {
|
||||
const X: u32 = 1;
|
||||
const Y: usize = &X as *const u32 as usize; //~ ERROR E0018
|
||||
const Y: usize = &X as *const u32 as usize; //~ ERROR is unstable
|
||||
println!("{}", Y);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
// compile-pass
|
||||
#![feature(const_fn_union)]
|
||||
|
||||
union U {
|
||||
a: usize,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue