events-macros: Use lookahead1 instead of parse().is_ok()

This commit is contained in:
Akshay 2021-02-06 22:53:40 +05:30 committed by GitHub
parent 7846142690
commit 8fadffa31d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -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())
}
}
}

View File

@ -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")]