Skip to content

Commit

Permalink
Factor out impl Trait parenthesizing code
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jun 2, 2022
1 parent e26dad7 commit 3a4b7c2
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,7 @@ impl VisitMut for AddLifetimeToImplTrait {
}

fn visit_type_reference_mut(&mut self, ty: &mut TypeReference) {
if let Type::ImplTrait(_) = *ty.elem {
let elem = mem::replace(&mut *ty.elem, Type::Verbatim(TokenStream::new()));
*ty.elem = Type::Paren(TypeParen {
paren_token: token::Paren(ty.and_token.span),
elem: Box::new(elem),
});
}
parenthesize_impl_trait(&mut ty.elem, ty.and_token.span);
visit_mut::visit_type_reference_mut(self, ty);
}

Expand All @@ -97,3 +91,13 @@ impl VisitMut for AddLifetimeToImplTrait {
// fn outer(arg: [u8; { fn inner(_: impl Trait) {}; 0 }]);
}
}

fn parenthesize_impl_trait(elem: &mut Type, paren_span: Span) {
if let Type::ImplTrait(_) = *elem {
let placeholder = Type::Verbatim(TokenStream::new());
*elem = Type::Paren(TypeParen {
paren_token: token::Paren(paren_span),
elem: Box::new(mem::replace(elem, placeholder)),
});
}
}

0 comments on commit 3a4b7c2

Please sign in to comment.