Skip to content

Commit 1a8f698

Browse files
authored
Rollup merge of rust-lang#92417 - dtolnay:printimpl, r=jackh726
Fix spacing and ordering of words in pretty printed Impl Follow-up to rust-lang#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 {}`
2 parents 0604cf5 + a24e238 commit 1a8f698

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1287,14 +1287,17 @@ impl<'a> State<'a> {
12871287
self.print_visibility(&item.vis);
12881288
self.print_defaultness(defaultness);
12891289
self.print_unsafety(unsafety);
1290-
self.word_nbsp("impl");
1291-
self.print_constness(constness);
1290+
self.word("impl");
12921291

1293-
if !generics.params.is_empty() {
1292+
if generics.params.is_empty() {
1293+
self.nbsp();
1294+
} else {
12941295
self.print_generic_params(&generics.params);
12951296
self.space();
12961297
}
12971298

1299+
self.print_constness(constness);
1300+
12981301
if let ast::ImplPolarity::Negative(_) = polarity {
12991302
self.word("!");
13001303
}

src/test/ui/macros/stringify.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -603,14 +603,20 @@ fn test_item() {
603603
stringify_item!(
604604
impl<T> Struct<T> {}
605605
),
606-
"impl <T> Struct<T> {}", // FIXME
606+
"impl<T> Struct<T> {}",
607607
);
608608
assert_eq!(
609609
stringify_item!(
610610
pub impl Trait for Struct {}
611611
),
612612
"pub impl Trait for Struct {}",
613613
);
614+
assert_eq!(
615+
stringify_item!(
616+
impl<T> const Trait for T {}
617+
),
618+
"impl<T> const Trait for T {}",
619+
);
614620
assert_eq!(
615621
stringify_item!(
616622
impl ~const Struct {}

0 commit comments

Comments
 (0)