diff --git a/src/generics.rs b/src/generics.rs index 9c2802f87b..6d4fe847ed 100644 --- a/src/generics.rs +++ b/src/generics.rs @@ -828,6 +828,31 @@ pub mod parsing { } } + impl TypeParamBound { + pub(crate) fn parse_multiple( + input: ParseStream, + allow_plus: bool, + ) -> Result> { + let mut bounds = Punctuated::new(); + loop { + bounds.push_value(input.parse()?); + if !(allow_plus && input.peek(Token![+])) { + break; + } + bounds.push_punct(input.parse()?); + if !(input.peek(Ident::peek_any) + || input.peek(Token![::]) + || input.peek(Token![?]) + || input.peek(Lifetime) + || input.peek(token::Paren)) + { + break; + } + } + Ok(bounds) + } + } + #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for TraitBound { fn parse(input: ParseStream) -> Result { diff --git a/src/ty.rs b/src/ty.rs index 4068be3c75..5c3b31f71f 100644 --- a/src/ty.rs +++ b/src/ty.rs @@ -924,22 +924,7 @@ pub mod parsing { input: ParseStream, allow_plus: bool, ) -> Result> { - let mut bounds = Punctuated::new(); - loop { - bounds.push_value(input.parse()?); - if !(allow_plus && input.peek(Token![+])) { - break; - } - bounds.push_punct(input.parse()?); - if !(input.peek(Ident::peek_any) - || input.peek(Token![::]) - || input.peek(Token![?]) - || input.peek(Lifetime) - || input.peek(token::Paren)) - { - break; - } - } + let bounds = TypeParamBound::parse_multiple(input, allow_plus)?; // Just lifetimes like `'a + 'b` is not a TraitObject. if !at_least_one_type(&bounds) { return Err(input.error("expected at least one type"));