Skip to content

Commit

Permalink
More robust scanning for fmt argument expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Nov 2, 2024
1 parent c005055 commit 2585669
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions impl/src/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::ast::Field;
use crate::attr::{Display, Trait};
use crate::scan_expr::scan_expr;
use proc_macro2::TokenTree;
use quote::{format_ident, quote_spanned};
use std::collections::{BTreeSet as Set, HashMap as Map};
Expand Down Expand Up @@ -121,14 +122,16 @@ fn explicit_named_args(input: ParseStream) -> Result<Set<Ident>> {
let mut named_args = Set::new();

while !input.is_empty() {
if input.peek(Token![,]) && input.peek2(Ident::peek_any) && input.peek3(Token![=]) {
input.parse::<Token![,]>()?;
input.parse::<Token![,]>()?;
if input.is_empty() {
break;
}
if input.peek(Ident::peek_any) && input.peek2(Token![=]) && !input.peek2(Token![==]) {
let ident = input.call(Ident::parse_any)?;
input.parse::<Token![=]>()?;
named_args.insert(ident);
} else {
input.parse::<TokenTree>()?;
}
scan_expr(input)?;
}

Ok(named_args)
Expand Down

0 comments on commit 2585669

Please sign in to comment.