forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatic.rs
112 lines (89 loc) · 2.02 KB
/
static.rs
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Compiler:
//
// Run-time:
// status: 0
// stdout: 10
// 14
// 1
// 12
// 12
// 1
#![feature(auto_traits, lang_items, no_core, intrinsics, rustc_attrs)]
#![allow(internal_features)]
#![no_std]
#![no_core]
#![no_main]
/*
* Core
*/
// Because we don't have core yet.
#[lang = "sized"]
pub trait Sized {}
#[lang = "destruct"]
pub trait Destruct {}
#[lang = "drop"]
pub trait Drop {}
#[lang = "copy"]
trait Copy {
}
impl Copy for isize {}
impl<T: ?Sized> Copy for *mut T {}
#[lang = "receiver"]
trait Receiver {
}
#[lang = "freeze"]
pub(crate) unsafe auto trait Freeze {}
mod intrinsics {
use super::Sized;
#[rustc_nounwind]
#[rustc_intrinsic]
pub fn abort() -> !;
}
mod libc {
#[link(name = "c")]
extern "C" {
pub fn printf(format: *const i8, ...) -> i32;
}
}
#[lang = "structural_peq"]
pub trait StructuralPartialEq {}
#[lang = "drop_in_place"]
#[allow(unconditional_recursion)]
pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
// Code here does not matter - this is replaced by the
// real drop glue by the compiler.
drop_in_place(to_drop);
}
/*
* Code
*/
struct Test {
field: isize,
}
struct WithRef {
refe: &'static Test,
}
static mut CONSTANT: isize = 10;
static mut TEST: Test = Test {
field: 12,
};
static mut TEST2: Test = Test {
field: 14,
};
static mut WITH_REF: WithRef = WithRef {
refe: unsafe { &TEST },
};
#[no_mangle]
extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
unsafe {
libc::printf(b"%ld\n\0" as *const u8 as *const i8, CONSTANT);
libc::printf(b"%ld\n\0" as *const u8 as *const i8, TEST2.field);
TEST2.field = argc;
libc::printf(b"%ld\n\0" as *const u8 as *const i8, TEST2.field);
libc::printf(b"%ld\n\0" as *const u8 as *const i8, WITH_REF.refe.field);
WITH_REF.refe = &TEST2;
libc::printf(b"%ld\n\0" as *const u8 as *const i8, TEST.field);
libc::printf(b"%ld\n\0" as *const u8 as *const i8, WITH_REF.refe.field);
}
0
}