Skip to content

Commit 3a4b7c2

Browse files
committed
Factor out impl Trait parenthesizing code
1 parent e26dad7 commit 3a4b7c2

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/lifetime.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,7 @@ impl VisitMut for AddLifetimeToImplTrait {
8181
}
8282

8383
fn visit_type_reference_mut(&mut self, ty: &mut TypeReference) {
84-
if let Type::ImplTrait(_) = *ty.elem {
85-
let elem = mem::replace(&mut *ty.elem, Type::Verbatim(TokenStream::new()));
86-
*ty.elem = Type::Paren(TypeParen {
87-
paren_token: token::Paren(ty.and_token.span),
88-
elem: Box::new(elem),
89-
});
90-
}
84+
parenthesize_impl_trait(&mut ty.elem, ty.and_token.span);
9185
visit_mut::visit_type_reference_mut(self, ty);
9286
}
9387

@@ -97,3 +91,13 @@ impl VisitMut for AddLifetimeToImplTrait {
9791
// fn outer(arg: [u8; { fn inner(_: impl Trait) {}; 0 }]);
9892
}
9993
}
94+
95+
fn parenthesize_impl_trait(elem: &mut Type, paren_span: Span) {
96+
if let Type::ImplTrait(_) = *elem {
97+
let placeholder = Type::Verbatim(TokenStream::new());
98+
*elem = Type::Paren(TypeParen {
99+
paren_token: token::Paren(paren_span),
100+
elem: Box::new(mem::replace(elem, placeholder)),
101+
});
102+
}
103+
}

0 commit comments

Comments
 (0)