Skip to content

Commit

Permalink
Rollup merge of #92417 - dtolnay:printimpl, r=jackh726
Browse files Browse the repository at this point in the history
Fix spacing and ordering of words in pretty printed Impl

Follow-up to #92238 fixing one of the FIXMEs.

```rust
macro_rules! repro {
    ($item:item) => {
        stringify!($item)
    };
}

fn main() {
    println!("{}", repro!(impl<T> Struct<T> {}));
    println!("{}", repro!(impl<T> const Trait for T {}));
}
```

Before:&ensp;`impl <T> Struct<T> {}`
After:&ensp;`impl<T> Struct<T> {}`

Before:&ensp;`impl const <T> Trait for T {}` 😿
After:&ensp;`impl<T> const Trait for T {}`
  • Loading branch information
matthiaskrgr committed Jan 6, 2022
2 parents 0604cf5 + a24e238 commit 1a8f698
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 6 additions & 3 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1287,14 +1287,17 @@ impl<'a> State<'a> {
self.print_visibility(&item.vis);
self.print_defaultness(defaultness);
self.print_unsafety(unsafety);
self.word_nbsp("impl");
self.print_constness(constness);
self.word("impl");

if !generics.params.is_empty() {
if generics.params.is_empty() {
self.nbsp();
} else {
self.print_generic_params(&generics.params);
self.space();
}

self.print_constness(constness);

if let ast::ImplPolarity::Negative(_) = polarity {
self.word("!");
}
Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/macros/stringify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,14 +603,20 @@ fn test_item() {
stringify_item!(
impl<T> Struct<T> {}
),
"impl <T> Struct<T> {}", // FIXME
"impl<T> Struct<T> {}",
);
assert_eq!(
stringify_item!(
pub impl Trait for Struct {}
),
"pub impl Trait for Struct {}",
);
assert_eq!(
stringify_item!(
impl<T> const Trait for T {}
),
"impl<T> const Trait for T {}",
);
assert_eq!(
stringify_item!(
impl ~const Struct {}
Expand Down

0 comments on commit 1a8f698

Please sign in to comment.