Merge pull request #2391 from dtolnay/parselifetimes

Simplify parsing of borrow="..." attributes
This commit is contained in:
David Tolnay 2023-03-08 18:44:57 -08:00 committed by GitHub
commit eb1e8c140d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,7 +5,7 @@ use quote::ToTokens;
use std::borrow::Cow; use std::borrow::Cow;
use std::collections::BTreeSet; use std::collections::BTreeSet;
use syn; use syn;
use syn::parse::{Parse, ParseStream}; use syn::parse::ParseStream;
use syn::punctuated::Punctuated; use syn::punctuated::Punctuated;
use syn::Ident; use syn::Ident;
use syn::Meta::{List, NameValue, Path}; use syn::Meta::{List, NameValue, Path};
@ -1662,15 +1662,9 @@ fn parse_lit_into_lifetimes(
return Err(()); return Err(());
} }
struct BorrowedLifetimes(Punctuated<syn::Lifetime, Token![+]>); if let Ok(lifetimes) =
string.parse_with(Punctuated::<syn::Lifetime, Token![+]>::parse_separated_nonempty)
impl Parse for BorrowedLifetimes { {
fn parse(input: ParseStream) -> syn::Result<Self> {
Punctuated::parse_separated_nonempty(input).map(BorrowedLifetimes)
}
}
if let Ok(BorrowedLifetimes(lifetimes)) = string.parse() {
let mut set = BTreeSet::new(); let mut set = BTreeSet::new();
for lifetime in lifetimes { for lifetime in lifetimes {
if !set.insert(lifetime.clone()) { if !set.insert(lifetime.clone()) {