Skip to content

Commit 9a30ecd

Browse files
committed
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.
1 parent b8b18aa commit 9a30ecd

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/libsyntax/print/pprust.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1781,11 +1781,8 @@ impl<'a> State<'a> {
17811781
token::Paren => try!(self.popen()),
17821782
token::Bracket => try!(word(&mut self.s, "[")),
17831783
token::Brace => {
1784-
// head-ibox, will be closed by bopen()
1785-
try!(self.ibox(0));
1786-
// Don't ask me why the regular bopen() does
1787-
// more then just opening a brace...
1788-
try!(self.bopen())
1784+
try!(self.head(""));
1785+
try!(self.bopen());
17891786
}
17901787
}
17911788
try!(self.print_tts(&m.node.tts));

src/test/pretty/issue-30731.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
//
11+
// Test pretty printing of macro with braces but without terminating semicolon,
12+
// this used to panic before fix.
13+
14+
// pretty-compare-only
15+
// pp-exact
16+
17+
fn main() { b!{ } c }

0 commit comments

Comments
 (0)