Skip to content

Commit

Permalink
Merge pull request #1545 from dtolnay/groupedlet
Browse files Browse the repository at this point in the history
Fix None-delimited let expression in stmt position
  • Loading branch information
dtolnay committed Dec 11, 2023
2 parents 0ddfc27 + 384621a commit 9ec66d4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![::])
Expand Down
29 changes: 27 additions & 2 deletions tests/test_stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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,
Expand All @@ -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]
Expand Down

0 comments on commit 9ec66d4

Please sign in to comment.