Auto merge of #94131 - Mark-Simulacrum:fmt-string, r=oli-obk

Always format to internal String in FmtPrinter

This avoids monomorphizing for different parameters, decreasing generic code
instantiated downstream from rustc_middle -- locally seeing 7% unoptimized LLVM IR
line wins on rustc_borrowck, for example.

We likely can't/shouldn't get rid of the Result-ness on most functions, though some
further cleanup avoiding fmt::Error where we now know it won't occur may be possible,
though somewhat painful -- fmt::Write is a pretty annoying API to work with in practice
when you're trying to use it infallibly.
This commit is contained in:
bors
2022-02-24 17:18:07 +00:00
10 changed files with 84 additions and 80 deletions

View File

@@ -22,10 +22,13 @@ use std::sync::Arc;
impl fmt::Debug for ty::TraitDef {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
ty::tls::with(|tcx| {
with_no_trimmed_paths!(
FmtPrinter::new(tcx, f, Namespace::TypeNS).print_def_path(self.def_id, &[])?
);
Ok(())
with_no_trimmed_paths!({
f.write_str(
&FmtPrinter::new(tcx, Namespace::TypeNS)
.print_def_path(self.def_id, &[])?
.into_buffer(),
)
})
})
}
}
@@ -33,10 +36,13 @@ impl fmt::Debug for ty::TraitDef {
impl fmt::Debug for ty::AdtDef {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
ty::tls::with(|tcx| {
with_no_trimmed_paths!(
FmtPrinter::new(tcx, f, Namespace::TypeNS).print_def_path(self.did, &[])?
);
Ok(())
with_no_trimmed_paths!({
f.write_str(
&FmtPrinter::new(tcx, Namespace::TypeNS)
.print_def_path(self.did, &[])?
.into_buffer(),
)
})
})
}
}