File tree Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Expand file tree Collapse file tree 3 files changed +70
-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+ pub static FOO : & ' static i32 = & 42 ;
14+ pub static BAR : & ' static i32 = FOO ;
15+
16+ pub mod inner {
17+ pub static INNER_MOD_FOO : & ' static i32 = & 43 ;
18+ pub static INNER_MOD_BAR : & ' static i32 = INNER_MOD_FOO ;
19+ }
Original file line number Diff line number Diff line change 1+ // run-pass
2+ // aux-build:const_mut_refs_crate.rs
3+
4+ //! Regression test for https://github.com/rust-lang/rust/issues/79738
5+ //! Show how we are duplicationg allocations, even though static items that
6+ //! copy their value from another static should not also be duplicating
7+ //! memory behind references.
8+
9+ extern crate const_mut_refs_crate as other;
10+
11+ use other:: {
12+ inner:: { INNER_MOD_BAR , INNER_MOD_FOO } ,
13+ BAR , FOO ,
14+ } ;
15+
16+ pub static LOCAL_FOO : & ' static i32 = & 41 ;
17+ pub static LOCAL_BAR : & ' static i32 = LOCAL_FOO ;
18+ pub static COPY_OF_REMOTE_FOO : & ' static i32 = FOO ;
19+
20+ static DOUBLE_REF : & & i32 = & & 99 ;
21+ static ONE_STEP_ABOVE : & i32 = * DOUBLE_REF ;
22+
23+ pub fn main ( ) {
24+ assert_eq ! ( FOO as * const i32 , BAR as * const i32 ) ;
25+ assert_eq ! ( INNER_MOD_FOO as * const i32 , INNER_MOD_BAR as * const i32 ) ;
26+ assert_eq ! ( LOCAL_FOO as * const i32 , LOCAL_BAR as * const i32 ) ;
27+ assert_eq ! ( * DOUBLE_REF as * const i32 , ONE_STEP_ABOVE as * const i32 ) ;
28+
29+ // bug!
30+ assert_ne ! ( FOO as * const i32 , COPY_OF_REMOTE_FOO as * const i32 ) ;
31+ }
Original file line number Diff line number Diff line change 1+ // check-pass
2+
3+ use std:: cell:: Cell ;
4+ use std:: ptr:: NonNull ;
5+
6+ struct ChunkFooter {
7+ prev : Cell < NonNull < ChunkFooter > > ,
8+ }
9+
10+ struct EmptyChunkFooter ( ChunkFooter ) ;
11+
12+ unsafe impl Sync for EmptyChunkFooter { }
13+
14+ static EMPTY_CHUNK : EmptyChunkFooter = EmptyChunkFooter ( ChunkFooter {
15+ prev : Cell :: new ( unsafe {
16+ NonNull :: new_unchecked ( & EMPTY_CHUNK as * const EmptyChunkFooter as * mut ChunkFooter )
17+ } ) ,
18+ } ) ;
19+
20+ fn main ( ) { }
You can’t perform that action at this time.
0 commit comments