Skip to content

Commit fee0753

Browse files
committed
Add feature gate checks
1 parent 3ef863b commit fee0753

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

src/test/compile-fail/cast-ptr-to-int-const.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-const_raw_ptr_to_usize_cast
12+
1113
fn main() {
1214
const X: u32 = main as u32; //~ ERROR casting pointers to integers in constants is unstable
1315
const Y: u32 = 0;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(const_fn)]
12+
13+
fn main() {}
14+
15+
union Foo {
16+
u: u32,
17+
i: i32,
18+
}
19+
20+
const unsafe fn foo(u: u32) -> i32 {
21+
Foo { u }.i //~ ERROR unions in const fn are unstable
22+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0658]: unions in const fn are unstable (see issue #51909)
2+
--> $DIR/feature-gate-const_fn_union.rs:21:5
3+
|
4+
LL | Foo { u }.i //~ ERROR unions in const fn are unstable
5+
| ^^^^^^^^^^^
6+
|
7+
= help: add #![feature(const_fn_union)] to the crate attributes to enable
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0658`.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-const_raw_ptr_deref
12+
1113
const REG_ADDR: *const u8 = 0x5f3759df as *const u8;
1214

1315
const VALUE: u8 = unsafe { *REG_ADDR };

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: dereferencing raw pointers in constants is unstable (see issue #51911)
2-
--> $DIR/E0396.rs:13:28
2+
--> $DIR/E0396.rs:15:28
33
|
44
LL | const VALUE: u8 = unsafe { *REG_ADDR };
55
| ^^^^^^^^^

0 commit comments

Comments
 (0)