]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_typeck/structured_errors.rs
Add some type-alias-impl-trait regression tests
[rust.git] / src / librustc_typeck / structured_errors.rs
index cedd6e6fdb241d37bb9ea8dfeb867ed05365f5ae..99b7b2001a9e9a29812a2ecf8ec6d3ec7da509c2 100644 (file)
@@ -1,9 +1,7 @@
 use rustc::session::Session;
-use syntax_pos::Span;
-use errors::{Applicability, DiagnosticId, DiagnosticBuilder};
 use rustc::ty::{Ty, TypeFoldable};
-
-use rustc_error_codes::*;
+use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticId};
+use rustc_span::Span;
 
 pub trait StructuredDiagnostic<'tcx> {
     fn session(&self) -> &Session;
@@ -14,11 +12,7 @@ pub trait StructuredDiagnostic<'tcx> {
 
     fn diagnostic(&self) -> DiagnosticBuilder<'tcx> {
         let err = self.common();
-        if self.session().teach(&self.code()) {
-            self.extended(err)
-        } else {
-            self.regular(err)
-        }
+        if self.session().teach(&self.code()) { self.extended(err) } else { self.regular(err) }
     }
 
     fn regular(&self, err: DiagnosticBuilder<'tcx>) -> DiagnosticBuilder<'tcx> {
@@ -38,20 +32,23 @@ pub struct VariadicError<'tcx> {
 }
 
 impl<'tcx> VariadicError<'tcx> {
-    pub fn new(sess: &'tcx Session,
-               span: Span,
-               t: Ty<'tcx>,
-               cast_ty: &'tcx str) -> VariadicError<'tcx> {
+    pub fn new(
+        sess: &'tcx Session,
+        span: Span,
+        t: Ty<'tcx>,
+        cast_ty: &'tcx str,
+    ) -> VariadicError<'tcx> {
         VariadicError { sess, span, t, cast_ty }
     }
 }
 
 impl<'tcx> StructuredDiagnostic<'tcx> for VariadicError<'tcx> {
-    fn session(&self) -> &Session { self.sess }
+    fn session(&self) -> &Session {
+        self.sess
+    }
 
     fn code(&self) -> DiagnosticId {
-        syntax::diagnostic_used!(E0617);
-        DiagnosticId::Error("E0617".to_owned())
+        rustc_errors::error_code!(E0617)
     }
 
     fn common(&self) -> DiagnosticBuilder<'tcx> {
@@ -78,10 +75,12 @@ fn common(&self) -> DiagnosticBuilder<'tcx> {
     }
 
     fn extended(&self, mut err: DiagnosticBuilder<'tcx>) -> DiagnosticBuilder<'tcx> {
-        err.note(&format!("certain types, like `{}`, must be cast before passing them to a \
+        err.note(&format!(
+            "certain types, like `{}`, must be cast before passing them to a \
                            variadic function, because of arcane ABI rules dictated by the C \
                            standard",
-                          self.t));
+            self.t
+        ));
         err
     }
 }
@@ -94,20 +93,23 @@ pub struct SizedUnsizedCastError<'tcx> {
 }
 
 impl<'tcx> SizedUnsizedCastError<'tcx> {
-    pub fn new(sess: &'tcx Session,
-               span: Span,
-               expr_ty: Ty<'tcx>,
-               cast_ty: String) -> SizedUnsizedCastError<'tcx> {
+    pub fn new(
+        sess: &'tcx Session,
+        span: Span,
+        expr_ty: Ty<'tcx>,
+        cast_ty: String,
+    ) -> SizedUnsizedCastError<'tcx> {
         SizedUnsizedCastError { sess, span, expr_ty, cast_ty }
     }
 }
 
 impl<'tcx> StructuredDiagnostic<'tcx> for SizedUnsizedCastError<'tcx> {
-    fn session(&self) -> &Session { self.sess }
+    fn session(&self) -> &Session {
+        self.sess
+    }
 
     fn code(&self) -> DiagnosticId {
-        syntax::diagnostic_used!(E0607);
-        DiagnosticId::Error("E0607".to_owned())
+        rustc_errors::error_code!(E0607)
     }
 
     fn common(&self) -> DiagnosticBuilder<'tcx> {
@@ -116,9 +118,10 @@ fn common(&self) -> DiagnosticBuilder<'tcx> {
         } else {
             self.sess.struct_span_fatal_with_code(
                 self.span,
-                &format!("cannot cast thin pointer `{}` to fat pointer `{}`",
-                         self.expr_ty,
-                         self.cast_ty),
+                &format!(
+                    "cannot cast thin pointer `{}` to fat pointer `{}`",
+                    self.expr_ty, self.cast_ty
+                ),
                 self.code(),
             )
         }
@@ -139,7 +142,8 @@ fn extended(&self, mut err: DiagnosticBuilder<'tcx>) -> DiagnosticBuilder<'tcx>
 pointers.
 
 For more information about casts, take a look at The Book:
-https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions");
+https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions",
+        );
         err
     }
 }