Skip to content

Commit

Permalink
Added warning when elements have keyword names
Browse files Browse the repository at this point in the history
Fixes lambda-fairy#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.
  • Loading branch information
ivanbakel committed Oct 11, 2018
1 parent d2af7c3 commit 5a74dd0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion maud_macros/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 5a74dd0

Please sign in to comment.