Skip to content

Commit f910afd

Browse files
authored
Merge pull request rust-lang#3470 from topecongiro/issue-3051
Do not add a space after empty impl
2 parents 288d7db + 17ca740 commit f910afd

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/types.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,9 +667,13 @@ impl Rewrite for ast::Ty {
667667
rewrite_macro(mac, None, context, shape, MacroPosition::Expression)
668668
}
669669
ast::TyKind::ImplicitSelf => Some(String::from("")),
670-
ast::TyKind::ImplTrait(_, ref it) => it
671-
.rewrite(context, shape)
672-
.map(|it_str| format!("impl {}", it_str)),
670+
ast::TyKind::ImplTrait(_, ref it) => {
671+
// Empty trait is not a parser error.
672+
it.rewrite(context, shape).map(|it_str| {
673+
let space = if it_str.is_empty() { "" } else { " " };
674+
format!("impl{}{}", space, it_str)
675+
})
676+
}
673677
ast::TyKind::CVarArgs => Some("...".to_owned()),
674678
ast::TyKind::Err | ast::TyKind::Typeof(..) => unreachable!(),
675679
}

tests/source/type.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ impl Future<Item = (), Error = SomeError> + 'a,
8383
'c {
8484
}
8585

86+
// #3051
87+
token![impl];
88+
token![ impl ];
89+
8690
// #3060
8791
macro_rules! foo {
8892
($foo_api: ty) => {

tests/target/type.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ pub fn do_something<'a, T: Trait1 + Trait2 + 'a>(
8282
> + 'a + 'b + 'c {
8383
}
8484

85+
// #3051
86+
token![impl];
87+
token![impl];
88+
8589
// #3060
8690
macro_rules! foo {
8791
($foo_api: ty) => {

0 commit comments

Comments
 (0)