Skip to content

Commit f759c23

Browse files
authored
Rollup merge of rust-lang#120970 - RalfJung:static-promoted-test, r=oli-obk
add another test for promoteds-in-static rust-lang#119614 led to validation of promoteds recursing into statics. These statics can point to `static mut` and interior mutable `static` and do other things we don't allow in `const`, but promoteds are validated as `const`, so we get strange errors (saying "in `const`" when there is no const) and surprising validation failures. rust-lang#120960 fixes that; this here adds another test. r? ``@oli-obk`` Fixes rust-lang#120968
2 parents 7075502 + a313ffb commit f759c23

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// check-pass
2+
#![allow(non_camel_case_types, non_upper_case_globals, static_mut_ref)]
3+
4+
pub struct wl_interface {
5+
pub version: i32
6+
}
7+
8+
pub struct Interface {
9+
pub other_interfaces: &'static [&'static Interface],
10+
pub c_ptr: Option<&'static wl_interface>,
11+
}
12+
13+
pub static mut wl_callback_interface: wl_interface = wl_interface {
14+
version: 0,
15+
};
16+
17+
pub static WL_CALLBACK_INTERFACE: Interface = Interface {
18+
other_interfaces: &[],
19+
c_ptr: Some(unsafe { &wl_callback_interface }),
20+
};
21+
22+
// This static contains a promoted that points to a static that points to a mutable static.
23+
pub static WL_SURFACE_INTERFACE: Interface = Interface {
24+
other_interfaces: &[&WL_CALLBACK_INTERFACE],
25+
c_ptr: None,
26+
};
27+
28+
// And another variant of the same thing, this time with interior mutability.
29+
use std::sync::OnceLock;
30+
static LAZY_INIT: OnceLock<u32> = OnceLock::new();
31+
static LAZY_INIT_REF: &[&OnceLock<u32>] = &[&LAZY_INIT];
32+
33+
fn main() {}

0 commit comments

Comments
 (0)