Skip to content

Commit

Permalink
remove unused #[no_parse_bound] attr
Browse files Browse the repository at this point in the history
  • Loading branch information
sharnoff committed Dec 8, 2020
1 parent 5fa14ec commit 1cb8f49
Showing 1 changed file with 3 additions and 44 deletions.
47 changes: 3 additions & 44 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@
use proc_macro2::{Span, TokenStream};
use quote::{quote, quote_spanned, ToTokens};
use syn::spanned::Spanned;
use syn::{parse_macro_input, AttrStyle, Attribute, Data, DeriveInput, Ident, Result};
use syn::{parse_macro_input, Data, DeriveInput, Ident, Result};

#[macro_use]
mod error_macros;
Expand All @@ -343,17 +343,7 @@ mod variants;

#[proc_macro_derive(
Parse,
attributes(
paren,
bracket,
brace,
inside,
call,
parse_terminated,
peek,
peek_with,
no_parse_bound
)
attributes(paren, bracket, brace, inside, call, parse_terminated, peek, peek_with)
)]
pub fn derive_parse(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input = parse_macro_input!(item as DeriveInput);
Expand Down Expand Up @@ -418,7 +408,7 @@ fn require_impl_parse_if_type(param: &syn::GenericParam) -> Result<TokenStream>
eq_token,
default,
} = match param {
Type(t) if !any_attr_allows_no_parse(&t.attrs)? => t,
Type(t) => t,
param => return Ok(param.to_token_stream()),
};

Expand All @@ -442,37 +432,6 @@ fn require_impl_parse_if_type(param: &syn::GenericParam) -> Result<TokenStream>
})
}

// Returns true if and only if there's an attribute that's exactly `#[no_parse_bound]`
fn any_attr_allows_no_parse(attrs: &[Attribute]) -> Result<bool> {
attrs
.iter()
.try_fold(false, |acc, a| Ok(acc || attr_allows_no_parse(a)?))
}

// Returns true if and only if the attribute is `#[no_parse_bound]`
fn attr_allows_no_parse(attr: &Attribute) -> Result<bool> {
if let AttrStyle::Inner(_) = &attr.style {
return Err(syn::Error::new(
attr.span(),
"`#[no_parse_bound]` must be an outer attribute",
));
}

let Attribute { path, tokens, .. } = attr;
if path.get_ident().map(ToString::to_string) != Some("no_parse_bound".into()) {
return Ok(false);
}

if !tokens.is_empty() {
return Err(syn::Error::new(
attr.span(),
"`#[no_parse_bound]` does not expect arguments",
));
}

Ok(true)
}

fn convert_to_arg(param: syn::GenericParam) -> TokenStream {
use syn::GenericParam::{Const, Lifetime, Type};

Expand Down

0 comments on commit 1cb8f49

Please sign in to comment.