Skip to content

Commit 75a042e

Browse files
committed
Fix some unwanted uses of Debug formatting on user-facing messages
While formatting for user diagnostics used `Display` for all most cases, some small amount of cases used `Debug` instead. Until now, `Display` and `Debug` yielded the same output for many types. However, with path trimming, we want to show a shorter path for the user, these cases need fixing.
1 parent e36e4bd commit 75a042e

File tree

7 files changed

+19
-18
lines changed

7 files changed

+19
-18
lines changed

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,11 +611,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
611611
let sig = self.tcx.fn_sig(did);
612612
let bound_output = sig.output();
613613
let output = bound_output.skip_binder();
614-
err.span_label(e.span, &format!("this method call resolves to `{:?}`", output));
614+
err.span_label(e.span, &format!("this method call resolves to `{}`", output));
615615
let kind = &output.kind;
616616
if let ty::Projection(proj) = kind {
617617
if let Some(span) = self.tcx.hir().span_if_local(proj.item_def_id) {
618-
err.span_label(span, &format!("`{:?}` defined here", output));
618+
err.span_label(span, &format!("`{}` defined here", output));
619619
}
620620
}
621621
}

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
5858
.tcx()
5959
.sess
6060
.struct_span_err(sp, "`impl` item signature doesn't match `trait` item signature");
61-
err.span_label(sp, &format!("found `{:?}`", found));
62-
err.span_label(trait_sp, &format!("expected `{:?}`", expected));
61+
err.span_label(sp, &format!("found `{}`", found));
62+
err.span_label(trait_sp, &format!("expected `{}`", expected));
6363

6464
// Get the span of all the used type parameters in the method.
6565
let assoc_item = self.tcx().associated_item(trait_def_id);
@@ -92,7 +92,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
9292
err.note_expected_found(&"", expected, &"", found);
9393
} else {
9494
// This fallback shouldn't be necessary, but let's keep it in just in case.
95-
err.note(&format!("expected `{:?}`\n found `{:?}`", expected, found));
95+
err.note(&format!("expected `{}`\n found `{}`", expected, found));
9696
}
9797
err.span_help(
9898
type_param_span,

compiler/rustc_middle/src/ty/instance.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,11 @@ impl<'tcx> fmt::Display for Instance<'tcx> {
260260
InstanceDef::ReifyShim(_) => write!(f, " - shim(reify)"),
261261
InstanceDef::Intrinsic(_) => write!(f, " - intrinsic"),
262262
InstanceDef::Virtual(_, num) => write!(f, " - virtual#{}", num),
263-
InstanceDef::FnPtrShim(_, ty) => write!(f, " - shim({:?})", ty),
263+
InstanceDef::FnPtrShim(_, ty) => write!(f, " - shim({})", ty),
264264
InstanceDef::ClosureOnceShim { .. } => write!(f, " - shim"),
265-
InstanceDef::DropGlue(_, ty) => write!(f, " - shim({:?})", ty),
266-
InstanceDef::CloneShim(_, ty) => write!(f, " - shim({:?})", ty),
265+
InstanceDef::DropGlue(_, None) => write!(f, " - shim(None)"),
266+
InstanceDef::DropGlue(_, Some(ty)) => write!(f, " - shim(Some({}))", ty),
267+
InstanceDef::CloneShim(_, ty) => write!(f, " - shim({})", ty),
267268
}
268269
}
269270
}

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ pub enum LayoutError<'tcx> {
174174
impl<'tcx> fmt::Display for LayoutError<'tcx> {
175175
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
176176
match *self {
177-
LayoutError::Unknown(ty) => write!(f, "the type `{:?}` has an unknown layout", ty),
177+
LayoutError::Unknown(ty) => write!(f, "the type `{}` has an unknown layout", ty),
178178
LayoutError::SizeOverflow(ty) => {
179-
write!(f, "the type `{:?}` is too big for the current architecture", ty)
179+
write!(f, "the type `{}` is too big for the current architecture", ty)
180180
}
181181
}
182182
}

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,8 +1342,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
13421342
.normalize(candidate)
13431343
.ok();
13441344
match normalized {
1345-
Some(normalized) => format!("\n {:?}", normalized.value),
1346-
None => format!("\n {:?}", candidate),
1345+
Some(normalized) => format!("\n {}", normalized.value),
1346+
None => format!("\n {}", candidate),
13471347
}
13481348
})
13491349
};

compiler/rustc_typeck/src/check/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,14 +2487,14 @@ fn fn_sig_suggestion<'tcx>(
24872487
_ => format!("self: {}", ty),
24882488
}
24892489
} else {
2490-
format!("_: {:?}", ty)
2490+
format!("_: {}", ty)
24912491
}
24922492
}
24932493
_ => {
24942494
if assoc.fn_has_self_parameter && i == 0 {
2495-
format!("self: {:?}", ty)
2495+
format!("self: {}", ty)
24962496
} else {
2497-
format!("_: {:?}", ty)
2497+
format!("_: {}", ty)
24982498
}
24992499
}
25002500
})
@@ -2504,7 +2504,7 @@ fn fn_sig_suggestion<'tcx>(
25042504
.collect::<Vec<String>>()
25052505
.join(", ");
25062506
let output = sig.output();
2507-
let output = if !output.is_unit() { format!(" -> {:?}", output) } else { String::new() };
2507+
let output = if !output.is_unit() { format!(" -> {}", output) } else { String::new() };
25082508

25092509
let unsafety = sig.unsafety.prefix_str();
25102510
let (generics, where_clauses) = bounds_from_generic_predicates(tcx, predicates);
@@ -2542,7 +2542,7 @@ fn suggestion_signature(assoc: &ty::AssocItem, tcx: TyCtxt<'_>) -> String {
25422542
ty::AssocKind::Const => {
25432543
let ty = tcx.type_of(assoc.def_id);
25442544
let val = expr::ty_kind_suggestion(ty).unwrap_or("value");
2545-
format!("const {}: {:?} = {};", assoc.ident, ty, val)
2545+
format!("const {}: {} = {};", assoc.ident, ty, val)
25462546
}
25472547
}
25482548
}

compiler/rustc_typeck/src/check/wfcheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ fn e0307(fcx: &FnCtxt<'fcx, 'tcx>, span: Span, receiver_ty: Ty<'_>) {
11771177
fcx.tcx.sess.diagnostic(),
11781178
span,
11791179
E0307,
1180-
"invalid `self` parameter type: {:?}",
1180+
"invalid `self` parameter type: {}",
11811181
receiver_ty,
11821182
)
11831183
.note("type of `self` must be `Self` or a type that dereferences to it")

0 commit comments

Comments
 (0)