From fee07534bbe192befadb03b1626c2bbf3d6e5cfb Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 2 Jul 2018 19:59:39 +0200 Subject: [PATCH] Add feature gate checks --- .../compile-fail/cast-ptr-to-int-const.rs | 2 ++ .../const-eval/feature-gate-const_fn_union.rs | 22 +++++++++++++++++++ .../feature-gate-const_fn_union.stderr | 11 ++++++++++ src/test/ui/error-codes/E0396.rs | 2 ++ src/test/ui/error-codes/E0396.stderr | 2 +- 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/const-eval/feature-gate-const_fn_union.rs create mode 100644 src/test/ui/const-eval/feature-gate-const_fn_union.stderr diff --git a/src/test/compile-fail/cast-ptr-to-int-const.rs b/src/test/compile-fail/cast-ptr-to-int-const.rs index 30f94e1b5da..8764cb72b8c 100644 --- a/src/test/compile-fail/cast-ptr-to-int-const.rs +++ b/src/test/compile-fail/cast-ptr-to-int-const.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// gate-test-const_raw_ptr_to_usize_cast + fn main() { const X: u32 = main as u32; //~ ERROR casting pointers to integers in constants is unstable const Y: u32 = 0; diff --git a/src/test/ui/const-eval/feature-gate-const_fn_union.rs b/src/test/ui/const-eval/feature-gate-const_fn_union.rs new file mode 100644 index 00000000000..113046b0689 --- /dev/null +++ b/src/test/ui/const-eval/feature-gate-const_fn_union.rs @@ -0,0 +1,22 @@ +// Copyright 2018 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_fn)] + +fn main() {} + +union Foo { + u: u32, + i: i32, +} + +const unsafe fn foo(u: u32) -> i32 { + Foo { u }.i //~ ERROR unions in const fn are unstable +} diff --git a/src/test/ui/const-eval/feature-gate-const_fn_union.stderr b/src/test/ui/const-eval/feature-gate-const_fn_union.stderr new file mode 100644 index 00000000000..1e28f14165f --- /dev/null +++ b/src/test/ui/const-eval/feature-gate-const_fn_union.stderr @@ -0,0 +1,11 @@ +error[E0658]: unions in const fn are unstable (see issue #51909) + --> $DIR/feature-gate-const_fn_union.rs:21:5 + | +LL | Foo { u }.i //~ ERROR unions in const fn are unstable + | ^^^^^^^^^^^ + | + = help: add #![feature(const_fn_union)] to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/error-codes/E0396.rs b/src/test/ui/error-codes/E0396.rs index 6434620d26a..1ee8a74a465 100644 --- a/src/test/ui/error-codes/E0396.rs +++ b/src/test/ui/error-codes/E0396.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// gate-test-const_raw_ptr_deref + const REG_ADDR: *const u8 = 0x5f3759df as *const u8; const VALUE: u8 = unsafe { *REG_ADDR }; diff --git a/src/test/ui/error-codes/E0396.stderr b/src/test/ui/error-codes/E0396.stderr index 70331acc0e9..a2a2e724358 100644 --- a/src/test/ui/error-codes/E0396.stderr +++ b/src/test/ui/error-codes/E0396.stderr @@ -1,5 +1,5 @@ error[E0658]: dereferencing raw pointers in constants is unstable (see issue #51911) - --> $DIR/E0396.rs:13:28 + --> $DIR/E0396.rs:15:28 | LL | const VALUE: u8 = unsafe { *REG_ADDR }; | ^^^^^^^^^