This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ // This is a support file for ../const-mut-refs-crate.rs
2+
3+ // This is to test that static inners from an external
4+ // crate like this one, still preserves the alloc.
5+ // That is, the address from the standpoint of rustc+llvm
6+ // is the same.
7+ // The need for this test originated from the GH issue
8+ // https://github.com/rust-lang/rust/issues/57349
9+
10+ // See also ../const-mut-refs-crate.rs for more details
11+ // about this test.
12+
13+ #![ feature( const_mut_refs) ]
14+
15+ // if we used immutable references here, then promotion would
16+ // turn the `&42` into a promoted, which gets duplicated arbitrarily.
17+ pub static mut FOO : & ' static mut i32 = & mut 42 ;
18+ pub static mut BAR : & ' static mut i32 = unsafe { FOO } ;
19+
20+ pub mod inner {
21+ pub static INNER_MOD_FOO : & ' static i32 = & 43 ;
22+ pub static INNER_MOD_BAR : & ' static i32 = INNER_MOD_FOO ;
23+ }
Original file line number Diff line number Diff line change 1+ //@ run-pass
2+ //@ aux-build:const_mut_refs_crate.rs
3+
4+ #![ feature( const_mut_refs) ]
5+
6+ //! Regression test for https://github.com/rust-lang/rust/issues/79738
7+ //! Show how we are duplicationg allocations, even though static items that
8+ //! copy their value from another static should not also be duplicating
9+ //! memory behind references.
10+
11+ extern crate const_mut_refs_crate as other;
12+
13+ use other:: {
14+ inner:: { INNER_MOD_BAR , INNER_MOD_FOO } ,
15+ BAR , FOO ,
16+ } ;
17+
18+ pub static LOCAL_FOO : & ' static i32 = & 41 ;
19+ pub static LOCAL_BAR : & ' static i32 = LOCAL_FOO ;
20+ pub static mut COPY_OF_REMOTE_FOO : & ' static mut i32 = unsafe { FOO } ;
21+
22+ static DOUBLE_REF : & & i32 = & & 99 ;
23+ static ONE_STEP_ABOVE : & i32 = * DOUBLE_REF ;
24+
25+ pub fn main ( ) {
26+ unsafe {
27+ assert_ne ! ( FOO as * const i32 , BAR as * const i32 ) ;
28+ assert_eq ! ( INNER_MOD_FOO as * const i32 , INNER_MOD_BAR as * const i32 ) ;
29+ assert_eq ! ( LOCAL_FOO as * const i32 , LOCAL_BAR as * const i32 ) ;
30+ assert_eq ! ( * DOUBLE_REF as * const i32 , ONE_STEP_ABOVE as * const i32 ) ;
31+
32+ // bug!
33+ assert_ne ! ( FOO as * const i32 , COPY_OF_REMOTE_FOO as * const i32 ) ;
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments