From e49c85ad34cfd746f3668e1b052573c2878da71d Mon Sep 17 00:00:00 2001 From: Jaysonmaw <55055180+jaysonmaw@users.noreply.github.com> Date: Sat, 15 Jul 2023 21:17:20 -0500 Subject: [PATCH] Added error back for derive attribute using the wrong delimiters --- ouroboros_macro/src/parse.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ouroboros_macro/src/parse.rs b/ouroboros_macro/src/parse.rs index eb6174e..07447ad 100644 --- a/ouroboros_macro/src/parse.rs +++ b/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, @@ -116,11 +116,14 @@ fn parse_derive_token(token: &TokenTree) -> Result, Error> { fn parse_derive_attribute(attr: &Attribute) -> Result, 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); }