Skip to content

Commit 45e782d

Browse files
committed
review comments
1 parent 5963f7a commit 45e782d

File tree

2 files changed

+12
-44
lines changed

2 files changed

+12
-44
lines changed

compiler/rustc_middle/src/ty/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ impl<'tcx> TyCtxt<'tcx> {
248248
short
249249
}
250250

251+
/// When calling this after a `Diag` is constructed, the preferred way of doing so is
252+
/// `tcx.short_string(ty, diag.long_ty_path())`. The diagnostic itself is the one that keeps
253+
/// the existence of a "long type" anywhere in the diagnostic, so the note telling the user
254+
/// where we wrote the file to is only printed once. The path will use the type namespace.
251255
pub fn short_string<T>(self, p: T, path: &mut Option<PathBuf>) -> String
252256
where
253257
T: Copy + Hash + for<'a, 'b> Lift<TyCtxt<'b>, Lifted: Print<'b, FmtPrinter<'a, 'b>>>,

compiler/rustc_middle/src/ty/instance.rs

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use tracing::{debug, instrument};
1616
use crate::error;
1717
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
1818
use crate::ty::normalize_erasing_regions::NormalizationError;
19-
use crate::ty::print::{FmtPrinter, Printer};
19+
use crate::ty::print::{FmtPrinter, Print};
2020
use crate::ty::{
2121
self, EarlyBinder, GenericArgs, GenericArgsRef, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable,
2222
TypeVisitable, TypeVisitableExt, TypeVisitor,
@@ -388,51 +388,15 @@ fn type_length<'tcx>(item: impl TypeVisitable<TyCtxt<'tcx>>) -> usize {
388388
visitor.type_length
389389
}
390390

391-
pub fn fmt_instance(
392-
f: &mut fmt::Formatter<'_>,
393-
instance: Instance<'_>,
394-
type_length: Option<rustc_session::Limit>,
395-
) -> fmt::Result {
396-
ty::tls::with(|tcx| {
397-
let args = tcx.lift(instance.args).expect("could not lift for printing");
398-
399-
let mut cx = if let Some(type_length) = type_length {
400-
FmtPrinter::new_with_limit(tcx, Namespace::ValueNS, type_length)
401-
} else {
402-
FmtPrinter::new(tcx, Namespace::ValueNS)
403-
};
404-
cx.print_def_path(instance.def_id(), args)?;
405-
let s = cx.into_buffer();
406-
f.write_str(&s)
407-
})?;
408-
409-
match instance.def {
410-
InstanceKind::Item(_) => Ok(()),
411-
InstanceKind::VTableShim(_) => write!(f, " - shim(vtable)"),
412-
InstanceKind::ReifyShim(_, None) => write!(f, " - shim(reify)"),
413-
InstanceKind::ReifyShim(_, Some(ReifyReason::FnPtr)) => write!(f, " - shim(reify-fnptr)"),
414-
InstanceKind::ReifyShim(_, Some(ReifyReason::Vtable)) => write!(f, " - shim(reify-vtable)"),
415-
InstanceKind::ThreadLocalShim(_) => write!(f, " - shim(tls)"),
416-
InstanceKind::Intrinsic(_) => write!(f, " - intrinsic"),
417-
InstanceKind::Virtual(_, num) => write!(f, " - virtual#{num}"),
418-
InstanceKind::FnPtrShim(_, ty) => write!(f, " - shim({ty})"),
419-
InstanceKind::ClosureOnceShim { .. } => write!(f, " - shim"),
420-
InstanceKind::ConstructCoroutineInClosureShim { .. } => write!(f, " - shim"),
421-
InstanceKind::DropGlue(_, None) => write!(f, " - shim(None)"),
422-
InstanceKind::DropGlue(_, Some(ty)) => write!(f, " - shim(Some({ty}))"),
423-
InstanceKind::CloneShim(_, ty) => write!(f, " - shim({ty})"),
424-
InstanceKind::FnPtrAddrShim(_, ty) => write!(f, " - shim({ty})"),
425-
InstanceKind::FutureDropPollShim(_, proxy_ty, impl_ty) => {
426-
write!(f, " - dropshim({proxy_ty}-{impl_ty})")
427-
}
428-
InstanceKind::AsyncDropGlue(_, ty) => write!(f, " - shim({ty})"),
429-
InstanceKind::AsyncDropGlueCtorShim(_, ty) => write!(f, " - shim(Some({ty}))"),
430-
}
431-
}
432-
433391
impl<'tcx> fmt::Display for Instance<'tcx> {
434392
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
435-
fmt_instance(f, *self, None)
393+
ty::tls::with(|tcx| {
394+
let mut cx = FmtPrinter::new(tcx, Namespace::ValueNS);
395+
let instance = tcx.lift(*self).expect("could not lift for printing");
396+
instance.print(&mut cx)?;
397+
let s = cx.into_buffer();
398+
f.write_str(&s)
399+
})
436400
}
437401
}
438402

0 commit comments

Comments
 (0)