about summary refs log tree commit diff
path: root/compiler/rustc_ast_lowering/src/lib.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-06-19 19:13:32 +0000
committerbors <bors@rust-lang.org>2025-06-19 19:13:32 +0000
commit255aa220821c05c3eac7605fce4ea1c9ab2cbdb4 (patch)
treeee6218a293a2c3d22a0f830cc64ef2f28a73a83d /compiler/rustc_ast_lowering/src/lib.rs
parent8de4c7234dd9b97c9d76b58671343fdbbc9a433e (diff)
parentb4f2cac097504a0728206b08fd4f8cb3d0946a3c (diff)
downloadrust-255aa220821c05c3eac7605fce4ea1c9ab2cbdb4.tar.gz
rust-255aa220821c05c3eac7605fce4ea1c9ab2cbdb4.zip
Auto merge of #140748 - m-ou-se:super-format-args3, r=jdonszelmann
 Allow storing `format_args!()` in variable

Fixes https://github.com/rust-lang/rust/issues/92698

Tracking issue for super let: https://github.com/rust-lang/rust/issues/139076

Tracking issue for format_args: https://github.com/rust-lang/rust/issues/99012

This change allows:

```rust
let name = "world";
let f = format_args!("hello {name}!"); // New: Store format_args!() for later!

println!("{f}");
```

This will need an FCP.

This implementation makes use of `super let`, which is unstable and might not exist in the future in its current form. However, it is entirely reasonable to assume future Rust will always have _a_ way of expressing temporary lifetimes like this, since the (stable) `pin!()` macro needs this too. (This was also the motivation for merging https://github.com/rust-lang/rust/pull/139114.)

(This is a second version of https://github.com/rust-lang/rust/pull/139135)
Diffstat (limited to 'compiler/rustc_ast_lowering/src/lib.rs')
-rw-r--r--compiler/rustc_ast_lowering/src/lib.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs
index e74fd1db15b..26d7c0cd6d3 100644
--- a/compiler/rustc_ast_lowering/src/lib.rs
+++ b/compiler/rustc_ast_lowering/src/lib.rs
@@ -2292,6 +2292,26 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
         self.stmt(span, hir::StmtKind::Let(self.arena.alloc(local)))
     }
 
+    fn stmt_super_let_pat(
+        &mut self,
+        span: Span,
+        pat: &'hir hir::Pat<'hir>,
+        init: Option<&'hir hir::Expr<'hir>>,
+    ) -> hir::Stmt<'hir> {
+        let hir_id = self.next_id();
+        let local = hir::LetStmt {
+            super_: Some(span),
+            hir_id,
+            init,
+            pat,
+            els: None,
+            source: hir::LocalSource::Normal,
+            span: self.lower_span(span),
+            ty: None,
+        };
+        self.stmt(span, hir::StmtKind::Let(self.arena.alloc(local)))
+    }
+
     fn block_expr(&mut self, expr: &'hir hir::Expr<'hir>) -> &'hir hir::Block<'hir> {
         self.block_all(expr.span, &[], Some(expr))
     }