From 9a30ecdf1169dd53a1e226cc3523260ef88fd90a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Thu, 28 Jan 2016 07:21:32 +0100 Subject: [PATCH] libsyntax: fix pretty printing of macro with braces Pretty printing of macro with braces but without terminated semicolon removed more boxes from stack than it put there, resulting in panic. This fixes the issue #30731. --- src/libsyntax/print/pprust.rs | 7 ++----- src/test/pretty/issue-30731.rs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 src/test/pretty/issue-30731.rs diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index e80297eb797..759b16c5738 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1781,11 +1781,8 @@ pub fn print_mac(&mut self, m: &ast::Mac, delim: token::DelimToken) token::Paren => try!(self.popen()), token::Bracket => try!(word(&mut self.s, "[")), token::Brace => { - // head-ibox, will be closed by bopen() - try!(self.ibox(0)); - // Don't ask me why the regular bopen() does - // more then just opening a brace... - try!(self.bopen()) + try!(self.head("")); + try!(self.bopen()); } } try!(self.print_tts(&m.node.tts)); diff --git a/src/test/pretty/issue-30731.rs b/src/test/pretty/issue-30731.rs new file mode 100644 index 00000000000..cd72ae98433 --- /dev/null +++ b/src/test/pretty/issue-30731.rs @@ -0,0 +1,17 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +// +// Test pretty printing of macro with braces but without terminating semicolon, +// this used to panic before fix. + +// pretty-compare-only +// pp-exact + +fn main() { b!{ } c }