From 3847880404bdf5418e2d6099ac8ed6143436a4f3 Mon Sep 17 00:00:00 2001 From: Chris Wong <lambda.fairy@gmail.com> Date: Sun, 12 Aug 2018 14:07:57 +1200 Subject: [PATCH] Span the whole attribute in duplicate attribute errors --- maud_macros/src/ast.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/maud_macros/src/ast.rs b/maud_macros/src/ast.rs index feed270..fd72129 100644 --- a/maud_macros/src/ast.rs +++ b/maud_macros/src/ast.rs @@ -86,8 +86,7 @@ impl Attr { } }, Attr::Id { ref name } => span_tokens(name.clone()), - // TODO - Attr::Attribute { ref attribute } => span_tokens(attribute.name.clone()), + Attr::Attribute { ref attribute } => attribute.span(), } } } @@ -139,6 +138,17 @@ pub struct Attribute { pub attr_type: AttrType, } +impl Attribute { + fn span(&self) -> Span { + let name_span = span_tokens(self.name.clone()); + if let Some(attr_type_span) = self.attr_type.span() { + name_span.join(attr_type_span).unwrap_or(name_span) + } else { + name_span + } + } +} + #[derive(Debug)] pub enum AttrType { Normal { @@ -149,12 +159,27 @@ pub enum AttrType { }, } +impl AttrType { + fn span(&self) -> Option<Span> { + match *self { + AttrType::Normal { ref value } => Some(value.span()), + AttrType::Empty { ref toggler } => toggler.as_ref().map(|toggler| toggler.span()), + } + } +} + #[derive(Debug)] pub struct Toggler { pub cond: TokenStream, pub cond_span: Span, } +impl Toggler { + fn span(&self) -> Span { + self.cond_span + } +} + #[derive(Debug)] pub struct MatchArm { pub head: TokenStream,