Skip to content

Commit 8a5c4d1

Browse files
committed
Use write_str when args only consists of trailing comma
1 parent f790bee commit 8a5c4d1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

impl/src/attr.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use proc_macro2::{Delimiter, Group, Span, TokenStream, TokenTree};
22
use quote::{format_ident, quote, ToTokens};
33
use std::collections::BTreeSet as Set;
4+
use syn::parse::discouraged::Speculative;
45
use syn::parse::ParseStream;
56
use syn::{
67
braced, bracketed, parenthesized, token, Attribute, Error, Ident, Index, LitInt, LitStr, Meta,
@@ -105,8 +106,18 @@ fn parse_error_attribute<'a>(attrs: &mut Attrs<'a>, attr: &'a Attribute) -> Resu
105106
}
106107

107108
let fmt: LitStr = input.parse()?;
108-
let args = parse_token_expr(input, false)?;
109+
110+
let ahead = input.fork();
111+
ahead.parse::<Option<Token![,]>>()?;
112+
let args = if ahead.is_empty() {
113+
input.advance_to(&ahead);
114+
TokenStream::new()
115+
} else {
116+
parse_token_expr(input, false)?
117+
};
118+
109119
let requires_fmt_machinery = !args.is_empty();
120+
110121
let display = Display {
111122
original: attr,
112123
fmt,

0 commit comments

Comments
 (0)