diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs
index aa539516d5e50..c4d130e19dd50 100644
--- a/compiler/rustc_const_eval/src/interpret/validity.rs
+++ b/compiler/rustc_const_eval/src/interpret/validity.rs
@@ -772,9 +772,9 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
// MyNewtype and then the scalar in there).
match op.layout.abi {
Abi::Uninhabited => {
- throw_validation_failure!(self.path,
- { "a value of uninhabited type {:?}", op.layout.ty }
- );
+ ty::print::with_no_trimmed_paths!(throw_validation_failure!(self.path,
+ { "a value of uninhabited type {}", op.layout.ty }
+ ));
}
Abi::Scalar(scalar_layout) => {
if !scalar_layout.is_uninit_valid() {
diff --git a/compiler/rustc_middle/src/mir/graphviz.rs b/compiler/rustc_middle/src/mir/graphviz.rs
index 5de56dad07a41..cdfbc0fc0a3af 100644
--- a/compiler/rustc_middle/src/mir/graphviz.rs
+++ b/compiler/rustc_middle/src/mir/graphviz.rs
@@ -3,7 +3,6 @@ use rustc_graphviz as dot;
use rustc_hir::def_id::DefId;
use rustc_middle::mir::*;
use rustc_middle::ty::{self, TyCtxt};
-use std::fmt::Debug;
use std::io::{self, Write};
use super::generic_graph::mir_fn_to_generic_graph;
@@ -122,13 +121,13 @@ fn write_graph_label<'tcx, W: std::fmt::Write>(
w,
r#"debug {} => {};
"#,
var_debug_info.name,
- escape(&var_debug_info.value),
+ dot::escape_html(&format!("{:?}", &var_debug_info.value)),
)?;
}
Ok(())
}
-fn escape(t: &T) -> String {
- dot::escape_html(&format!("{:?}", t))
+fn escape(t: &T) -> String {
+ dot::escape_html(&format!("{}", t))
}
diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs
index 552af589bec59..75868544b855a 100644
--- a/compiler/rustc_middle/src/mir/mod.rs
+++ b/compiler/rustc_middle/src/mir/mod.rs
@@ -1061,7 +1061,7 @@ impl<'tcx> Debug for VarDebugInfoContents<'tcx> {
VarDebugInfoContents::Const(c) => write!(fmt, "{}", c),
VarDebugInfoContents::Place(p) => write!(fmt, "{:?}", p),
VarDebugInfoContents::Composite { ty, fragments } => {
- write!(fmt, "{:?}{{ ", ty)?;
+ ty::print::with_no_trimmed_paths!(write!(fmt, "{}{{ ", ty))?;
for f in fragments.iter() {
write!(fmt, "{:?}, ", f)?;
}
@@ -1722,7 +1722,8 @@ impl Debug for Place<'_> {
write!(fmt, ")")?;
}
ProjectionElem::Field(field, ty) => {
- write!(fmt, ".{:?}: {:?})", field.index(), ty)?;
+ let ty = ty::print::with_no_trimmed_paths!(format!("{ty}"));
+ write!(fmt, ".{:?}: {})", field.index(), ty)?;
}
ProjectionElem::Index(ref index) => {
write!(fmt, "[{:?}]", index)?;
@@ -2009,7 +2010,8 @@ impl<'tcx> Debug for Rvalue<'tcx> {
}
Len(ref a) => write!(fmt, "Len({:?})", a),
Cast(ref kind, ref place, ref ty) => {
- write!(fmt, "{:?} as {:?} ({:?})", place, ty, kind)
+ let ty = ty::print::with_no_trimmed_paths!(format!("{ty}"));
+ write!(fmt, "{:?} as {} ({:?})", place, ty, kind)
}
BinaryOp(ref op, box (ref a, ref b)) => write!(fmt, "{:?}({:?}, {:?})", op, a, b),
CheckedBinaryOp(ref op, box (ref a, ref b)) => {
@@ -2017,7 +2019,10 @@ impl<'tcx> Debug for Rvalue<'tcx> {
}
UnaryOp(ref op, ref a) => write!(fmt, "{:?}({:?})", op, a),
Discriminant(ref place) => write!(fmt, "discriminant({:?})", place),
- NullaryOp(ref op, ref t) => write!(fmt, "{:?}({:?})", op, t),
+ NullaryOp(ref op, ref t) => {
+ let t = ty::print::with_no_trimmed_paths!(format!("{t}"));
+ write!(fmt, "{:?}({})", op, t)
+ }
ThreadLocalRef(did) => ty::tls::with(|tcx| {
let muta = tcx.static_mutability(did).unwrap().prefix_str();
write!(fmt, "&/*tls*/ {}{}", muta, tcx.def_path_str(did))
@@ -2144,7 +2149,8 @@ impl<'tcx> Debug for Rvalue<'tcx> {
}
ShallowInitBox(ref place, ref ty) => {
- write!(fmt, "ShallowInitBox({:?}, {:?})", place, ty)
+ let ty = ty::print::with_no_trimmed_paths!(format!("{ty}"));
+ write!(fmt, "ShallowInitBox({:?}, {})", place, ty)
}
}
}
diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs
index 40289af257ff4..9d363f0afbf87 100644
--- a/compiler/rustc_middle/src/mir/pretty.rs
+++ b/compiler/rustc_middle/src/mir/pretty.rs
@@ -582,8 +582,14 @@ fn write_scope_tree(
let mut_str = if local_decl.mutability == Mutability::Mut { "mut " } else { "" };
- let mut indented_decl =
- format!("{0:1$}let {2}{3:?}: {4:?}", INDENT, indent, mut_str, local, local_decl.ty);
+ let mut indented_decl = format!(
+ "{0:1$}let {2}{3:?}: {4}",
+ INDENT,
+ indent,
+ mut_str,
+ local,
+ ty::print::with_no_trimmed_paths!(format!("{}", local_decl.ty))
+ );
if let Some(user_ty) = &local_decl.user_ty {
for user_ty in user_ty.projections() {
write!(indented_decl, " as {:?}", user_ty).unwrap();
@@ -1049,11 +1055,11 @@ fn write_user_type_annotations(
for (index, annotation) in body.user_type_annotations.iter_enumerated() {
writeln!(
w,
- "| {:?}: user_ty: {:?}, span: {}, inferred_ty: {:?}",
+ "| {:?}: user_ty: {:?}, span: {}, inferred_ty: {}",
index.index(),
annotation.user_ty,
tcx.sess.source_map().span_to_embeddable_string(annotation.span),
- annotation.inferred_ty,
+ ty::print::with_no_trimmed_paths!(format!("{}", annotation.inferred_ty)),
)?;
}
if !body.user_type_annotations.is_empty() {
diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs
index 034aab0c38ea3..f3b0d6e095cdf 100644
--- a/compiler/rustc_middle/src/ty/structural_impls.rs
+++ b/compiler/rustc_middle/src/ty/structural_impls.rs
@@ -108,7 +108,7 @@ impl<'tcx> fmt::Debug for ty::TraitRef<'tcx> {
impl<'tcx> fmt::Debug for Ty<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- with_no_trimmed_paths!(fmt::Display::fmt(self, f))
+ with_no_trimmed_paths!(fmt::Debug::fmt(self.kind(), f))
}
}
diff --git a/compiler/rustc_middle/src/ty/typeck_results.rs b/compiler/rustc_middle/src/ty/typeck_results.rs
index 79a6c730d7159..b9a6afaacf7e6 100644
--- a/compiler/rustc_middle/src/ty/typeck_results.rs
+++ b/compiler/rustc_middle/src/ty/typeck_results.rs
@@ -703,7 +703,7 @@ impl<'tcx> CanonicalUserType<'tcx> {
/// A user-given type annotation attached to a constant. These arise
/// from constants that are named via paths, like `Foo::::new` and
/// so forth.
-#[derive(Copy, Clone, Debug, PartialEq, TyEncodable, TyDecodable)]
+#[derive(Copy, Clone, PartialEq, TyEncodable, TyDecodable)]
#[derive(Eq, Hash, HashStable, TypeFoldable, TypeVisitable, Lift)]
pub enum UserType<'tcx> {
Ty(Ty<'tcx>),
@@ -712,3 +712,14 @@ pub enum UserType<'tcx> {
/// given substitutions applied.
TypeOf(DefId, UserSubsts<'tcx>),
}
+
+impl<'tcx> std::fmt::Debug for UserType<'tcx> {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ match self {
+ Self::Ty(arg0) => {
+ ty::print::with_no_trimmed_paths!(f.write_fmt(format_args!("Ty({})", arg0)))
+ }
+ Self::TypeOf(arg0, arg1) => f.debug_tuple("TypeOf").field(arg0).field(arg1).finish(),
+ }
+ }
+}
diff --git a/compiler/rustc_passes/src/layout_test.rs b/compiler/rustc_passes/src/layout_test.rs
index 827d86780aa8c..acce73ae785bd 100644
--- a/compiler/rustc_passes/src/layout_test.rs
+++ b/compiler/rustc_passes/src/layout_test.rs
@@ -69,13 +69,15 @@ fn dump_layout_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribute) {
}
sym::debug => {
- let normalized_ty = format!(
- "{:?}",
- tcx.normalize_erasing_regions(
- param_env.with_reveal_all_normalized(tcx),
- ty,
- )
- );
+ let normalized_ty =
+ rustc_middle::ty::print::with_no_trimmed_paths!(format!(
+ "{}",
+ tcx.normalize_erasing_regions(
+ param_env.with_reveal_all_normalized(tcx),
+ ty,
+ )
+ ));
+
let ty_layout = format!("{:#?}", *ty_layout);
tcx.sess.emit_err(LayoutOf {
span: tcx.def_span(item_def_id.to_def_id()),
diff --git a/compiler/rustc_target/src/abi/call/mod.rs b/compiler/rustc_target/src/abi/call/mod.rs
index a0730fbb650dc..7b394b895f345 100644
--- a/compiler/rustc_target/src/abi/call/mod.rs
+++ b/compiler/rustc_target/src/abi/call/mod.rs
@@ -458,12 +458,18 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
/// Information about how to pass an argument to,
/// or return a value from, a function, under some ABI.
-#[derive(PartialEq, Eq, Hash, Debug, HashStable_Generic)]
+#[derive(PartialEq, Eq, Hash, HashStable_Generic)]
pub struct ArgAbi<'a, Ty> {
pub layout: TyAndLayout<'a, Ty>,
pub mode: PassMode,
}
+impl<'a, Ty: fmt::Debug + fmt::Display> fmt::Debug for ArgAbi<'a, Ty> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.debug_struct("ArgAbi").field("layout", &self.layout).field("mode", &self.mode).finish()
+ }
+}
+
impl<'a, Ty> ArgAbi<'a, Ty> {
pub fn new(
cx: &impl HasDataLayout,
@@ -605,7 +611,7 @@ pub enum Conv {
///
/// I will do my best to describe this structure, but these
/// comments are reverse-engineered and may be inaccurate. -NDM
-#[derive(PartialEq, Eq, Hash, Debug, HashStable_Generic)]
+#[derive(PartialEq, Eq, Hash, HashStable_Generic)]
pub struct FnAbi<'a, Ty> {
/// The LLVM types of each argument.
pub args: Box<[ArgAbi<'a, Ty>]>,
@@ -626,6 +632,19 @@ pub struct FnAbi<'a, Ty> {
pub can_unwind: bool,
}
+impl<'a, Ty: fmt::Debug + fmt::Display> fmt::Debug for FnAbi<'a, Ty> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.debug_struct("FnAbi")
+ .field("args", &self.args)
+ .field("ret", &self.ret)
+ .field("c_variadic", &self.c_variadic)
+ .field("fixed_count", &self.fixed_count)
+ .field("conv", &self.conv)
+ .field("can_unwind", &self.can_unwind)
+ .finish()
+ }
+}
+
/// Error produced by attempting to adjust a `FnAbi`, for a "foreign" ABI.
#[derive(Copy, Clone, Debug, HashStable_Generic)]
pub enum AdjustForForeignAbiError {
diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs
index 39761baf1bc29..fe7dbca4edc18 100644
--- a/compiler/rustc_target/src/abi/mod.rs
+++ b/compiler/rustc_target/src/abi/mod.rs
@@ -68,12 +68,21 @@ impl<'a> Layout<'a> {
/// to that obtained from `layout_of(ty)`, as we need to produce
/// layouts for which Rust types do not exist, such as enum variants
/// or synthetic fields of enums (i.e., discriminants) and fat pointers.
-#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable_Generic)]
+#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable_Generic)]
pub struct TyAndLayout<'a, Ty> {
pub ty: Ty,
pub layout: Layout<'a>,
}
+impl<'a, Ty: fmt::Debug + fmt::Display> fmt::Debug for TyAndLayout<'a, Ty> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.debug_struct("TyAndLayout")
+ .field("ty", &format_args!("{}", &self.ty))
+ .field("layout", &self.layout)
+ .finish()
+ }
+}
+
impl<'a, Ty> Deref for TyAndLayout<'a, Ty> {
type Target = &'a LayoutS;
fn deref(&self) -> &&'a LayoutS {
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
index b35b9d62759c7..46e02517afc50 100644
--- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
+++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
@@ -1652,7 +1652,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
);
} else {
err.note(&format!(
- "`{}` is implemented for `{:?}`, but not for `{:?}`",
+ "`{}` is implemented for `{}`, but not for `{}`",
trait_pred.print_modifiers_and_trait_path(),
suggested_ty,
trait_pred.skip_binder().self_ty(),
diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs
index 378cd5a99ed86..db09e7bb04dcb 100644
--- a/compiler/rustc_ty_utils/src/layout.rs
+++ b/compiler/rustc_ty_utils/src/layout.rs
@@ -826,7 +826,7 @@ fn record_layout_for_printing_outlined<'tcx>(
// (delay format until we actually need it)
let record = |kind, packed, opt_discr_size, variants| {
- let type_desc = format!("{:?}", layout.ty);
+ let type_desc = format!("{}", layout.ty);
cx.tcx.sess.code_stats.record_type_size(
kind,
type_desc,
diff --git a/tests/mir-opt/building/async_await.b-{closure#0}.generator_resume.0.mir b/tests/mir-opt/building/async_await.b-{closure#0}.generator_resume.0.mir
index 1449247aedad3..cc87b27b9cd39 100644
--- a/tests/mir-opt/building/async_await.b-{closure#0}.generator_resume.0.mir
+++ b/tests/mir-opt/building/async_await.b-{closure#0}.generator_resume.0.mir
@@ -2,7 +2,13 @@
/* generator_layout = GeneratorLayout {
field_tys: {
_0: GeneratorSavedTy {
- ty: impl std::future::Future