Skip to content

Commit

Permalink
Merge pull request #341 from dtolnay/parsescan
Browse files Browse the repository at this point in the history
Interleave Expr parsing and scanning better
  • Loading branch information
dtolnay authored Nov 4, 2024
2 parents 925f2dd + 40a53f7 commit c92ac99
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions impl/src/fmt.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -138,12 +138,7 @@ fn explicit_named_args(input: ParseStream) -> Result<Set<Ident>> {
}

fn try_explicit_named_args(input: ParseStream) -> Result<Set<Ident>> {
let scan_expr = if is_syn_full() {
|input: ParseStream| input.parse::<Expr>().map(drop)
} else {
scan_expr::scan_expr
};

let syn_full = is_syn_full();
let mut named_args = Set::new();

while !input.is_empty() {
Expand All @@ -156,6 +151,13 @@ fn try_explicit_named_args(input: ParseStream) -> Result<Set<Ident>> {
input.parse::<Token![=]>()?;
named_args.insert(ident);
}
if syn_full {
let ahead = input.fork();
if ahead.parse::<Expr>().is_ok() {
input.advance_to(&ahead);
continue;
}
}
scan_expr(input)?;
}

Expand Down

0 comments on commit c92ac99

Please sign in to comment.