]> git.lizzy.rs Git - rust.git/blob - tests/ui/statics/static-promotion.rs
Rollup merge of #106397 - compiler-errors:new-solver-impl-wc, r=lcnr
[rust.git] / tests / ui / statics / static-promotion.rs
1 // run-pass
2
3 // Use of global static variables in literal values should be allowed for
4 // promotion.
5 // This test is to demonstrate the issue raised in
6 // https://github.com/rust-lang/rust/issues/70584
7
8 // Literal values were previously promoted into local static values when
9 // other global static variables are used.
10
11 struct A<T: 'static>(&'static T);
12 struct B<T: 'static + ?Sized> {
13     x: &'static T,
14 }
15 static STR: &'static [u8] = b"hi";
16 static C: A<B<B<[u8]>>> = {
17     A(&B {
18         x: &B { x: STR },
19     })
20 };
21
22 pub struct Slice(&'static [i32]);
23
24 static CONTENT: i32 = 42;
25 pub static CONTENT_MAP: Slice = Slice(&[CONTENT]);
26
27 pub static FOO: (i32, i32) = (42, 43);
28 pub static CONTENT_MAP2: Slice = Slice(&[FOO.0]);
29
30 fn main() {
31     assert_eq!(b"hi", C.0.x.x);
32     assert_eq!(&[42], CONTENT_MAP.0);
33     assert_eq!(&[42], CONTENT_MAP2.0);
34 }