]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/ty/error.rs
Rollup merge of #66503 - thomasetter:panic-error-msg, r=joshtriplett
[rust.git] / src / librustc / ty / error.rs
index feb53539a2eda3f9c384af2dbaa90643e614fd3e..be6d21564a0f1bd939feba5ac2ba062bab561532 100644 (file)
@@ -1,14 +1,15 @@
+use crate::hir;
 use crate::hir::def_id::DefId;
 use crate::ty::{self, BoundRegion, Region, Ty, TyCtxt};
-use std::borrow::Cow;
-use std::fmt;
+
+use errors::{Applicability, DiagnosticBuilder};
 use rustc_target::spec::abi;
 use syntax::ast;
 use syntax::errors::pluralize;
-use errors::{Applicability, DiagnosticBuilder};
 use syntax_pos::Span;
 
-use crate::hir;
+use std::borrow::Cow;
+use std::fmt;
 
 #[derive(Clone, Copy, Debug, PartialEq, Eq, TypeFoldable)]
 pub struct ExpectedFound<T> {
@@ -222,8 +223,8 @@ impl<'tcx> ty::TyS<'tcx> {
     pub fn sort_string(&self, tcx: TyCtxt<'_>) -> Cow<'static, str> {
         match self.kind {
             ty::Bool | ty::Char | ty::Int(_) |
-            ty::Uint(_) | ty::Float(_) | ty::Str | ty::Never => format!("{}", self).into(),
-            ty::Tuple(ref tys) if tys.is_empty() => format!("{}", self).into(),
+            ty::Uint(_) | ty::Float(_) | ty::Str | ty::Never => format!("`{}`", self).into(),
+            ty::Tuple(ref tys) if tys.is_empty() => format!("`{}`", self).into(),
 
             ty::Adt(def, _) => format!("{} `{}`", def.descr(), tcx.def_path_str(def.did)).into(),
             ty::Foreign(def_id) => format!("extern type `{}`", tcx.def_path_str(def_id)).into(),
@@ -244,7 +245,7 @@ pub fn sort_string(&self, tcx: TyCtxt<'_>) -> Cow<'static, str> {
                 if tymut_string != "_" && (
                     ty.is_simple_text() || tymut_string.len() < "mutable reference".len()
                 ) {
-                    format!("&{}", tymut_string).into()
+                    format!("`&{}`", tymut_string).into()
                 } else { // Unknown type name, it's long or has type arguments
                     match mutbl {
                         hir::Mutability::Mutable => "mutable reference",
@@ -256,7 +257,7 @@ pub fn sort_string(&self, tcx: TyCtxt<'_>) -> Cow<'static, str> {
             ty::FnPtr(_) => "fn pointer".into(),
             ty::Dynamic(ref inner, ..) => {
                 if let Some(principal) = inner.principal() {
-                    format!("trait {}", tcx.def_path_str(principal.def_id())).into()
+                    format!("trait `{}`", tcx.def_path_str(principal.def_id())).into()
                 } else {
                     "trait".into()
                 }