diff --git a/src/stmt.rs b/src/stmt.rs index fb67feccb2..fd14aec26c 100644 --- a/src/stmt.rs +++ b/src/stmt.rs @@ -200,7 +200,7 @@ pub(crate) mod parsing { } } - if input.peek(Token![let]) { + if input.peek(Token![let]) && !input.peek(token::Group) { stmt_local(input, attrs).map(Stmt::Local) } else if input.peek(Token![pub]) || input.peek(Token![crate]) && !input.peek2(Token![::]) diff --git a/tests/test_stmt.rs b/tests/test_stmt.rs index 6223a6dfaa..61890a40ec 100644 --- a/tests/test_stmt.rs +++ b/tests/test_stmt.rs @@ -8,7 +8,7 @@ mod macros; use proc_macro2::{Delimiter, Group, Ident, Span, TokenStream, TokenTree}; -use quote::quote; +use quote::{quote, ToTokens as _}; use syn::parse::Parser as _; use syn::{Block, Stmt}; @@ -68,7 +68,6 @@ fn test_none_group() { TokenTree::Group(Group::new(Delimiter::Brace, TokenStream::new())), ]), ))]); - snapshot!(tokens as Stmt, @r###" Stmt::Item(Item::Fn { vis: Visibility::Inherited, @@ -83,6 +82,32 @@ fn test_none_group() { }, }) "###); + + let tokens = Group::new(Delimiter::None, quote!(let None = None)).to_token_stream(); + let stmts = Block::parse_within.parse2(tokens).unwrap(); + snapshot!(stmts, @r###" + [ + Stmt::Expr( + Expr::Group { + expr: Expr::Let { + pat: Pat::Ident { + ident: "None", + }, + expr: Expr::Path { + path: Path { + segments: [ + PathSegment { + ident: "None", + }, + ], + }, + }, + }, + }, + None, + ), + ] + "###); } #[test]