]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/pass/no_std.rs
Auto merge of #104915 - weihanglo:update-cargo, r=ehuss
[rust.git] / src / tools / miri / tests / pass / no_std.rs
1 #![feature(lang_items, start)]
2 #![no_std]
3
4 // Plumbing to let us use `writeln!` to host stdout:
5
6 extern "Rust" {
7     fn miri_write_to_stdout(bytes: &[u8]);
8 }
9
10 struct Host;
11
12 use core::fmt::Write;
13
14 impl Write for Host {
15     fn write_str(&mut self, s: &str) -> core::fmt::Result {
16         unsafe {
17             miri_write_to_stdout(s.as_bytes());
18         }
19         Ok(())
20     }
21 }
22
23 // Aaaand the test:
24
25 #[start]
26 fn start(_: isize, _: *const *const u8) -> isize {
27     writeln!(Host, "hello, world!").unwrap();
28     0
29 }
30
31 #[panic_handler]
32 fn panic_handler(_: &core::panic::PanicInfo) -> ! {
33     loop {}
34 }
35
36 #[lang = "eh_personality"]
37 fn eh_personality() {}