rust/src/tools
bors 374ce1f909 Auto merge of #136932 - m-ou-se:fmt-width-precision-u16, r=scottmcm
Reduce formatting `width` and `precision` to 16 bits

This is part of https://github.com/rust-lang/rust/issues/99012

This is reduces the `width` and `precision` fields in format strings to 16 bits. They are currently full `usize`s, but it's a bit nonsensical that we need to support the case where someone wants to pad their value to eighteen quintillion spaces and/or have eighteen quintillion digits of precision.

By reducing these fields to 16 bit, we can reduce `FormattingOptions` to 64 bits (see https://github.com/rust-lang/rust/pull/136974) and improve the in memory representation of `format_args!()`. (See additional context below.)

This also fixes a bug where the width or precision is silently truncated when cross-compiling to a target with a smaller `usize`. By reducing the width and precision fields to the minimum guaranteed size of `usize`, 16 bits, this bug is eliminated.

This is a breaking change, but affects almost no existing code.

---

Details of this change:

There are three ways to set a width or precision today:

1. Directly a formatting string, e.g. `println!("{a:1234}")`
2. Indirectly in a formatting string, e.g. `println!("{a:width$}", width=1234)`
3. Through the unstable `FormattingOptions::width` method.

This PR:

- Adds a compiler error for 1. (`println!("{a:9999999}")` no longer compiles and gives a clear error.)
- Adds a runtime check for 2. (`println!("{a:width$}, width=9999999)` will panic.)
- Changes the signatures of the (unstable) `FormattingOptions::[get_]width` methods to use a `u16` instead.

---

Additional context for improving `FormattingOptions` and `fmt::Arguments`:

All the formatting flags and options are currently:

- The `+` flag (1 bit)
- The `-` flag (1 bit)
- The `#` flag (1 bit)
- The `0` flag (1 bit)
- The `x?` flag (1 bit)
- The `X?` flag (1 bit)
- The alignment (2 bits)
- The fill character (21 bits)
- Whether a width is specified (1 bit)
- Whether a precision is specified (1 bit)
- If used, the width (a full usize)
- If used, the precision (a full usize)

Everything except the last two can simply fit in a `u32` (those add up to 31 bits in total).

If we can accept a max width and precision of u16::MAX, we can make a `FormattingOptions` that is exactly 64 bits in size; the same size as a thin reference on most platforms.

If, additionally, we also limit the number of formatting arguments, we can also reduce the size of `fmt::Arguments` (that is, of a `format_args!()` expression).
2025-03-11 04:07:05 +00:00
..
build-manifest Remove i586-pc-windows-msvc 2025-03-03 20:15:25 +01:00
bump-stage0 Update bootstrap compiler and rustfmt 2025-02-08 22:07:11 +00:00
cargo@ab1463d632 Update cargo 2025-03-07 21:47:33 -05:00
cargotest
clippy Rollup merge of #137977 - nnethercote:less-kw-Empty-1, r=spastorino 2025-03-07 19:15:34 +01:00
collect-license-metadata collect-license-metadata: move JSON to root, and add a 'check' mode 2024-11-25 14:14:57 +00:00
compiletest Rollup merge of #137537 - jieyouxu:daily-rmake, r=Kobzol 2025-03-07 21:57:49 -05:00
coverage-dump Rustfmt 2025-02-08 22:12:13 +00:00
enzyme@a35f4f7731 update enzyme to handle range metadata 2025-02-28 03:53:22 -05:00
error_index_generator Move error_index_generator to the rustbook workspace 2025-02-17 10:58:15 -08:00
features-status-dump features-status-dump: add new build-metrics tool 2025-01-26 14:45:05 +08:00
generate-copyright generate-copyright: pass the vendored sources from bootstrap 2025-02-17 11:00:21 +01:00
generate-windows-sys Windows: Update generated bindings to 0.59 2025-02-13 10:32:59 +00:00
html-checker
jsondocck jsondocck: catch and error on deprecated syntax 2025-03-01 10:31:46 +00:00
jsondoclint Rustfmt 2025-02-08 22:12:13 +00:00
libcxx-version
linkchecker Add bstr files to linkchecker since they have a Deref to slice 2025-01-11 06:35:21 +02:00
lint-docs Rustfmt 2025-02-08 22:12:13 +00:00
lld-wrapper
llvm-bitcode-linker Pass through of target features to llvm-bitcode-linker and handling them 2025-02-16 21:57:03 +01:00
miri Move fs into sys 2025-03-08 16:22:37 -08:00
miropt-test-tools Emit error on skip-filecheck test containing filecheck directives 2024-10-19 13:24:07 +00:00
nix-dev-shell chore: fix typos 2024-12-30 14:56:21 +07:00
opt-dist Rollup merge of #137667 - Kobzol:gcc-dist-build, r=onur-ozkan 2025-03-04 14:50:41 -08:00
remote-test-client
remote-test-server
replace-version-placeholder Include rustc and rustdoc book in replace-version-placeholder 2025-01-07 22:46:18 +01:00
rls
run-make-support Don't link against advapi32, except on win7. 2025-03-08 10:55:47 -05:00
rust-analyzer Auto merge of #136932 - m-ou-se:fmt-width-precision-u16, r=scottmcm 2025-03-11 04:07:05 +00:00
rust-installer Rustfmt 2025-02-08 22:12:13 +00:00
rustbook Move error_index_generator to the rustbook workspace 2025-02-17 10:58:15 -08:00
rustc-perf@e22e08623a bump rustc-perf 2025-01-09 16:56:50 +00:00
rustdoc librustdoc: 2024 edition! 🎊 2025-03-04 12:35:18 +02:00
rustdoc-gui Update browser-ui-test version to 0.20.2 2025-02-05 17:06:38 +01:00
rustdoc-gui-test move src/tools/build_helper into src/build_helper 2024-11-11 11:19:11 +03:00
rustdoc-js fix error for when results in a rustdoc-js test are in the wrong order 2025-01-16 12:10:38 -06:00
rustdoc-themes
rustfmt Rollup merge of #134797 - spastorino:ergonomic-ref-counting-1, r=nikomatsakis 2025-03-07 19:15:33 +01:00
suggest-tests Fix typos 2024-12-30 21:43:22 +08:00
tidy Auto merge of #138302 - matthiaskrgr:rollup-an2up80, r=matthiaskrgr 2025-03-11 00:55:25 +00:00
tier-check
unicode-table-generator Rustfmt 2025-02-08 22:12:13 +00:00
unstable-book-gen
wasm-component-ld Update the wasm-component-ld tool 2025-01-21 15:22:01 -08:00
x
cherry-pick.sh
publish_toolstate.py Update toolstate maintainers 2025-01-23 09:55:21 -08:00