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.
This commit is contained in:
Dan Aloni 2020-08-28 13:38:43 +03:00
parent e36e4bd0f7
commit 75a042e74b
7 changed files with 19 additions and 18 deletions

View File

@ -611,11 +611,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let sig = self.tcx.fn_sig(did);
let bound_output = sig.output();
let output = bound_output.skip_binder();
err.span_label(e.span, &format!("this method call resolves to `{:?}`", output));
err.span_label(e.span, &format!("this method call resolves to `{}`", output));
let kind = &output.kind;
if let ty::Projection(proj) = kind {
if let Some(span) = self.tcx.hir().span_if_local(proj.item_def_id) {
err.span_label(span, &format!("`{:?}` defined here", output));
err.span_label(span, &format!("`{}` defined here", output));
}
}
}

View File

@ -58,8 +58,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
.tcx()
.sess
.struct_span_err(sp, "`impl` item signature doesn't match `trait` item signature");
err.span_label(sp, &format!("found `{:?}`", found));
err.span_label(trait_sp, &format!("expected `{:?}`", expected));
err.span_label(sp, &format!("found `{}`", found));
err.span_label(trait_sp, &format!("expected `{}`", expected));
// Get the span of all the used type parameters in the method.
let assoc_item = self.tcx().associated_item(trait_def_id);
@ -92,7 +92,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
err.note_expected_found(&"", expected, &"", found);
} else {
// This fallback shouldn't be necessary, but let's keep it in just in case.
err.note(&format!("expected `{:?}`\n found `{:?}`", expected, found));
err.note(&format!("expected `{}`\n found `{}`", expected, found));
}
err.span_help(
type_param_span,

View File

@ -260,10 +260,11 @@ impl<'tcx> fmt::Display for Instance<'tcx> {
InstanceDef::ReifyShim(_) => write!(f, " - shim(reify)"),
InstanceDef::Intrinsic(_) => write!(f, " - intrinsic"),
InstanceDef::Virtual(_, num) => write!(f, " - virtual#{}", num),
InstanceDef::FnPtrShim(_, ty) => write!(f, " - shim({:?})", ty),
InstanceDef::FnPtrShim(_, ty) => write!(f, " - shim({})", ty),
InstanceDef::ClosureOnceShim { .. } => write!(f, " - shim"),
InstanceDef::DropGlue(_, ty) => write!(f, " - shim({:?})", ty),
InstanceDef::CloneShim(_, ty) => write!(f, " - shim({:?})", ty),
InstanceDef::DropGlue(_, None) => write!(f, " - shim(None)"),
InstanceDef::DropGlue(_, Some(ty)) => write!(f, " - shim(Some({}))", ty),
InstanceDef::CloneShim(_, ty) => write!(f, " - shim({})", ty),
}
}
}

View File

@ -174,9 +174,9 @@ pub enum LayoutError<'tcx> {
impl<'tcx> fmt::Display for LayoutError<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
LayoutError::Unknown(ty) => write!(f, "the type `{:?}` has an unknown layout", ty),
LayoutError::Unknown(ty) => write!(f, "the type `{}` has an unknown layout", ty),
LayoutError::SizeOverflow(ty) => {
write!(f, "the type `{:?}` is too big for the current architecture", ty)
write!(f, "the type `{}` is too big for the current architecture", ty)
}
}
}

View File

@ -1342,8 +1342,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
.normalize(candidate)
.ok();
match normalized {
Some(normalized) => format!("\n {:?}", normalized.value),
None => format!("\n {:?}", candidate),
Some(normalized) => format!("\n {}", normalized.value),
None => format!("\n {}", candidate),
}
})
};

View File

@ -2487,14 +2487,14 @@ fn fn_sig_suggestion<'tcx>(
_ => format!("self: {}", ty),
}
} else {
format!("_: {:?}", ty)
format!("_: {}", ty)
}
}
_ => {
if assoc.fn_has_self_parameter && i == 0 {
format!("self: {:?}", ty)
format!("self: {}", ty)
} else {
format!("_: {:?}", ty)
format!("_: {}", ty)
}
}
})
@ -2504,7 +2504,7 @@ fn fn_sig_suggestion<'tcx>(
.collect::<Vec<String>>()
.join(", ");
let output = sig.output();
let output = if !output.is_unit() { format!(" -> {:?}", output) } else { String::new() };
let output = if !output.is_unit() { format!(" -> {}", output) } else { String::new() };
let unsafety = sig.unsafety.prefix_str();
let (generics, where_clauses) = bounds_from_generic_predicates(tcx, predicates);
@ -2542,7 +2542,7 @@ fn suggestion_signature(assoc: &ty::AssocItem, tcx: TyCtxt<'_>) -> String {
ty::AssocKind::Const => {
let ty = tcx.type_of(assoc.def_id);
let val = expr::ty_kind_suggestion(ty).unwrap_or("value");
format!("const {}: {:?} = {};", assoc.ident, ty, val)
format!("const {}: {} = {};", assoc.ident, ty, val)
}
}
}

View File

@ -1177,7 +1177,7 @@ fn e0307(fcx: &FnCtxt<'fcx, 'tcx>, span: Span, receiver_ty: Ty<'_>) {
fcx.tcx.sess.diagnostic(),
span,
E0307,
"invalid `self` parameter type: {:?}",
"invalid `self` parameter type: {}",
receiver_ty,
)
.note("type of `self` must be `Self` or a type that dereferences to it")