File: const-mut-refs-crate.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (35 lines) | stat: -rw-r--r-- 1,247 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//@ run-pass
//@ aux-build:const_mut_refs_crate.rs

//! Regression test for https://github.com/rust-lang/rust/issues/79738
//! Show how we are not duplicating allocations anymore. Statics that
//! copy their value from another static used to also duplicate
//! memory behind references.

extern crate const_mut_refs_crate as other;

use other::{
    inner::{INNER_MOD_BAR, INNER_MOD_FOO},
    BAR, FOO,
};

pub static LOCAL_FOO: &'static i32 = &41;
pub static LOCAL_BAR: &'static i32 = LOCAL_FOO;
pub static mut COPY_OF_REMOTE_FOO: &'static mut i32 = unsafe { FOO };

static DOUBLE_REF: &&i32 = &&99;
static ONE_STEP_ABOVE: &i32 = *DOUBLE_REF;
static mut DOUBLE_REF_MUT: &mut &mut i32 = &mut &mut 99;
static mut ONE_STEP_ABOVE_MUT: &mut i32 = unsafe { *DOUBLE_REF_MUT };

pub fn main() {
    unsafe {
        assert_eq!(FOO as *const i32, BAR as *const i32);
        assert_eq!(INNER_MOD_FOO as *const i32, INNER_MOD_BAR as *const i32);
        assert_eq!(LOCAL_FOO as *const i32, LOCAL_BAR as *const i32);
        assert_eq!(*DOUBLE_REF as *const i32, ONE_STEP_ABOVE as *const i32);
        assert_eq!(*DOUBLE_REF_MUT as *mut i32, ONE_STEP_ABOVE_MUT as *mut i32);

        assert_eq!(FOO as *const i32, COPY_OF_REMOTE_FOO as *const i32);
    }
}