diff --git a/src/generics.rs b/src/generics.rs index 3c641fc..017e3af 100644 --- a/src/generics.rs +++ b/src/generics.rs @@ -151,13 +151,19 @@ impl Printer { #[cfg(feature = "verbatim")] fn type_param_bound_verbatim(&mut self, tokens: &TokenStream) { use syn::parse::{Parse, ParseStream, Result}; - use syn::{parenthesized, token, Token}; + use syn::{parenthesized, token, Ident, Lifetime, Token}; enum TypeParamBoundVerbatim { Ellipsis, + PreciseCapture(Vec), TildeConst(TraitBound), } + enum Capture { + Lifetime(Lifetime), + Type(Ident), + } + impl Parse for TypeParamBoundVerbatim { fn parse(input: ParseStream) -> Result { let content; @@ -167,7 +173,33 @@ impl Printer { (None, input) }; let lookahead = content.lookahead1(); - if lookahead.peek(Token![~]) { + if lookahead.peek(Token![use]) { + input.parse::()?; + input.parse::()?; + let mut captures = Vec::new(); + loop { + let lookahead = input.lookahead1(); + captures.push(if lookahead.peek(Lifetime) { + input.parse().map(Capture::Lifetime)? + } else if lookahead.peek(Ident) { + input.parse().map(Capture::Type)? + } else if lookahead.peek(Token![>]) { + break; + } else { + return Err(lookahead.error()); + }); + let lookahead = input.lookahead1(); + if lookahead.peek(Token![,]) { + input.parse::()?; + } else if lookahead.peek(Token![>]) { + break; + } else { + return Err(lookahead.error()); + } + } + input.parse::]>()?; + Ok(TypeParamBoundVerbatim::PreciseCapture(captures)) + } else if lookahead.peek(Token![~]) { content.parse::()?; content.parse::()?; let mut bound: TraitBound = content.parse()?; @@ -191,6 +223,19 @@ impl Printer { TypeParamBoundVerbatim::Ellipsis => { self.word("..."); } + TypeParamBoundVerbatim::PreciseCapture(captures) => { + self.word("use<"); + for capture in captures.iter().delimited() { + match *capture { + Capture::Lifetime(lifetime) => self.lifetime(lifetime), + Capture::Type(ident) => self.ident(ident), + } + if !capture.is_last { + self.word(", "); + } + } + self.word(">"); + } TypeParamBoundVerbatim::TildeConst(trait_bound) => { let tilde_const = true; self.trait_bound(&trait_bound, tilde_const);