From e182d12a8493b40a557394325a3a713b6528de60 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 12 Aug 2022 02:47:57 +0000 Subject: [PATCH] Fix HIR pretty printing of let else --- compiler/rustc_hir_pretty/src/lib.rs | 4 ++++ src/test/ui/unpretty/pretty-let-else.rs | 10 ++++++++++ src/test/ui/unpretty/pretty-let-else.stdout | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 src/test/ui/unpretty/pretty-let-else.rs create mode 100644 src/test/ui/unpretty/pretty-let-else.stdout diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index e0179bd3ed1..c7966b662de 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -911,6 +911,10 @@ pub fn print_local( if let Some(els) = els { self.nbsp(); self.word_space("else"); + // containing cbox, will be closed by print-block at `}` + self.cbox(0); + // head-box, will be closed by print-block after `{` + self.ibox(0); self.print_block(els); } diff --git a/src/test/ui/unpretty/pretty-let-else.rs b/src/test/ui/unpretty/pretty-let-else.rs new file mode 100644 index 00000000000..5abfa2523b7 --- /dev/null +++ b/src/test/ui/unpretty/pretty-let-else.rs @@ -0,0 +1,10 @@ +// compile-flags: -Zunpretty=hir +// check-pass + +#![feature(let_else)] + +fn foo(x: Option) { + let Some(_) = x else { panic!() }; +} + +fn main() {} diff --git a/src/test/ui/unpretty/pretty-let-else.stdout b/src/test/ui/unpretty/pretty-let-else.stdout new file mode 100644 index 00000000000..ffe1d1657aa --- /dev/null +++ b/src/test/ui/unpretty/pretty-let-else.stdout @@ -0,0 +1,18 @@ +// compile-flags: -Zunpretty=hir +// check-pass + +#![feature(let_else)] +#[prelude_import] +use ::std::prelude::rust_2015::*; +#[macro_use] +extern crate std; + +fn foo(x: + Option) { + let Some(_) = x else + { + + { ::std::rt::begin_panic("explicit panic") } + }; + } +fn main() { }