Skip to content

Commit bb1ad0a

Browse files
committed
Optimize format usage
Per #112156, using `&` in `format!` may cause a small perf delay, so I tried to clean up one module at a time format usage. This PR includes a few removals of the ref in format (they do compile locally without the ref), as well as a few format inlining for consistency.
1 parent 8771282 commit bb1ad0a

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl<'a> Parser<'a> {
238238
_ => unreachable!(),
239239
}
240240
.into();
241-
let invalid = format!("{}=", &sugg);
241+
let invalid = format!("{sugg}=");
242242
self.sess.emit_err(errors::InvalidComparisonOperator {
243243
span: sp,
244244
invalid: invalid.clone(),

compiler/rustc_parse/src/validate_attr.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,32 +157,32 @@ fn emit_malformed_attribute(
157157
matches!(name, sym::doc | sym::ignore | sym::inline | sym::link | sym::test | sym::bench)
158158
};
159159

160-
let error_msg = format!("malformed `{}` attribute input", name);
160+
let error_msg = format!("malformed `{name}` attribute input");
161161
let mut msg = "attribute must be of the form ".to_owned();
162162
let mut suggestions = vec![];
163163
let mut first = true;
164164
let inner = if style == ast::AttrStyle::Inner { "!" } else { "" };
165165
if template.word {
166166
first = false;
167-
let code = format!("#{}[{}]", inner, name);
168-
msg.push_str(&format!("`{}`", &code));
167+
let code = format!("#{inner}[{name}]");
168+
msg.push_str(&format!("`{code}`"));
169169
suggestions.push(code);
170170
}
171171
if let Some(descr) = template.list {
172172
if !first {
173173
msg.push_str(" or ");
174174
}
175175
first = false;
176-
let code = format!("#{}[{}({})]", inner, name, descr);
177-
msg.push_str(&format!("`{}`", &code));
176+
let code = format!("#{inner}[{name}({descr})]");
177+
msg.push_str(&format!("`{code}`"));
178178
suggestions.push(code);
179179
}
180180
if let Some(descr) = template.name_value_str {
181181
if !first {
182182
msg.push_str(" or ");
183183
}
184-
let code = format!("#{}[{} = \"{}\"]", inner, name, descr);
185-
msg.push_str(&format!("`{}`", &code));
184+
let code = format!("#{inner}[{name} = \"{descr}\"]");
185+
msg.push_str(&format!("`{code}`"));
186186
suggestions.push(code);
187187
}
188188
if should_warn(name) {

0 commit comments

Comments
 (0)