]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/pass/no_std.rs
Rollup merge of #103456 - scottmcm:fix-unchecked-shifts, r=scottmcm
[rust.git] / src / tools / miri / tests / pass / no_std.rs
1 #![feature(lang_items, start)]
2 #![no_std]
3 // windows tls dtors go through libstd right now, thus this test
4 // cannot pass. When windows tls dtors go through the special magic
5 // windows linker section, we can run this test on windows again.
6 //@ignore-target-windows: no-std not supported on Windows
7
8 // Plumbing to let us use `writeln!` to host stdout:
9
10 extern "Rust" {
11     fn miri_write_to_stdout(bytes: &[u8]);
12 }
13
14 struct Host;
15
16 use core::fmt::Write;
17
18 impl Write for Host {
19     fn write_str(&mut self, s: &str) -> core::fmt::Result {
20         unsafe {
21             miri_write_to_stdout(s.as_bytes());
22         }
23         Ok(())
24     }
25 }
26
27 // Aaaand the test:
28
29 #[start]
30 fn start(_: isize, _: *const *const u8) -> isize {
31     writeln!(Host, "hello, world!").unwrap();
32     0
33 }
34
35 #[panic_handler]
36 fn panic_handler(_: &core::panic::PanicInfo) -> ! {
37     loop {}
38 }
39
40 #[lang = "eh_personality"]
41 fn eh_personality() {}