about summary refs log tree commit diff
path: root/compiler/rustc_hir_pretty/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-07-13 17:13:27 +0000
committerbors <bors@rust-lang.org>2022-07-13 17:13:27 +0000
commitc80dde43f992f3eb419899a34551b84c6301f8e8 (patch)
tree8cdaab3defdcc525a68f7dba82c23e62be66fa9c /compiler/rustc_hir_pretty/src
parent42bd138126b0a9d38d65bc9973e72de3c5b6c37f (diff)
parent3933b2b310e9358b77269e69b0656d12a126e14a (diff)
downloadrust-c80dde43f992f3eb419899a34551b84c6301f8e8.tar.gz
rust-c80dde43f992f3eb419899a34551b84c6301f8e8.zip
Auto merge of #99210 - Dylan-DPC:rollup-879cp1t, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #98574 (Lower let-else in MIR)
 - #99011 (`UnsafeCell` blocks niches inside its nested type from being available outside)
 - #99030 (diagnostics: error messages when struct literals fail to parse)
 - #99155 (Keep unstable target features for asm feature checking)
 - #99199 (Refactor: remove an unnecessary `span_to_snippet`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_hir_pretty/src')
-rw-r--r--compiler/rustc_hir_pretty/src/lib.rs18
1 files changed, 15 insertions, 3 deletions
diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs
index 50acb0270b0..e3c97ec357e 100644
--- a/compiler/rustc_hir_pretty/src/lib.rs
+++ b/compiler/rustc_hir_pretty/src/lib.rs
@@ -883,7 +883,12 @@ impl<'a> State<'a> {
         self.ann.post(self, AnnNode::SubItem(ii.hir_id()))
     }
 
-    pub fn print_local(&mut self, init: Option<&hir::Expr<'_>>, decl: impl Fn(&mut Self)) {
+    pub fn print_local(
+        &mut self,
+        init: Option<&hir::Expr<'_>>,
+        els: Option<&hir::Block<'_>>,
+        decl: impl Fn(&mut Self),
+    ) {
         self.space_if_not_bol();
         self.ibox(INDENT_UNIT);
         self.word_nbsp("let");
@@ -897,6 +902,13 @@ impl<'a> State<'a> {
             self.word_space("=");
             self.print_expr(init);
         }
+
+        if let Some(els) = els {
+            self.nbsp();
+            self.word_space("else");
+            self.print_block(els);
+        }
+
         self.end()
     }
 
@@ -904,7 +916,7 @@ impl<'a> State<'a> {
         self.maybe_print_comment(st.span.lo());
         match st.kind {
             hir::StmtKind::Local(loc) => {
-                self.print_local(loc.init, |this| this.print_local_decl(loc));
+                self.print_local(loc.init, loc.els, |this| this.print_local_decl(loc));
             }
             hir::StmtKind::Item(item) => self.ann.nested(self, Nested::Item(item)),
             hir::StmtKind::Expr(expr) => {
@@ -1404,7 +1416,7 @@ impl<'a> State<'a> {
 
                 // Print `let _t = $init;`:
                 let temp = Ident::from_str("_t");
-                self.print_local(Some(init), |this| this.print_ident(temp));
+                self.print_local(Some(init), None, |this| this.print_ident(temp));
                 self.word(";");
 
                 // Print `_t`: