|
| 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 | +// New test for #53818: modifying static memory at compile-time is not allowed. |
| 12 | +// The test should never succeed. |
| 13 | + |
| 14 | +#![feature(const_raw_ptr_deref)] |
| 15 | +#![feature(const_let)] |
| 16 | + |
| 17 | +use std::cell::UnsafeCell; |
| 18 | + |
| 19 | +struct Foo(UnsafeCell<u32>); |
| 20 | + |
| 21 | +unsafe impl Send for Foo {} |
| 22 | +unsafe impl Sync for Foo {} |
| 23 | + |
| 24 | +static FOO: Foo = Foo(UnsafeCell::new(42)); |
| 25 | + |
| 26 | +static BAR: () = unsafe { |
| 27 | + *FOO.0.get() = 5; |
| 28 | + //~^ ERROR calls in statics are limited to constant functions, tuple structs and tuple variants |
| 29 | + |
| 30 | + // This error is caused by a separate bug that the feature gate error is reported |
| 31 | + // even though the feature gate "const_let" is active. |
| 32 | + //~| statements in statics are unstable (see issue #48821) |
| 33 | +}; |
| 34 | + |
| 35 | +fn main() { |
| 36 | + println!("{}", unsafe { *FOO.0.get() }); |
| 37 | +} |
0 commit comments