From 3fd3835fdfa32f574e07765cf8fcda84a969ba89 Mon Sep 17 00:00:00 2001 From: Lukas Kalbertodt Date: Fri, 14 May 2021 21:23:39 +0200 Subject: [PATCH] Error on unexpected extra tokens in attribute --- macro/src/ir.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/macro/src/ir.rs b/macro/src/ir.rs index fe375f5..a79f0da 100644 --- a/macro/src/ir.rs +++ b/macro/src/ir.rs @@ -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")) + } +}