mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 06:22:00 +00:00
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: `""`
After: `"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:
dd3ac41495/compiler/rustc_ast_pretty/src/pprust/state.rs (L1178-L1184)
This commit is contained in:
commit
9527533408
@ -1357,9 +1357,7 @@ impl<'a> State<'a> {
|
||||
self.bclose(item.span, empty);
|
||||
}
|
||||
ast::ItemKind::TraitAlias(ref generics, ref bounds) => {
|
||||
self.head("");
|
||||
self.print_visibility(&item.vis);
|
||||
self.word_nbsp("trait");
|
||||
self.head(visibility_qualified(&item.vis, "trait"));
|
||||
self.print_ident(item.ident);
|
||||
self.print_generic_params(&generics.params);
|
||||
let mut real_bounds = Vec::with_capacity(bounds.len());
|
||||
@ -1377,6 +1375,8 @@ impl<'a> State<'a> {
|
||||
self.print_type_bounds("=", &real_bounds);
|
||||
self.print_where_clause(&generics.where_clause);
|
||||
self.word(";");
|
||||
self.end(); // end inner head-block
|
||||
self.end(); // end outer head-block
|
||||
}
|
||||
ast::ItemKind::MacCall(ref mac) => {
|
||||
self.print_mac(mac);
|
||||
|
@ -705,9 +705,7 @@ impl<'a> State<'a> {
|
||||
self.bclose(item.span);
|
||||
}
|
||||
hir::ItemKind::TraitAlias(ref generics, ref bounds) => {
|
||||
self.head("");
|
||||
self.print_visibility(&item.vis);
|
||||
self.word_nbsp("trait");
|
||||
self.head(visibility_qualified(&item.vis, "trait"));
|
||||
self.print_ident(item.ident);
|
||||
self.print_generic_params(&generics.params);
|
||||
let mut real_bounds = Vec::with_capacity(bounds.len());
|
||||
@ -725,6 +723,8 @@ impl<'a> State<'a> {
|
||||
self.print_bounds("=", real_bounds);
|
||||
self.print_where_clause(&generics.where_clause);
|
||||
self.word(";");
|
||||
self.end(); // end inner head-block
|
||||
self.end(); // end outer head-block
|
||||
}
|
||||
}
|
||||
self.ann.post(self, AnnNode::Item(item))
|
||||
|
@ -589,7 +589,7 @@ fn test_item() {
|
||||
stringify_item!(
|
||||
pub trait Trait<T> = Sized where T: 'a;
|
||||
),
|
||||
"", // FIXME
|
||||
"pub trait Trait<T> = Sized where T: 'a;",
|
||||
);
|
||||
|
||||
// ItemKind::Impl
|
||||
|
Loading…
Reference in New Issue
Block a user