Skip to content

Commit 9527533

Browse files
authored
Rollup merge of #92487 - dtolnay:traitalias, r=matthewjasper
Fix unclosed boxes in pretty printing of TraitAlias This was causing trait aliases to not even render at all in stringified / pretty printed output. ```rust macro_rules! repro { ($item:item) => { stringify!($item) }; } fn main() { println!("{:?}", repro!(pub trait Trait<T> = Sized where T: 'a;)); } ``` Before:&ensp;`""` After:&ensp;`"pub trait Trait<T> = Sized where T: 'a;"` The fix is copied from how `head`/`end` for `ItemKind::Use`, `ItemKind::ExternCrate`, and `ItemKind::Mod` are all done in the pretty printer: https://github.com/rust-lang/rust/blob/dd3ac41495e85a9b7b5cb3186379d02ce17e51fe/compiler/rustc_ast_pretty/src/pprust/state.rs#L1178-L1184
2 parents 7be8693 + a18f43f commit 9527533

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1357,9 +1357,7 @@ impl<'a> State<'a> {
13571357
self.bclose(item.span, empty);
13581358
}
13591359
ast::ItemKind::TraitAlias(ref generics, ref bounds) => {
1360-
self.head("");
1361-
self.print_visibility(&item.vis);
1362-
self.word_nbsp("trait");
1360+
self.head(visibility_qualified(&item.vis, "trait"));
13631361
self.print_ident(item.ident);
13641362
self.print_generic_params(&generics.params);
13651363
let mut real_bounds = Vec::with_capacity(bounds.len());
@@ -1377,6 +1375,8 @@ impl<'a> State<'a> {
13771375
self.print_type_bounds("=", &real_bounds);
13781376
self.print_where_clause(&generics.where_clause);
13791377
self.word(";");
1378+
self.end(); // end inner head-block
1379+
self.end(); // end outer head-block
13801380
}
13811381
ast::ItemKind::MacCall(ref mac) => {
13821382
self.print_mac(mac);

compiler/rustc_hir_pretty/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -705,9 +705,7 @@ impl<'a> State<'a> {
705705
self.bclose(item.span);
706706
}
707707
hir::ItemKind::TraitAlias(ref generics, ref bounds) => {
708-
self.head("");
709-
self.print_visibility(&item.vis);
710-
self.word_nbsp("trait");
708+
self.head(visibility_qualified(&item.vis, "trait"));
711709
self.print_ident(item.ident);
712710
self.print_generic_params(&generics.params);
713711
let mut real_bounds = Vec::with_capacity(bounds.len());
@@ -725,6 +723,8 @@ impl<'a> State<'a> {
725723
self.print_bounds("=", real_bounds);
726724
self.print_where_clause(&generics.where_clause);
727725
self.word(";");
726+
self.end(); // end inner head-block
727+
self.end(); // end outer head-block
728728
}
729729
}
730730
self.ann.post(self, AnnNode::Item(item))

src/test/ui/macros/stringify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ fn test_item() {
589589
stringify_item!(
590590
pub trait Trait<T> = Sized where T: 'a;
591591
),
592-
"", // FIXME
592+
"pub trait Trait<T> = Sized where T: 'a;",
593593
);
594594

595595
// ItemKind::Impl

0 commit comments

Comments
 (0)