Rollup merge of #92417 - dtolnay:printimpl, r=jackh726

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 {}`
This commit is contained in:
Matthias Krüger 2022-01-06 23:15:16 +01:00 committed by GitHub
commit 1a8f69826c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View file

@ -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("!");
}

View file

@ -603,7 +603,7 @@ fn test_item() {
stringify_item!(
impl<T> Struct<T> {}
),
"impl <T> Struct<T> {}", // FIXME
"impl<T> Struct<T> {}",
);
assert_eq!(
stringify_item!(
@ -611,6 +611,12 @@ fn test_item() {
),
"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 {}