Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Interleave Expr parsing and scanning better #341

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading