rust/compiler/rustc_interface/src
bors d19b64fb54 Auto merge of #109999 - m-ou-se:flatten-format-args, r=oli-obk
Enable flatten-format-args by default.

Part of https://github.com/rust-lang/rust/issues/99012.

This enables the `flatten-format-args` feature that was added by https://github.com/rust-lang/rust/pull/106824:

> 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.

This is mostly an optimization, except that it will be visible through [`fmt::Arguments::as_str()`](https://doc.rust-lang.org/nightly/std/fmt/struct.Arguments.html#method.as_str).

In https://github.com/rust-lang/rust/pull/106823, there was already a libs-api FCP about the documentation of `fmt::Arguments::as_str()` to allow it to give `Some` rather than `None` depending on optimizations like this. That was just a documentation update though. This PR is the one that actually makes the user visible change:

```rust
assert_eq!(format_args!("abc").as_str(), Some("abc")); // Unchanged.
assert_eq!(format_args!("ab{}", "c").as_str(), Some("abc")); // Was `None` before!
```
2023-04-20 23:19:19 +00:00
..
callbacks.rs Simplify tls::enter_context. 2023-02-09 15:25:45 +11:00
errors.rs Remove a back compat warning 2023-02-22 19:39:03 +00:00
interface.rs Improve with_source_map. 2023-03-31 15:57:25 +11:00
lib.rs Add rustc_fluent_macro to decouple fluent from rustc_macros 2023-04-18 18:56:22 +00:00
passes.rs Migrate sess.opts.tests uses to sess.is_test_crate() 2023-04-09 21:37:31 +02:00
proc_macro_decls.rs rustc: Remove unused Session argument from some attribute functions 2023-03-22 13:55:55 +04:00
queries.rs Add a usize-indexed append-only-vec 2023-04-04 09:01:44 +00:00
tests.rs Update test. 2023-04-17 14:13:37 +02:00
util.rs Rollup merge of #108480 - Zoxc:rayon-tlv, r=cuviper 2023-03-28 12:51:12 +02:00