From d09c4182955b459a4699adaf9b045077308a1d1a Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 11 Feb 2024 10:06:36 -0800 Subject: [PATCH] Touch up PR 286 --- impl/src/attr.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/impl/src/attr.rs b/impl/src/attr.rs index 7bba4ad..a54a3b1 100644 --- a/impl/src/attr.rs +++ b/impl/src/attr.rs @@ -104,7 +104,7 @@ fn parse_error_attribute<'a>(attrs: &mut Attrs<'a>, attr: &'a Attribute) -> Resu return Ok(()); } - let fmt = input.parse()?; + let fmt: LitStr = input.parse()?; let args = parse_token_expr(input, false)?; let display = Display { original: attr, @@ -202,9 +202,9 @@ impl ToTokens for Display<'_> { let fmt = &self.fmt; let args = &self.args; - // Currently compiler is unable to generate as efficient code for - // write!(f, "text") as it does for f.write_str("text"), - // so handle it here when the literal string has no braces/no args. + // Currently `write!(f, "text")` produces less efficient code than + // `f.write_str("text")`. We recognize the case when the format string + // has no braces and no interpolated values, and generate simpler code. tokens.extend(if self.use_write_str { quote! { __formatter.write_str(#fmt)