Skip to content

Commit

Permalink
Added error back for derive attribute using the wrong delimiters
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysonmaw committed Jul 16, 2023
1 parent cecf2d7 commit e49c85a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ouroboros_macro/src/parse.rs
@@ -1,6 +1,6 @@
use proc_macro2::{Delimiter, Span, TokenTree};
use quote::format_ident;
use syn::{spanned::Spanned, Attribute, Error, Fields, GenericParam, ItemStruct, Meta};
use syn::{spanned::Spanned, Attribute, Error, Fields, GenericParam, ItemStruct, Meta, MacroDelimiter};

use crate::{
covariance_detection::type_is_covariant_over_this_lifetime,
Expand Down Expand Up @@ -116,11 +116,14 @@ fn parse_derive_token(token: &TokenTree) -> Result<Option<Derive>, Error> {

fn parse_derive_attribute(attr: &Attribute) -> Result<Vec<Derive>, Error> {
let body = match &attr.meta {
Meta::List(ml) => &ml.tokens,
Meta::List(ml) => ml,
_ => unreachable!(),
};
if !matches!(body.delimiter, MacroDelimiter::Paren(_)){
return Err(Error::new(attr.span(), format!("malformed derive input, derive attributes are of the form `#[derive({})]`",body.tokens.to_string())));
}
let mut derives = Vec::new();
for token in body.clone().into_iter() {
for token in body.tokens.clone().into_iter() {
if let Some(derive) = parse_derive_token(&token)? {
derives.push(derive);
}
Expand Down

0 comments on commit e49c85a

Please sign in to comment.