Skip to content

Commit

Permalink
Fix HIR pretty printing of let else
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Aug 12, 2022
1 parent 2ed0f29 commit e182d12
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,10 @@ impl<'a> State<'a> {
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);
}

Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/unpretty/pretty-let-else.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// compile-flags: -Zunpretty=hir
// check-pass

#![feature(let_else)]

fn foo(x: Option<u32>) {
let Some(_) = x else { panic!() };
}

fn main() {}
18 changes: 18 additions & 0 deletions src/test/ui/unpretty/pretty-let-else.stdout
Original file line number Diff line number Diff line change
@@ -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<u32>) {
let Some(_) = x else
{

{ ::std::rt::begin_panic("explicit panic") }
};
}
fn main() { }

0 comments on commit e182d12

Please sign in to comment.