From 40a53f7f338e8cca0a3e589d01a19457c4794cc0 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 4 Nov 2024 11:21:12 -0500 Subject: [PATCH] Interleave Expr parsing and scanning better --- impl/src/fmt.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/impl/src/fmt.rs b/impl/src/fmt.rs index 153a423..1fc290e 100644 --- a/impl/src/fmt.rs +++ b/impl/src/fmt.rs @@ -1,6 +1,6 @@ use crate::ast::Field; use crate::attr::{Display, Trait}; -use crate::scan_expr; +use crate::scan_expr::scan_expr; use proc_macro2::{TokenStream, TokenTree}; use quote::{format_ident, quote, quote_spanned}; use std::collections::{BTreeSet as Set, HashMap as Map}; @@ -138,12 +138,7 @@ fn explicit_named_args(input: ParseStream) -> Result> { } fn try_explicit_named_args(input: ParseStream) -> Result> { - let scan_expr = if is_syn_full() { - |input: ParseStream| input.parse::().map(drop) - } else { - scan_expr::scan_expr - }; - + let syn_full = is_syn_full(); let mut named_args = Set::new(); while !input.is_empty() { @@ -156,6 +151,13 @@ fn try_explicit_named_args(input: ParseStream) -> Result> { input.parse::()?; named_args.insert(ident); } + if syn_full { + let ahead = input.fork(); + if ahead.parse::().is_ok() { + input.advance_to(&ahead); + continue; + } + } scan_expr(input)?; }