Skip to content

Commit

Permalink
Use write_str when args only consists of trailing comma
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Feb 11, 2024
1 parent f790bee commit 8a5c4d1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion impl/src/attr.rs
@@ -1,6 +1,7 @@
use proc_macro2::{Delimiter, Group, Span, TokenStream, TokenTree};
use quote::{format_ident, quote, ToTokens};
use std::collections::BTreeSet as Set;
use syn::parse::discouraged::Speculative;
use syn::parse::ParseStream;
use syn::{
braced, bracketed, parenthesized, token, Attribute, Error, Ident, Index, LitInt, LitStr, Meta,
Expand Down Expand Up @@ -105,8 +106,18 @@ fn parse_error_attribute<'a>(attrs: &mut Attrs<'a>, attr: &'a Attribute) -> Resu
}

let fmt: LitStr = input.parse()?;
let args = parse_token_expr(input, false)?;

let ahead = input.fork();
ahead.parse::<Option<Token![,]>>()?;
let args = if ahead.is_empty() {
input.advance_to(&ahead);
TokenStream::new()
} else {
parse_token_expr(input, false)?
};

let requires_fmt_machinery = !args.is_empty();

let display = Display {
original: attr,
fmt,
Expand Down

0 comments on commit 8a5c4d1

Please sign in to comment.