events-macros: Use lookahead1 instead of parse().is_ok()
This commit is contained in:
parent
7846142690
commit
8fadffa31d
@ -42,15 +42,19 @@ impl EventMeta {
|
||||
|
||||
impl Parse for EventMeta {
|
||||
fn parse(input: ParseStream) -> syn::Result<Self> {
|
||||
if input.parse::<Token![type]>().is_ok() {
|
||||
let lookahead = input.lookahead1();
|
||||
if lookahead.peek(Token![type]) {
|
||||
input.parse::<Token![type]>()?;
|
||||
input.parse::<Token![=]>()?;
|
||||
Ok(EventMeta::Type(input.parse::<LitStr>()?))
|
||||
} else if input.parse::<kw::skip_redaction>().is_ok() {
|
||||
input.parse().map(EventMeta::Type)
|
||||
} else if lookahead.peek(kw::skip_redaction) {
|
||||
input.parse::<kw::skip_redaction>()?;
|
||||
Ok(EventMeta::SkipRedacted)
|
||||
} else if input.parse::<kw::custom_redacted>().is_ok() {
|
||||
} else if lookahead.peek(kw::custom_redacted) {
|
||||
input.parse::<kw::custom_redacted>()?;
|
||||
Ok(EventMeta::CustomRedacted)
|
||||
} else {
|
||||
Err(syn::Error::new(input.span(), "not a recognized `ruma_event` attribute"))
|
||||
Err(lookahead.error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: not a recognized `ruma_event` attribute
|
||||
error: expected one of: `type`, `skip_redaction`, `custom_redacted`
|
||||
--> $DIR/03-invalid-event-type.rs:11:14
|
||||
|
|
||||
11 | #[ruma_event(event = "m.macro.test")]
|
||||
|
Loading…
x
Reference in New Issue
Block a user