Capture parens in trait bound
diff --git a/src/gen/fold.rs b/src/gen/fold.rs
index e53ff9a..b5b67b3 100644
--- a/src/gen/fold.rs
+++ b/src/gen/fold.rs
@@ -2483,6 +2483,7 @@
# [ cfg ( any ( feature = "full" , feature = "derive" ) ) ]
pub fn fold_trait_bound<V: Fold + ?Sized>(_visitor: &mut V, _i: TraitBound) -> TraitBound {
TraitBound {
+ paren_token: (_i . paren_token).map(|it| { Paren(tokens_helper(_visitor, &(it).0)) }),
modifier: _visitor.fold_trait_bound_modifier(_i . modifier),
lifetimes: (_i . lifetimes).map(|it| { _visitor.fold_bound_lifetimes(it) }),
path: _visitor.fold_path(_i . path),
diff --git a/src/gen/visit.rs b/src/gen/visit.rs
index 1298276..6a38d1d 100644
--- a/src/gen/visit.rs
+++ b/src/gen/visit.rs
@@ -1935,6 +1935,7 @@
}
# [ cfg ( any ( feature = "full" , feature = "derive" ) ) ]
pub fn visit_trait_bound<'ast, V: Visit<'ast> + ?Sized>(_visitor: &mut V, _i: &'ast TraitBound) {
+ if let Some(ref it) = _i . paren_token { tokens_helper(_visitor, &(it).0) };
_visitor.visit_trait_bound_modifier(& _i . modifier);
if let Some(ref it) = _i . lifetimes { _visitor.visit_bound_lifetimes(it) };
_visitor.visit_path(& _i . path);
diff --git a/src/gen/visit_mut.rs b/src/gen/visit_mut.rs
index 95a358a..2a86a0c 100644
--- a/src/gen/visit_mut.rs
+++ b/src/gen/visit_mut.rs
@@ -1936,6 +1936,7 @@
}
# [ cfg ( any ( feature = "full" , feature = "derive" ) ) ]
pub fn visit_trait_bound_mut<V: VisitMut + ?Sized>(_visitor: &mut V, _i: &mut TraitBound) {
+ if let Some(ref mut it) = _i . paren_token { tokens_helper(_visitor, &mut (it).0) };
_visitor.visit_trait_bound_modifier_mut(& mut _i . modifier);
if let Some(ref mut it) = _i . lifetimes { _visitor.visit_bound_lifetimes_mut(it) };
_visitor.visit_path_mut(& mut _i . path);
diff --git a/src/generics.rs b/src/generics.rs
index a27298f..eaade92 100644
--- a/src/generics.rs
+++ b/src/generics.rs
@@ -385,6 +385,7 @@
/// *This type is available if Syn is built with the `"derive"` or `"full"`
/// feature.*
pub struct TraitBound {
+ pub paren_token: Option<token::Paren>,
pub modifier: TraitBoundModifier,
/// The `for<'a>` in `for<'a> Foo<&'a T>`
pub lifetimes: Option<BoundLifetimes>,
@@ -599,7 +600,10 @@
|
syn!(TraitBound) => { TypeParamBound::Trait }
|
- parens!(syn!(TraitBound)) => { |bound| TypeParamBound::Trait(bound.1) }
+ parens!(syn!(TraitBound)) => {|(parens, mut bound)| {
+ bound.paren_token = Some(parens);
+ TypeParamBound::Trait(bound)
+ }}
));
fn description() -> Option<&'static str> {
@@ -622,6 +626,7 @@
path.segments.last_mut().unwrap().value_mut().arguments = parenthesized;
}
TraitBound {
+ paren_token: None,
modifier: modifier,
lifetimes: lifetimes,
path: path,
@@ -919,9 +924,15 @@
impl ToTokens for TraitBound {
fn to_tokens(&self, tokens: &mut Tokens) {
- self.modifier.to_tokens(tokens);
- self.lifetimes.to_tokens(tokens);
- self.path.to_tokens(tokens);
+ let to_tokens = |tokens: &mut Tokens| {
+ self.modifier.to_tokens(tokens);
+ self.lifetimes.to_tokens(tokens);
+ self.path.to_tokens(tokens);
+ };
+ match self.paren_token {
+ Some(paren) => paren.surround(tokens, to_tokens),
+ None => to_tokens(tokens),
+ }
}
}
diff --git a/tests/test_generics.rs b/tests/test_generics.rs
index 84eb529..d4ca16f 100644
--- a/tests/test_generics.rs
+++ b/tests/test_generics.rs
@@ -79,6 +79,7 @@
}.into(),
bounds: punctuated![
TypeParamBound::Trait(TraitBound {
+ paren_token: None,
modifier: TraitBoundModifier::None,
lifetimes: None,
path: "Debug".into(),
@@ -126,6 +127,7 @@
let tokens = quote!(Debug);
let expected = TypeParamBound::Trait(TraitBound {
+ paren_token: None,
modifier: TraitBoundModifier::None,
lifetimes: None,
path: "Debug".into(),
@@ -137,6 +139,7 @@
let tokens = quote!(?Sized);
let expected = TypeParamBound::Trait(TraitBound {
+ paren_token: None,
modifier: TraitBoundModifier::Maybe(Default::default()),
lifetimes: None,
path: "Sized".into(),