Skip to content

Commit 1da5780

Browse files
committed
Add test to check for fmt::write bloat.
It checks that fmt::write by itself doesn't pull in any panicking or or display code.
1 parent ea24395 commit 1da5780

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

Diff for: src/test/run-make/fmt-write-bloat/Makefile

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-include ../../run-make-fulldeps/tools.mk
2+
3+
# ignore-windows
4+
5+
ifeq ($(shell $(RUSTC) -vV | grep 'host: $(TARGET)'),)
6+
7+
# Don't run this test when cross compiling.
8+
all:
9+
10+
else
11+
12+
NM = nm
13+
14+
PANIC_SYMS = panic_bounds_check pad_integral Display Debug
15+
16+
# Allow for debug_assert!() in debug builds of std.
17+
ifdef NO_DEBUG_ASSERTIONS
18+
PANIC_SYMS += panicking panic_fmt
19+
endif
20+
21+
all: main.rs
22+
$(RUSTC) $< -O
23+
$(NM) $(call RUN_BINFILE,main) | $(CGREP) -v $(PANIC_SYMS)
24+
25+
endif

Diff for: src/test/run-make/fmt-write-bloat/main.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#![feature(lang_items)]
2+
#![feature(start)]
3+
#![no_std]
4+
5+
use core::fmt;
6+
use core::fmt::Write;
7+
8+
#[link(name = "c")]
9+
extern "C" {}
10+
11+
struct Dummy;
12+
13+
impl fmt::Write for Dummy {
14+
#[inline(never)]
15+
fn write_str(&mut self, _: &str) -> fmt::Result {
16+
Ok(())
17+
}
18+
}
19+
20+
#[start]
21+
fn main(_: isize, _: *const *const u8) -> isize {
22+
let _ = writeln!(Dummy, "Hello World");
23+
0
24+
}
25+
26+
#[lang = "eh_personality"]
27+
fn eh_personality() {}
28+
29+
#[panic_handler]
30+
fn panic(_: &core::panic::PanicInfo) -> ! {
31+
loop {}
32+
}

0 commit comments

Comments
 (0)