Error on unexpected extra tokens in attribute

This commit is contained in:
Lukas Kalbertodt
2021-05-14 21:23:39 +02:00
parent 0f37618c19
commit 3fd3835fdf

View File

@@ -175,6 +175,7 @@ impl Parse for InternalAttr {
"default" => {
let _: Token![=] = input.parse()?;
let expr = Expr::from_lit(input.parse()?)?;
assert_empty(input)?;
Ok(Self::Default(expr))
}
@@ -182,3 +183,11 @@ impl Parse for InternalAttr {
}
}
}
fn assert_empty(input: ParseStream) -> Result<(), Error> {
if input.is_empty() {
Ok(())
} else {
Err(Error::new(input.span(), "unexpected tokens, expected no more tokens in this context"))
}
}