Skip to content

Commit 7c34eb3

Browse files
committed
style: simplify string interpolation
1 parent b32f181 commit 7c34eb3

File tree

43 files changed

+71
-78
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+71
-78
lines changed

crates/flycheck/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl FlycheckActor {
288288
Some(c) => c,
289289
None => continue,
290290
};
291-
let formatted_command = format!("{:?}", command);
291+
let formatted_command = format!("{command:?}");
292292

293293
tracing::debug!(?command, "will restart flycheck");
294294
let (sender, receiver) = unbounded();
@@ -301,8 +301,7 @@ impl FlycheckActor {
301301
}
302302
Err(error) => {
303303
self.report_progress(Progress::DidFailToRestart(format!(
304-
"Failed to run the following command: {} error={}",
305-
formatted_command, error
304+
"Failed to run the following command: {formatted_command} error={error}"
306305
)));
307306
}
308307
}
@@ -313,7 +312,7 @@ impl FlycheckActor {
313312
// Watcher finished
314313
let command_handle = self.command_handle.take().unwrap();
315314
self.command_receiver.take();
316-
let formatted_handle = format!("{:?}", command_handle);
315+
let formatted_handle = format!("{command_handle:?}");
317316

318317
let res = command_handle.join();
319318
if let Err(error) = &res {

crates/hir-ty/src/consteval/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,23 @@ fn check_answer(ra_fixture: &str, check: impl FnOnce(&[u8], &MemoryMap)) {
7373
Ok(t) => t,
7474
Err(e) => {
7575
let err = pretty_print_err(e, db);
76-
panic!("Error in evaluating goal: {}", err);
76+
panic!("Error in evaluating goal: {err}");
7777
}
7878
};
7979
match &r.data(Interner).value {
8080
chalk_ir::ConstValue::Concrete(c) => match &c.interned {
8181
ConstScalar::Bytes(b, mm) => {
8282
check(b, mm);
8383
}
84-
x => panic!("Expected number but found {:?}", x),
84+
x => panic!("Expected number but found {x:?}"),
8585
},
8686
_ => panic!("result of const eval wasn't a concrete const"),
8787
}
8888
}
8989

9090
fn pretty_print_err(e: ConstEvalError, db: TestDB) -> String {
9191
let mut err = String::new();
92-
let span_formatter = |file, range| format!("{:?} {:?}", file, range);
92+
let span_formatter = |file, range| format!("{file:?} {range:?}");
9393
match e {
9494
ConstEvalError::MirLowerError(e) => e.pretty_print(&mut err, &db, span_formatter),
9595
ConstEvalError::MirEvalError(e) => e.pretty_print(&mut err, &db, span_formatter),

crates/hir-ty/src/display.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ fn render_const_scalar(
670670
TyKind::FnDef(..) => ty.hir_fmt(f),
671671
TyKind::Function(_) | TyKind::Raw(_, _) => {
672672
let it = u128::from_le_bytes(pad16(b, false));
673-
write!(f, "{:#X} as ", it)?;
673+
write!(f, "{it:#X} as ")?;
674674
ty.hir_fmt(f)
675675
}
676676
TyKind::Array(ty, len) => {

crates/hir-ty/src/mir/eval.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ impl MirEvalError {
363363
)?;
364364
}
365365
Either::Right(closure) => {
366-
writeln!(f, "In {:?}", closure)?;
366+
writeln!(f, "In {closure:?}")?;
367367
}
368368
}
369369
let source_map = db.body_with_source_map(*def).1;
@@ -424,7 +424,7 @@ impl MirEvalError {
424424
| MirEvalError::StackOverflow
425425
| MirEvalError::CoerceUnsizedError(_)
426426
| MirEvalError::InternalError(_)
427-
| MirEvalError::InvalidVTableId(_) => writeln!(f, "{:?}", err)?,
427+
| MirEvalError::InvalidVTableId(_) => writeln!(f, "{err:?}")?,
428428
}
429429
Ok(())
430430
}

crates/hir-ty/src/mir/eval/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn check_panic(ra_fixture: &str, expected_panic: &str) {
7777
let (db, file_ids) = TestDB::with_many_files(ra_fixture);
7878
let file_id = *file_ids.last().unwrap();
7979
let e = eval_main(&db, file_id).unwrap_err();
80-
assert_eq!(e.is_panic().unwrap_or_else(|| panic!("unexpected error: {:?}", e)), expected_panic);
80+
assert_eq!(e.is_panic().unwrap_or_else(|| panic!("unexpected error: {e:?}")), expected_panic);
8181
}
8282

8383
#[test]

crates/hir-ty/src/mir/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl MirLowerError {
213213
| MirLowerError::LangItemNotFound(_)
214214
| MirLowerError::MutatingRvalue
215215
| MirLowerError::UnresolvedLabel
216-
| MirLowerError::UnresolvedUpvar(_) => writeln!(f, "{:?}", self)?,
216+
| MirLowerError::UnresolvedUpvar(_) => writeln!(f, "{self:?}")?,
217217
}
218218
Ok(())
219219
}

crates/hir/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,9 +2414,9 @@ impl Const {
24142414
let value_signed =
24152415
i128::from_le_bytes(mir::pad16(b, matches!(s, Scalar::Int(_))));
24162416
if value >= 10 {
2417-
return Ok(format!("{} ({:#X})", value_signed, value));
2417+
return Ok(format!("{value_signed} ({value:#X})"));
24182418
} else {
2419-
return Ok(format!("{}", value_signed));
2419+
return Ok(format!("{value_signed}"));
24202420
}
24212421
}
24222422
}

crates/ide-assists/src/handlers/auto_import.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<
140140
acc.add_group(
141141
&group_label,
142142
assist_id,
143-
format!("Import `{}`", import_name),
143+
format!("Import `{import_name}`"),
144144
range,
145145
|builder| {
146146
let scope = match scope.clone() {
@@ -165,7 +165,7 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<
165165
acc.add_group(
166166
&group_label,
167167
assist_id,
168-
format!("Import `{} as _`", import_name),
168+
format!("Import `{import_name} as _`"),
169169
range,
170170
|builder| {
171171
let scope = match scope.clone() {

crates/ide-assists/src/handlers/bool_to_enum.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ fn replace_usages(
228228

229229
edit.replace(
230230
prefix_expr.syntax().text_range(),
231-
format!("{} == Bool::False", inner_expr),
231+
format!("{inner_expr} == Bool::False"),
232232
);
233233
} else if let Some((record_field, initializer)) = name
234234
.as_name_ref()
@@ -275,7 +275,7 @@ fn replace_usages(
275275
} else if let Some(receiver) = find_method_call_expr_usage(&name) {
276276
edit.replace(
277277
receiver.syntax().text_range(),
278-
format!("({} == Bool::True)", receiver),
278+
format!("({receiver} == Bool::True)"),
279279
);
280280
} else if name.syntax().ancestors().find_map(ast::UseTree::cast).is_none() {
281281
// for any other usage in an expression, replace it with a check that it is the true variant

crates/ide-assists/src/handlers/destructure_struct_binding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ fn generate_field_names(ctx: &AssistContext<'_>, data: &StructEditData) -> Vec<(
242242
.iter()
243243
.enumerate()
244244
.map(|(index, _)| {
245-
let new_name = new_field_name((format!("_{}", index)).into(), &data.names_in_scope);
245+
let new_name = new_field_name((format!("_{index}")).into(), &data.names_in_scope);
246246
(index.to_string().into(), new_name)
247247
})
248248
.collect(),

0 commit comments

Comments
 (0)