1
Fork 0

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 sig = self.tcx.fn_sig(did);
let bound_output = sig.output(); let bound_output = sig.output();
let output = bound_output.skip_binder(); 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; let kind = &output.kind;
if let ty::Projection(proj) = kind { if let ty::Projection(proj) = kind {
if let Some(span) = self.tcx.hir().span_if_local(proj.item_def_id) { 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() .tcx()
.sess .sess
.struct_span_err(sp, "`impl` item signature doesn't match `trait` item signature"); .struct_span_err(sp, "`impl` item signature doesn't match `trait` item signature");
err.span_label(sp, &format!("found `{:?}`", found)); err.span_label(sp, &format!("found `{}`", found));
err.span_label(trait_sp, &format!("expected `{:?}`", expected)); err.span_label(trait_sp, &format!("expected `{}`", expected));
// Get the span of all the used type parameters in the method. // Get the span of all the used type parameters in the method.
let assoc_item = self.tcx().associated_item(trait_def_id); 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); err.note_expected_found(&"", expected, &"", found);
} else { } else {
// This fallback shouldn't be necessary, but let's keep it in just in case. // 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( err.span_help(
type_param_span, type_param_span,

View file

@ -260,10 +260,11 @@ impl<'tcx> fmt::Display for Instance<'tcx> {
InstanceDef::ReifyShim(_) => write!(f, " - shim(reify)"), InstanceDef::ReifyShim(_) => write!(f, " - shim(reify)"),
InstanceDef::Intrinsic(_) => write!(f, " - intrinsic"), InstanceDef::Intrinsic(_) => write!(f, " - intrinsic"),
InstanceDef::Virtual(_, num) => write!(f, " - virtual#{}", num), 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::ClosureOnceShim { .. } => write!(f, " - shim"),
InstanceDef::DropGlue(_, ty) => write!(f, " - shim({:?})", ty), InstanceDef::DropGlue(_, None) => write!(f, " - shim(None)"),
InstanceDef::CloneShim(_, ty) => write!(f, " - shim({:?})", ty), 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> { impl<'tcx> fmt::Display for LayoutError<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self { 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) => { 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) .normalize(candidate)
.ok(); .ok();
match normalized { match normalized {
Some(normalized) => format!("\n {:?}", normalized.value), Some(normalized) => format!("\n {}", normalized.value),
None => format!("\n {:?}", candidate), None => format!("\n {}", candidate),
} }
}) })
}; };

View file

@ -2487,14 +2487,14 @@ fn fn_sig_suggestion<'tcx>(
_ => format!("self: {}", ty), _ => format!("self: {}", ty),
} }
} else { } else {
format!("_: {:?}", ty) format!("_: {}", ty)
} }
} }
_ => { _ => {
if assoc.fn_has_self_parameter && i == 0 { if assoc.fn_has_self_parameter && i == 0 {
format!("self: {:?}", ty) format!("self: {}", ty)
} else { } else {
format!("_: {:?}", ty) format!("_: {}", ty)
} }
} }
}) })
@ -2504,7 +2504,7 @@ fn fn_sig_suggestion<'tcx>(
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join(", "); .join(", ");
let output = sig.output(); 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 unsafety = sig.unsafety.prefix_str();
let (generics, where_clauses) = bounds_from_generic_predicates(tcx, predicates); 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 => { ty::AssocKind::Const => {
let ty = tcx.type_of(assoc.def_id); let ty = tcx.type_of(assoc.def_id);
let val = expr::ty_kind_suggestion(ty).unwrap_or("value"); 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(), fcx.tcx.sess.diagnostic(),
span, span,
E0307, E0307,
"invalid `self` parameter type: {:?}", "invalid `self` parameter type: {}",
receiver_ty, receiver_ty,
) )
.note("type of `self` must be `Self` or a type that dereferences to it") .note("type of `self` must be `Self` or a type that dereferences to it")