From 5a74dd0232f38c696b8345b3f4c5af2a7acd12cf Mon Sep 17 00:00:00 2001 From: Isaac van Bakel Date: Thu, 11 Oct 2018 22:05:47 +0100 Subject: [PATCH] Added warning when elements have keyword names Fixes #91. To avoid erroneously preventing elements which are actually meant to be called `if` from being used, this is only a warning, with a suggestion of the template syntax. --- maud_macros/src/parse.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/maud_macros/src/parse.rs b/maud_macros/src/parse.rs index 7e511b06..4817bc76 100644 --- a/maud_macros/src/parse.rs +++ b/maud_macros/src/parse.rs @@ -148,7 +148,17 @@ impl Parser { } }, // Element - TokenTree::Ident(_) => { + TokenTree::Ident(ident) => { + let ident_string = ident.to_string(); + // Is this a keyword that's missing a '@'? + match ident_string.as_str() { + "if" | "while" | "for" | "match" | "let" => { + ident.span() + .warning(format!("found keyword `{}` - should this be a `@{}`?", ident_string, ident_string)) + .emit(); + } + _ => {} + } // `.try_namespaced_name()` should never fail as we've // already seen an `Ident` let name = self.try_namespaced_name().expect("identifier");