Make Attribute::interprete_meta understand booleans
So proc_macro2::Literal doesn't have any boolean related variant which
means that a boolean value is put in a TokenNode::Term and not a
TokenNode::Literal which in turn means that those values were ignored
and resulted in an impossibility to parse booleans in an attribute.
Fixes #346
diff --git a/src/attr.rs b/src/attr.rs
index 06af8a5..3c9e625 100644
--- a/src/attr.rs
+++ b/src/attr.rs
@@ -133,6 +133,17 @@
eq_token: Token,
lit: Lit::new(lit.clone(), tts[1].span),
}));
+ } else if let TokenNode::Term(ref term) = tts[1].kind {
+ match term.as_str() {
+ v @ "true" | v @ "false" => {
+ return Some(Meta::NameValue(MetaNameValue {
+ ident: *name,
+ eq_token: Token,
+ lit: Lit::Bool(LitBool { value: v == "true", span: tts[1].span }),
+ }));
+ },
+ _ => {}
+ }
}
}
}
@@ -161,6 +172,18 @@
lit: Lit::new(lit.clone(), tts[2].span),
};
return Some((Meta::NameValue(pair).into(), &tts[3..]));
+ } else if let TokenNode::Term(ref term) = tts[2].kind {
+ match term.as_str() {
+ v @ "true" | v @ "false" => {
+ let pair = MetaNameValue {
+ ident: Ident::new(sym.as_str(), tts[0].span),
+ eq_token: Token,
+ lit: Lit::Bool(LitBool { value: v == "true", span: tts[2].span }),
+ };
+ return Some((Meta::NameValue(pair).into(), &tts[3..]));
+ },
+ _ => {}
+ }
}
}
}