Skip to content

Commit 1d679eb

Browse files
amanjeevoli-obk
authored andcommitted
Add some tests
1 parent 340bb19 commit 1d679eb

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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() {}

0 commit comments

Comments
 (0)