]> git.lizzy.rs Git - rust.git/commitdiff
Make fatal errors work with codes, add to typeck
authorBrian Anderson <banderson@mozilla.com>
Sun, 18 Jan 2015 21:39:18 +0000 (13:39 -0800)
committerBrian Anderson <banderson@mozilla.com>
Tue, 20 Jan 2015 19:27:51 +0000 (11:27 -0800)
src/librustc/session/mod.rs
src/librustc_typeck/astconv.rs
src/librustc_typeck/check/mod.rs
src/librustc_typeck/diagnostics.rs
src/librustc_typeck/lib.rs
src/libsyntax/diagnostic.rs
src/libsyntax/diagnostics/macros.rs

index 5424b1c8cae508d0fa815a0449e571439c0bf8f5..0392fbfdeaecca8f95a7373f9b4b2329f7458a66 100644 (file)
@@ -69,6 +69,9 @@ impl Session {
     pub fn span_fatal(&self, sp: Span, msg: &str) -> ! {
         self.diagnostic().span_fatal(sp, msg)
     }
+    pub fn span_fatal_with_code(&self, sp: Span, msg: &str, code: &str) -> ! {
+        self.diagnostic().span_fatal_with_code(sp, msg, code)
+    }
     pub fn fatal(&self, msg: &str) -> ! {
         self.diagnostic().handler().fatal(msg)
     }
index 080959cae0c749c454dacd674f359611bffe1e3b..cfcc65bd15ace43c66519b2d1f78a3c798396097 100644 (file)
@@ -339,22 +339,22 @@ fn create_substs_for_ast_path<'tcx>(
         } else {
             "expected"
         };
-        this.tcx().sess.span_fatal(span,
-                                   &format!("wrong number of type arguments: {} {}, found {}",
+        span_fatal!(this.tcx().sess, span, E0243,
+                                   "wrong number of type arguments: {} {}, found {}",
                                            expected,
                                            required_ty_param_count,
-                                           supplied_ty_param_count)[]);
+                                           supplied_ty_param_count);
     } else if supplied_ty_param_count > formal_ty_param_count {
         let expected = if required_ty_param_count < formal_ty_param_count {
             "expected at most"
         } else {
             "expected"
         };
-        this.tcx().sess.span_fatal(span,
-                                   &format!("wrong number of type arguments: {} {}, found {}",
+        span_fatal!(this.tcx().sess, span, E0244,
+                                   "wrong number of type arguments: {} {}, found {}",
                                            expected,
                                            formal_ty_param_count,
-                                           supplied_ty_param_count)[]);
+                                           supplied_ty_param_count);
     }
 
     let mut substs = Substs::new_type(types, regions);
@@ -557,10 +557,9 @@ pub fn instantiate_trait_ref<'tcx>(
             trait_ref
         }
         _ => {
-            this.tcx().sess.span_fatal(
-                ast_trait_ref.path.span,
-                &format!("`{}` is not a trait",
-                        ast_trait_ref.path.user_string(this.tcx()))[]);
+            span_fatal!(this.tcx().sess, ast_trait_ref.path.span, E0245,
+                "`{}` is not a trait",
+                        ast_trait_ref.path.user_string(this.tcx()));
         }
     }
 }
@@ -1036,7 +1035,7 @@ pub fn ast_ty_to_ty<'tcx>(
     match ast_ty_to_ty_cache.get(&ast_ty.id) {
         Some(&ty::atttce_resolved(ty)) => return ty,
         Some(&ty::atttce_unresolved) => {
-            tcx.sess.span_fatal(ast_ty.span,
+            span_fatal!(tcx.sess, ast_ty.span, E0246,
                                 "illegal recursive type; insert an enum \
                                  or struct in the cycle, if this is \
                                  desired");
@@ -1136,9 +1135,9 @@ pub fn ast_ty_to_ty<'tcx>(
                         ty::mk_self_type(tcx)
                     }
                     def::DefMod(id) => {
-                        tcx.sess.span_fatal(ast_ty.span,
-                            &format!("found module name used as a type: {}",
-                                    tcx.map.node_to_string(id.node))[]);
+                        span_fatal!(tcx.sess, ast_ty.span, E0247,
+                            "found module name used as a type: {}",
+                                    tcx.map.node_to_string(id.node));
                     }
                     def::DefPrimTy(_) => {
                         panic!("DefPrimTy arm missed in previous ast_ty_to_prim_ty call");
@@ -1164,10 +1163,10 @@ pub fn ast_ty_to_ty<'tcx>(
                         associated_path_def_to_ty(this, ast_ty, provenance, assoc_ident.name)
                     }
                     _ => {
-                        tcx.sess.span_fatal(ast_ty.span,
-                                            &format!("found value name used \
+                        span_fatal!(tcx.sess, ast_ty.span, E0248,
+                                            "found value name used \
                                                      as a type: {:?}",
-                                                    a_def)[]);
+                                                    a_def);
                     }
                 }
             }
@@ -1185,17 +1184,16 @@ pub fn ast_ty_to_ty<'tcx>(
                                 ty::mk_vec(tcx, ast_ty_to_ty(this, rscope, &**ty),
                                            Some(i as uint)),
                             _ => {
-                                tcx.sess.span_fatal(
-                                    ast_ty.span, "expected constant expr for array length");
+                                span_fatal!(tcx.sess, ast_ty.span, E0249,
+                                            "expected constant expr for array length");
                             }
                         }
                     }
                     Err(ref r) => {
-                        tcx.sess.span_fatal(
-                            ast_ty.span,
-                            &format!("expected constant expr for array \
+                        span_fatal!(tcx.sess, ast_ty.span, E0250,
+                            "expected constant expr for array \
                                      length: {}",
-                                    *r)[]);
+                                    *r);
                     }
                 }
             }
index 58b655d758543956f872f658676f1bba00700cf7..db4962b0d22db299b517bf75c1c9750a23a86131 100644 (file)
@@ -5224,7 +5224,7 @@ fn param<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, n: u32) -> Ty<'tcx> {
             "get_tydesc" => {
               let tydesc_ty = match ty::get_tydesc_ty(ccx.tcx) {
                   Ok(t) => t,
-                  Err(s) => { tcx.sess.span_fatal(it.span, &s[]); }
+                  Err(s) => { span_fatal!(tcx.sess, it.span, E0240, "{}", &s[]); }
               };
               let td_ptr = ty::mk_ptr(ccx.tcx, ty::mt {
                   ty: tydesc_ty,
index ce30cb91c91c896e5942a320ae41844487e49225..3627fa41160608adf2778a3593e93737fc780277 100644 (file)
     E0236, // no lang item for range syntax
     E0237, // no lang item for range syntax
     E0238, // parenthesized parameters may only be used with a trait
-    E0239  // `next` method of `Iterator` trait has unexpected type
+    E0239, // `next` method of `Iterator` trait has unexpected type
+    E0240,
+    E0241,
+    E0242, // internal error looking up a definition
+    E0243, // wrong number of type arguments
+    E0244, // wrong number of type arguments
+    E0245, // not a trait
+    E0246, // illegal recursive type
+    E0247, // found module name used as a type
+    E0248, // found value name used as a type
+    E0249, // expected constant expr for array length
+    E0250  // expected constant expr for array length
 }
 
 __build_diagnostic_array! { DIAGNOSTICS }
index aa99549bcd645cb8bfcd7ee2defd72d007f1c40f..78007f3552ece5b61d336e719d5f0a4d6b286186 100644 (file)
@@ -162,7 +162,7 @@ fn lookup_def_tcx(tcx:&ty::ctxt, sp: Span, id: ast::NodeId) -> def::Def {
     match tcx.def_map.borrow().get(&id) {
         Some(x) => x.clone(),
         _ => {
-            tcx.sess.span_fatal(sp, "internal error looking up a definition")
+            span_fatal!(tcx.sess, sp, E0242, "internal error looking up a definition")
         }
     }
 }
index 7213b0fa9556cf0eb51021ecbf1e8fbe5463b74f..b26ec64c24bf2d98fce18cc2733b36951ff5145a 100644 (file)
@@ -92,6 +92,10 @@ pub fn span_fatal(&self, sp: Span, msg: &str) -> ! {
         self.handler.emit(Some((&self.cm, sp)), msg, Fatal);
         panic!(FatalError);
     }
+    pub fn span_fatal_with_code(&self, sp: Span, msg: &str, code: &str) -> ! {
+        self.handler.emit_with_code(Some((&self.cm, sp)), msg, code, Fatal);
+        panic!(FatalError);
+    }
     pub fn span_err(&self, sp: Span, msg: &str) {
         self.handler.emit(Some((&self.cm, sp)), msg, Error);
         self.handler.bump_err_count();
index 34a193dffd3db5d1d7079a2bf16fa08f3c7e1aff..5bd683c86aecac268352eddcc0ba0b34f234cf7b 100644 (file)
@@ -14,6 +14,14 @@ macro_rules! register_diagnostic {
     ($code:tt) => (__register_diagnostic! { $code })
 }
 
+#[macro_export]
+macro_rules! span_fatal {
+    ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
+        __diagnostic_used!($code);
+        $session.span_fatal_with_code($span, format!($($message)*).as_slice(), stringify!($code))
+    })
+}
+
 #[macro_export]
 macro_rules! span_err {
     ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({