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 {
|
impl Parse for EventMeta {
|
||||||
fn parse(input: ParseStream) -> syn::Result<Self> {
|
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![=]>()?;
|
input.parse::<Token![=]>()?;
|
||||||
Ok(EventMeta::Type(input.parse::<LitStr>()?))
|
input.parse().map(EventMeta::Type)
|
||||||
} else if input.parse::<kw::skip_redaction>().is_ok() {
|
} else if lookahead.peek(kw::skip_redaction) {
|
||||||
|
input.parse::<kw::skip_redaction>()?;
|
||||||
Ok(EventMeta::SkipRedacted)
|
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)
|
Ok(EventMeta::CustomRedacted)
|
||||||
} else {
|
} 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
|
--> $DIR/03-invalid-event-type.rs:11:14
|
||||||
|
|
|
|
||||||
11 | #[ruma_event(event = "m.macro.test")]
|
11 | #[ruma_event(event = "m.macro.test")]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user