Skip to content

Commit a1a94b1

Browse files
Improve code readability by moving fmt args directly into the string
1 parent 3071e0a commit a1a94b1

35 files changed

+261
-300
lines changed

src/librustdoc/clean/auto_trait.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ where
4646
let tcx = self.cx.tcx;
4747
let trait_ref = ty::Binder::dummy(ty::TraitRef::new(tcx, trait_def_id, [ty]));
4848
if !self.cx.generated_synthetics.insert((ty, trait_def_id)) {
49-
debug!("get_auto_trait_impl_for({:?}): already generated, aborting", trait_ref);
49+
debug!("get_auto_trait_impl_for({trait_ref:?}): already generated, aborting");
5050
return None;
5151
}
5252

@@ -140,7 +140,7 @@ where
140140
let ty = tcx.type_of(item_def_id).instantiate_identity();
141141
let f = auto_trait::AutoTraitFinder::new(tcx);
142142

143-
debug!("get_auto_trait_impls({:?})", ty);
143+
debug!("get_auto_trait_impls({ty:?})");
144144
let auto_traits: Vec<_> = self.cx.auto_traits.to_vec();
145145
let mut auto_traits: Vec<Item> = auto_traits
146146
.into_iter()
@@ -164,7 +164,7 @@ where
164164
region_name(region)
165165
.map(|name| {
166166
names_map.get(&name).unwrap_or_else(|| {
167-
panic!("Missing lifetime with name {:?} for {:?}", name.as_str(), region)
167+
panic!("Missing lifetime with name {:?} for {region:?}", name.as_str())
168168
})
169169
})
170170
.unwrap_or(&Lifetime::statik())
@@ -372,7 +372,7 @@ where
372372

373373
let output = output.as_ref().cloned().map(Box::new);
374374
if old_output.is_some() && old_output != output {
375-
panic!("Output mismatch for {:?} {:?} {:?}", ty, old_output, output);
375+
panic!("Output mismatch for {ty:?} {old_output:?} {output:?}");
376376
}
377377

378378
let new_params = GenericArgs::Parenthesized { inputs: old_input, output };
@@ -462,7 +462,7 @@ where
462462
);
463463
let mut generic_params = raw_generics.params;
464464

465-
debug!("param_env_to_generics({:?}): generic_params={:?}", item_def_id, generic_params);
465+
debug!("param_env_to_generics({item_def_id:?}): generic_params={generic_params:?}");
466466

467467
let mut has_sized = FxHashSet::default();
468468
let mut ty_to_bounds: FxHashMap<_, FxHashSet<_>> = Default::default();
@@ -623,7 +623,7 @@ where
623623
// loop
624624
ty_to_traits.entry(ty.clone()).or_default().insert(trait_.clone());
625625
}
626-
_ => panic!("Unexpected LHS {:?} for {:?}", lhs, item_def_id),
626+
_ => panic!("Unexpected LHS {lhs:?} for {item_def_id:?}"),
627627
}
628628
}
629629
};
@@ -710,7 +710,7 @@ where
710710
/// involved (impls rarely have more than a few bounds) means that it
711711
/// shouldn't matter in practice.
712712
fn unstable_debug_sort<T: Debug>(&self, vec: &mut [T]) {
713-
vec.sort_by_cached_key(|x| format!("{:?}", x))
713+
vec.sort_by_cached_key(|x| format!("{x:?}"))
714714
}
715715

716716
fn is_fn_trait(&self, path: &Path) -> bool {

src/librustdoc/clean/blanket_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
1717
let param_env = cx.tcx.param_env(item_def_id);
1818
let ty = cx.tcx.type_of(item_def_id);
1919

20-
trace!("get_blanket_impls({:?})", ty);
20+
trace!("get_blanket_impls({ty:?})");
2121
let mut impls = Vec::new();
2222
for trait_def_id in cx.tcx.all_traits() {
2323
if !cx.cache.effective_visibilities.is_reachable(cx.tcx, trait_def_id)
@@ -72,7 +72,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
7272
.into_iter()
7373
.chain(Some(ty::Binder::dummy(impl_trait_ref).to_predicate(infcx.tcx)));
7474
for predicate in predicates {
75-
debug!("testing predicate {:?}", predicate);
75+
debug!("testing predicate {predicate:?}");
7676
let obligation = traits::Obligation::new(
7777
infcx.tcx,
7878
traits::ObligationCause::dummy(),

src/librustdoc/clean/cfg.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,9 @@ impl<'a> fmt::Display for Display<'a> {
434434
}
435435
if let (true, Cfg::Cfg(_, Some(feat))) = (short_longhand, sub_cfg) {
436436
if self.1.is_html() {
437-
write!(fmt, "<code>{}</code>", feat)?;
437+
write!(fmt, "<code>{feat}</code>")?;
438438
} else {
439-
write!(fmt, "`{}`", feat)?;
439+
write!(fmt, "`{feat}`")?;
440440
}
441441
} else {
442442
write_with_opt_paren(fmt, !sub_cfg.is_all(), Display(sub_cfg, self.1))?;
@@ -471,9 +471,9 @@ impl<'a> fmt::Display for Display<'a> {
471471
}
472472
if let (true, Cfg::Cfg(_, Some(feat))) = (short_longhand, sub_cfg) {
473473
if self.1.is_html() {
474-
write!(fmt, "<code>{}</code>", feat)?;
474+
write!(fmt, "<code>{feat}</code>")?;
475475
} else {
476-
write!(fmt, "`{}`", feat)?;
476+
write!(fmt, "`{feat}`")?;
477477
}
478478
} else {
479479
write_with_opt_paren(fmt, !sub_cfg.is_simple(), Display(sub_cfg, self.1))?;
@@ -551,21 +551,21 @@ impl<'a> fmt::Display for Display<'a> {
551551
"sgx" => "SGX",
552552
_ => "",
553553
},
554-
(sym::target_endian, Some(endian)) => return write!(fmt, "{}-endian", endian),
555-
(sym::target_pointer_width, Some(bits)) => return write!(fmt, "{}-bit", bits),
554+
(sym::target_endian, Some(endian)) => return write!(fmt, "{endian}-endian"),
555+
(sym::target_pointer_width, Some(bits)) => return write!(fmt, "{bits}-bit"),
556556
(sym::target_feature, Some(feat)) => match self.1 {
557557
Format::LongHtml => {
558-
return write!(fmt, "target feature <code>{}</code>", feat);
558+
return write!(fmt, "target feature <code>{feat}</code>");
559559
}
560-
Format::LongPlain => return write!(fmt, "target feature `{}`", feat),
561-
Format::ShortHtml => return write!(fmt, "<code>{}</code>", feat),
560+
Format::LongPlain => return write!(fmt, "target feature `{feat}`"),
561+
Format::ShortHtml => return write!(fmt, "<code>{feat}</code>"),
562562
},
563563
(sym::feature, Some(feat)) => match self.1 {
564564
Format::LongHtml => {
565-
return write!(fmt, "crate feature <code>{}</code>", feat);
565+
return write!(fmt, "crate feature <code>{feat}</code>");
566566
}
567-
Format::LongPlain => return write!(fmt, "crate feature `{}`", feat),
568-
Format::ShortHtml => return write!(fmt, "<code>{}</code>", feat),
567+
Format::LongPlain => return write!(fmt, "crate feature `{feat}`"),
568+
Format::ShortHtml => return write!(fmt, "<code>{feat}</code>"),
569569
},
570570
_ => "",
571571
};
@@ -580,12 +580,12 @@ impl<'a> fmt::Display for Display<'a> {
580580
Escape(v.as_str())
581581
)
582582
} else {
583-
write!(fmt, r#"`{}="{}"`"#, name, v)
583+
write!(fmt, r#"`{name}="{v}"`"#)
584584
}
585585
} else if self.1.is_html() {
586586
write!(fmt, "<code>{}</code>", Escape(name.as_str()))
587587
} else {
588-
write!(fmt, "`{}`", name)
588+
write!(fmt, "`{name}`")
589589
}
590590
}
591591
}

src/librustdoc/clean/inline.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub(crate) fn try_inline(
5050
}
5151
let mut ret = Vec::new();
5252

53-
debug!("attrs={:?}", attrs);
53+
debug!("attrs={attrs:?}");
5454

5555
let attrs_without_docs = attrs.map(|(attrs, def_id)| {
5656
(attrs.into_iter().filter(|a| a.doc_str().is_none()).cloned().collect::<Vec<_>>(), def_id)
@@ -529,7 +529,7 @@ pub(crate) fn build_impl(
529529
}
530530

531531
let (merged_attrs, cfg) = merge_attrs(cx, load_attrs(cx, did), attrs);
532-
trace!("merged_attrs={:?}", merged_attrs);
532+
trace!("merged_attrs={merged_attrs:?}");
533533

534534
trace!(
535535
"build_impl: impl {:?} for {:?}",
@@ -781,7 +781,7 @@ pub(crate) fn record_extern_trait(cx: &mut DocContext<'_>, did: DefId) {
781781
cx.active_extern_traits.insert(did);
782782
}
783783

784-
debug!("record_extern_trait: {:?}", did);
784+
debug!("record_extern_trait: {did:?}");
785785
let trait_ = build_external_trait(cx, did);
786786

787787
cx.external_traits.borrow_mut().insert(did, trait_);

src/librustdoc/clean/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ pub(crate) fn clean_trait_ref_with_bindings<'tcx>(
215215
) -> Path {
216216
let kind = cx.tcx.def_kind(trait_ref.def_id()).into();
217217
if !matches!(kind, ItemType::Trait | ItemType::TraitAlias) {
218-
span_bug!(cx.tcx.def_span(trait_ref.def_id()), "`TraitRef` had unexpected kind {:?}", kind);
218+
span_bug!(cx.tcx.def_span(trait_ref.def_id()), "`TraitRef` had unexpected kind {kind:?}");
219219
}
220220
inline::record_extern_fqn(cx, trait_ref.def_id(), kind);
221221
let path =
@@ -304,7 +304,7 @@ pub(crate) fn clean_middle_region<'tcx>(region: ty::Region<'tcx>) -> Option<Life
304304
| ty::ReError(_)
305305
| ty::RePlaceholder(..)
306306
| ty::ReErased => {
307-
debug!("cannot clean region {:?}", region);
307+
debug!("cannot clean region {region:?}");
308308
None
309309
}
310310
}
@@ -1867,11 +1867,11 @@ fn normalize<'tcx>(
18671867
.map(|resolved| infcx.resolve_vars_if_possible(resolved.value));
18681868
match normalized {
18691869
Ok(normalized_value) => {
1870-
debug!("normalized {:?} to {:?}", ty, normalized_value);
1870+
debug!("normalized {ty:?} to {normalized_value:?}");
18711871
Some(normalized_value)
18721872
}
18731873
Err(err) => {
1874-
debug!("failed to normalize {:?}: {:?}", ty, err);
1874+
debug!("failed to normalize {ty:?}: {err:?}");
18751875
None
18761876
}
18771877
}

src/librustdoc/clean/types.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl ItemId {
7878
#[track_caller]
7979
pub(crate) fn expect_def_id(self) -> DefId {
8080
self.as_def_id()
81-
.unwrap_or_else(|| panic!("ItemId::expect_def_id: `{:?}` isn't a DefId", self))
81+
.unwrap_or_else(|| panic!("ItemId::expect_def_id: `{self:?}` isn't a DefId"))
8282
}
8383

8484
#[inline]
@@ -352,7 +352,7 @@ fn is_field_vis_inherited(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
352352
match tcx.def_kind(parent) {
353353
DefKind::Struct | DefKind::Union => false,
354354
DefKind::Variant => true,
355-
parent_kind => panic!("unexpected parent kind: {:?}", parent_kind),
355+
parent_kind => panic!("unexpected parent kind: {parent_kind:?}"),
356356
}
357357
}
358358

@@ -436,7 +436,7 @@ impl Item {
436436
attrs: Box<Attributes>,
437437
cfg: Option<Arc<Cfg>>,
438438
) -> Item {
439-
trace!("name={:?}, def_id={:?} cfg={:?}", name, def_id, cfg);
439+
trace!("name={name:?}, def_id={def_id:?} cfg={cfg:?}");
440440

441441
Item {
442442
item_id: def_id.into(),

src/librustdoc/clean/utils.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ pub(crate) fn build_deref_target_impls(
218218

219219
pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
220220
use rustc_hir::*;
221-
debug!("trying to get a name from pattern: {:?}", p);
221+
debug!("trying to get a name from pattern: {p:?}");
222222

223223
Symbol::intern(&match p.kind {
224224
PatKind::Wild | PatKind::Struct(..) => return kw::Underscore,
@@ -461,7 +461,7 @@ pub(crate) fn print_const_expr(tcx: TyCtxt<'_>, body: hir::BodyId) -> String {
461461

462462
/// Given a type Path, resolve it to a Type using the TyCtxt
463463
pub(crate) fn resolve_type(cx: &mut DocContext<'_>, path: Path) -> Type {
464-
debug!("resolve_type({:?})", path);
464+
debug!("resolve_type({path:?})");
465465

466466
match path.res {
467467
Res::PrimTy(p) => Primitive(PrimitiveType::from(p)),
@@ -500,7 +500,7 @@ pub(crate) fn get_auto_trait_and_blanket_impls(
500500
/// [`href()`]: crate::html::format::href
501501
pub(crate) fn register_res(cx: &mut DocContext<'_>, res: Res) -> DefId {
502502
use DefKind::*;
503-
debug!("register_res({:?})", res);
503+
debug!("register_res({res:?})");
504504

505505
let (kind, did) = match res {
506506
Res::Def(
@@ -523,7 +523,7 @@ pub(crate) fn register_res(cx: &mut DocContext<'_>, res: Res) -> DefId {
523523
did,
524524
) => (kind.into(), did),
525525

526-
_ => panic!("register_res: unexpected {:?}", res),
526+
_ => panic!("register_res: unexpected {res:?}"),
527527
};
528528
if did.is_local() {
529529
return did;
@@ -601,7 +601,7 @@ pub(super) fn render_macro_arms<'a>(
601601
) -> String {
602602
let mut out = String::new();
603603
for matcher in matchers {
604-
writeln!(out, " {} => {{ ... }}{}", render_macro_matcher(tcx, matcher), arm_delim)
604+
writeln!(out, " {} => {{ ... }}{arm_delim}", render_macro_matcher(tcx, matcher))
605605
.unwrap();
606606
}
607607
out
@@ -618,20 +618,18 @@ pub(super) fn display_macro_source(
618618
let matchers = def.body.tokens.chunks(4).map(|arm| &arm[0]);
619619

620620
if def.macro_rules {
621-
format!("macro_rules! {} {{\n{}}}", name, render_macro_arms(cx.tcx, matchers, ";"))
621+
format!("macro_rules! {name} {{\n{}}}", render_macro_arms(cx.tcx, matchers, ";"))
622622
} else {
623623
if matchers.len() <= 1 {
624624
format!(
625-
"{}macro {}{} {{\n ...\n}}",
625+
"{}macro {name}{} {{\n ...\n}}",
626626
visibility_to_src_with_space(Some(vis), cx.tcx, def_id),
627-
name,
628627
matchers.map(|matcher| render_macro_matcher(cx.tcx, matcher)).collect::<String>(),
629628
)
630629
} else {
631630
format!(
632-
"{}macro {} {{\n{}}}",
631+
"{}macro {name} {{\n{}}}",
633632
visibility_to_src_with_space(Some(vis), cx.tcx, def_id),
634-
name,
635633
render_macro_arms(cx.tcx, matchers, ","),
636634
)
637635
}

0 commit comments

Comments
 (0)