rust/src/test/run-make
bors cf9bfdb872 Auto merge of #78122 - fusion-engineering-forks:fmt-write-bounds-check, r=Mark-Simulacrum
Avoid panic_bounds_check in fmt::write.

Writing any fmt::Arguments would trigger the inclusion of usize formatting and padding code in the resulting binary, because indexing used in fmt::write would generate code using panic_bounds_check, which prints the index and length.

These bounds checks are not necessary, as fmt::Arguments never contains any out-of-bounds indexes.

This change replaces them with unsafe get_unchecked, to reduce the amount of generated code, which is especially important for embedded targets.

---

Demonstration of the size of and the symbols in a 'hello world' no_std binary:

<details>
<summary>Source code</summary>

```rust
#![feature(lang_items)]
#![feature(start)]
#![no_std]

use core::fmt;
use core::fmt::Write;

#[link(name = "c")]
extern "C" {
    #[allow(improper_ctypes)]
    fn write(fd: i32, s: &str) -> isize;
    fn exit(code: i32) -> !;
}

struct Stdout;

impl fmt::Write for Stdout {
    fn write_str(&mut self, s: &str) -> fmt::Result {
        unsafe { write(1, s) };
        Ok(())
    }
}

#[start]
fn main(_argc: isize, _argv: *const *const u8) -> isize {
    let _ = writeln!(Stdout, "Hello World");
    0
}

#[lang = "eh_personality"]
fn eh_personality() {}

#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
    unsafe { exit(1) };
}
```
</details>

Before:
```
   text	   data	    bss	    dec	    hex	filename
   6059	    736	      8	   6803	   1a93	before
```
```
0000000000001e00 T <T as core::any::Any>::type_id
0000000000003dd0 D core::fmt::num::DEC_DIGITS_LUT
0000000000001ce0 T core::fmt::num:👿:<impl core::fmt::Display for u64>::fmt
0000000000001ce0 T core::fmt::num:👿:<impl core::fmt::Display for usize>::fmt
0000000000001370 T core::fmt::write
0000000000001b30 t core::fmt::Formatter::pad_integral::write_prefix
0000000000001660 T core::fmt::Formatter::pad_integral
0000000000001350 T core::ops::function::FnOnce::call_once
0000000000001b80 t core::ptr::drop_in_place
0000000000001120 t core::ptr::drop_in_place
0000000000001c50 t core::iter::adapters::zip::Zip<A,B>::new
0000000000001c90 t core::iter::adapters::zip::Zip<A,B>::new
0000000000001b90 T core::panicking::panic_bounds_check
0000000000001c10 T core::panicking::panic_fmt
0000000000001130 t <&mut W as core::fmt::Write>::write_char
0000000000001200 t <&mut W as core::fmt::Write>::write_fmt
0000000000001250 t <&mut W as core::fmt::Write>::write_str
```

After:
```
   text	   data	    bss	    dec	    hex	filename
   3068	    600	      8	   3676	    e5c	after
```
```
0000000000001360 T core::fmt::write
0000000000001340 T core::ops::function::FnOnce::call_once
0000000000001120 t core::ptr::drop_in_place
0000000000001620 t core::iter::adapters::zip::Zip<A,B>::new
0000000000001660 t core::iter::adapters::zip::Zip<A,B>::new
0000000000001130 t <&mut W as core::fmt::Write>::write_char
0000000000001200 t <&mut W as core::fmt::Write>::write_fmt
0000000000001250 t <&mut W as core::fmt::Write>::write_str
```
2020-11-29 23:14:40 +00:00
..
env-dep-info proc_macro: Add API for tracked access to environment variables 2020-07-26 13:37:37 +03:00
fmt-write-bloat Add test to check for fmt::write bloat. 2020-11-29 11:38:51 +01:00
incr-prev-body-beyond-eof incr-comp: add ignore-32bit directive to incr-prev-body-beyond-eof test 2020-11-09 14:08:52 -08:00
issue-36710 incr-comp: add ignore-32bit directive to incr-prev-body-beyond-eof test 2020-11-09 14:08:52 -08:00
llvm-outputs add test for issue #21335 2018-11-26 12:41:43 -05:00
rustc-macro-dep-files expand: Stop using nonterminals for passing tokens to attribute and derive macros 2020-07-01 13:13:21 +03:00
static-pie Fix src/test/run-make/static-pie/test-aslr.rs 2020-07-13 11:33:03 +02:00
thumb-none-cortex-m Provide bootstrap tools with RUSTC in environment 2020-09-20 16:39:13 -04:00
thumb-none-qemu fix shellcheck error of SC2148 2020-11-06 20:33:12 +09:00
wasm-custom-section Upgrade Emscripten targets to use upstream LLVM backend 2019-10-16 17:06:48 -07:00
wasm-custom-sections-opt Upgrade Emscripten targets to use upstream LLVM backend 2019-10-16 17:06:48 -07:00
wasm-export-all-symbols Check for the entry kind 2020-01-08 10:05:44 +01:00
wasm-import-module Upgrade Emscripten targets to use upstream LLVM backend 2019-10-16 17:06:48 -07:00
wasm-panic-small Use Cell::take in a couple places 2020-04-26 11:50:53 +02:00
wasm-stringify-ints-small Change opt-level from 2 back to 3 2020-01-30 15:40:14 -05:00
wasm-symbols-different-module Fix handling of wasm import modules and names 2019-12-16 14:43:46 -08:00
wasm-symbols-not-exported Upgrade Emscripten targets to use upstream LLVM backend 2019-10-16 17:06:48 -07:00
wasm-symbols-not-imported Upgrade Emscripten targets to use upstream LLVM backend 2019-10-16 17:06:48 -07:00
x86_64-fortanix-unknown-sgx-lvi fix shellcheck error of SC2148 2020-11-06 20:33:12 +09:00
git_clone_sha1.sh Remove licenses 2018-12-25 21:08:33 -07:00