Skip to content

Commit 8eb20e2

Browse files
authored
Merge pull request #2017 from rust-lang/TC/remote-caveat-about-format_args
Remove caveats related to `format_args!` expansion
2 parents 4c8f8b7 + 48b8659 commit 8eb20e2

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

src/destructors.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,7 @@ let x = pin!(temp()); // Super operand of super macro call expression.
540540
# x;
541541
let x = pin!({ &mut temp() }); // As above.
542542
# x;
543-
# // FIXME: Simplify after this PR lands:
544-
# // <https://github.com/rust-lang/rust/pull/145882>.
545-
let x = format_args!("{:?}{:?}", (), temp()); // As above.
543+
let x = format_args!("{:?}", temp()); // As above.
546544
# x;
547545
//
548546
// All of the temporaries above are still live here.
@@ -613,11 +611,10 @@ let x = 'a: { break 'a &temp() }; // ERROR
613611
pin!({ &temp() }); // ERROR
614612
```
615613

616-
<!-- FIXME: Simplify after https://github.com/rust-lang/rust/pull/145882 lands. -->
617614
```rust,edition2024,compile_fail,E0716
618615
# fn temp() {}
619616
// As above.
620-
format_args!("{:?}{:?}", (), { &temp() }); // ERROR
617+
format_args!("{:?}", { &temp() }); // ERROR
621618
```
622619

623620
r[destructors.forget]

src/expressions.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -270,30 +270,22 @@ r[expr.super-macros.format_args]
270270
r[expr.super-macros.format_args.super-operands]
271271
Except for the format string argument, all arguments passed to [`format_args!`] are *super operands*.
272272

273-
<!-- FIXME: Remove after https://github.com/rust-lang/rust/pull/145882 lands. -->
274-
> [!NOTE]
275-
> When there is only one placeholder, `rustc` does not yet treat the corresponding argument as a super operand. This is a bug.
276-
>
277-
> For details, see Rust issue [#145880](https://github.com/rust-lang/rust/issues/145880).
278-
279-
<!-- FIXME: Simplify after https://github.com/rust-lang/rust/pull/145882 lands. -->
280273
```rust,edition2024
281274
# fn temp() -> String { String::from("") }
282275
// Due to the call being an extending expression and the argument
283276
// being a super operand, the inner block is an extending expression,
284277
// so the scope of the temporary created in its trailing expression
285278
// is extended.
286-
let _ = format_args!("{:?}{}", (), { &temp() }); // OK
279+
let _ = format_args!("{}", { &temp() }); // OK
287280
```
288281

289282
r[expr.super-macros.format_args.super-temporaries]
290283
The super operands of [`format_args!`] are [implicitly borrowed] and are therefore [place expression contexts]. When a [value expression] is passed as an argument, it creates a *super temporary*.
291284

292-
<!-- FIXME: Simplify after https://github.com/rust-lang/rust/pull/145882 lands. -->
293285
```rust
294286
# fn temp() -> String { String::from("") }
295-
let x = format_args!("{}{}", temp(), temp());
296-
x; // <-- The temporaries are extended, allowing use here.
287+
let x = format_args!("{}", temp());
288+
x; // <-- The temporary is extended, allowing use here.
297289
```
298290

299291
The expansion of a call to [`format_args!`] sometimes creates other internal *super temporaries*.

0 commit comments

Comments
 (0)