mirror of
https://gitee.com/openharmony/third_party_rust_syn
synced 2025-02-17 05:57:30 +00:00
Move TypeParamBound parse loop to associated function
This commit is contained in:
parent
3e915e5c98
commit
b8b0761cb8
@ -828,6 +828,31 @@ pub mod parsing {
|
||||
}
|
||||
}
|
||||
|
||||
impl TypeParamBound {
|
||||
pub(crate) fn parse_multiple(
|
||||
input: ParseStream,
|
||||
allow_plus: bool,
|
||||
) -> Result<Punctuated<Self, Token![+]>> {
|
||||
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<Self> {
|
||||
|
17
src/ty.rs
17
src/ty.rs
@ -924,22 +924,7 @@ pub mod parsing {
|
||||
input: ParseStream,
|
||||
allow_plus: bool,
|
||||
) -> Result<Punctuated<TypeParamBound, Token![+]>> {
|
||||
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"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user