rust/library/core/src
bors 1203e0866e Auto merge of #106824 - m-ou-se:format-args-flatten, r=oli-obk
Flatten/inline format_args!() and (string and int) literal arguments into format_args!()

Implements https://github.com/rust-lang/rust/issues/78356

Gated behind `-Zflatten-format-args=yes`.

Part of #99012

This change inlines string literals, integer literals and nested format_args!() into format_args!() during ast lowering, making all of the following pairs result in equivalent hir:

```rust
println!("Hello, {}!", "World");
println!("Hello, World!");
```

```rust
println!("[info] {}", format_args!("error"));
println!("[info] error");
```

```rust
println!("[{}] {}", status, format_args!("error: {}", msg));
println!("[{}] error: {}", status, msg);
```

```rust
println!("{} + {} = {}", 1, 2, 1 + 2);
println!("1 + 2 = {}", 1 + 2);
```

And so on.

This is useful for macros. E.g. a `log::info!()` macro could just pass the tokens from the user directly into a `format_args!()` that gets efficiently flattened/inlined into a `format_args!("info: {}")`.

It also means that `dbg!(x)` will have its file, line, and expression name inlined:

```rust
eprintln!("[{}:{}] {} = {:#?}", file!(), line!(), stringify!(x), x); // before
eprintln!("[example.rs:1] x = {:#?}", x); // after
```

Which can be nice in some cases, but also means a lot more unique static strings than before if dbg!() is used a lot.
2023-03-16 13:46:52 +00:00
..
alloc Clarify new_size for realloc means bytes 2023-02-09 23:56:20 -08:00
array Merge two different equality specialization traits in core 2023-03-01 14:42:06 -08:00
async_iter use consistent terminology 2022-10-29 09:23:12 +02:00
cell Add OnceCell<T>: !Sync impl for diagnostics 2023-01-19 20:14:21 +01:00
char Auto merge of #105671 - lukas-code:depreciate-char, r=scottmcm 2023-02-12 11:09:06 +00:00
cmp Merge two different equality specialization traits in core 2023-03-01 14:42:06 -08:00
convert Add examples section which demonstrates the behaviour (specifically the sign positive aspect) 2023-03-09 20:44:11 +00:00
ffi Auto merge of #106673 - flba-eb:add_qnx_nto_stdlib, r=workingjubilee 2023-03-02 02:41:42 +00:00
fmt Don't allow new const panic through format flattening. 2023-03-16 11:21:50 +01:00
future Remove identity_future indirection 2023-03-08 15:37:14 +01:00
hash unequal → not equal 2023-03-15 23:55:48 +05:30
intrinsics Remove DropAndReplace terminator 2023-03-07 14:25:22 +01:00
iter unequal → not equal 2023-03-15 23:55:48 +05:30
macros Remove HTML tags around warning 2023-01-06 13:20:58 +01:00
mem stage-step cfgs 2023-01-30 13:09:09 -05:00
net Add tracking issue 2023-02-26 13:50:10 +01:00
num Rollup merge of #106633 - c410-f3r:stabilize-nonzero_bits, r=dtolnay 2023-03-11 15:43:12 +01:00
ops Constify RangeBounds, RangeX::contains and RangeX::is_empty. 2023-02-15 15:50:54 +01:00
panic Replace libstd, libcore, liballoc in line comments. 2022-12-30 14:00:42 +01:00
prelude Replace libstd, libcore, liballoc in docs. 2022-12-30 14:00:40 +01:00
ptr Improved implementation and comments after code review feedback 2023-03-14 22:24:28 -07:00
slice Use nuw when calculating slice lengths from Ranges 2023-03-05 15:15:22 -08:00
str Auto merge of #105117 - pitaj:debug_asserts, r=the8472 2023-03-05 19:35:44 +00:00
sync Rollup merge of #108419 - tgross35:atomic-as-ptr, r=m-ou-se 2023-03-13 21:55:35 +01:00
task Inline Poll methods 2023-02-13 14:17:45 +08:00
unicode Replace libstd, libcore, liballoc in line comments. 2022-12-30 14:00:42 +01:00
any.rs Match unmatched backticks in library/ 2023-03-03 03:03:29 +01:00
arch.rs move core::arch into separate file 2022-11-20 10:28:14 +01:00
ascii.rs Inline <EscapeDefault as Iterator>::next 2022-03-10 15:35:22 +01:00
asserting.rs [RFC 2011] Library code 2022-05-22 07:18:32 -03:00
bool.rs Add missing assertion 2022-09-22 02:12:06 -04:00
borrow.rs Minor grammar nit. 2022-12-12 16:22:01 -07:00
cell.rs Rollup merge of #106921 - madsmtm:cell-memory-layout, r=dtolnay 2023-03-10 19:59:17 +01:00
clone.rs Make some trivial functions #[inline(always)] 2022-12-07 17:11:17 +01:00
cmp.rs Merge two different equality specialization traits in core 2023-03-01 14:42:06 -08:00
default.rs cfg-step code 2022-11-06 17:21:21 -05:00
error.md Small round of typo fixes 2022-11-04 20:06:18 -07:00
error.rs Remove a couple of #[doc(hidden)] pub fn and their #[feature] gates 2023-02-10 08:06:35 +01:00
hint.rs clarify correctness of black_box 2023-02-15 16:22:08 +00:00
internal_macros.rs ignore a doctest for the non-exported macro 2022-05-03 18:33:56 +09:00
intrinsics.rs Improved implementation and comments after code review feedback 2023-03-14 22:24:28 -07:00
lib.rs Revert "Stabilize #![feature(target_feature_11)]" 2023-03-02 13:41:17 +01:00
marker.rs may not => cannot 2023-03-08 00:00:18 +00:00
option.rs Clarify the text of some comments 2023-03-12 16:30:51 -07:00
panic.rs Replace libstd, libcore, liballoc in docs. 2022-12-30 14:00:40 +01:00
panicking.rs Don't allow new const panic through format flattening. 2023-03-16 11:21:50 +01:00
pin.rs Set version placeholders to 1.68 2023-01-25 09:44:29 -05:00
primitive.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
primitive_docs.rs unequal → not equal 2023-03-15 23:55:48 +05:30
result.rs "Basic usage" is redundant for there is just one example 2023-02-16 19:49:31 +02:00
time.rs Bump version placeholders to release 2022-11-06 17:11:02 -05:00
tuple.rs Use partial_cmp to implement tuple lt/le/ge/gt 2023-02-16 23:59:13 -08:00
unit.rs Use implicit capture syntax in format_args 2022-03-10 10:23:40 -05:00