]> git.lizzy.rs Git - rust.git/commitdiff
Make error code registration work again. #19624
authorBrian Anderson <banderson@mozilla.com>
Fri, 16 Jan 2015 23:54:58 +0000 (15:54 -0800)
committerBrian Anderson <banderson@mozilla.com>
Tue, 20 Jan 2015 19:27:14 +0000 (11:27 -0800)
mk/tests.mk
src/etc/errorck.py [new file with mode: 0644]
src/librustc/diagnostics.rs
src/librustc/lib.rs
src/librustc_driver/lib.rs
src/librustc_resolve/diagnostics.rs [new file with mode: 0644]
src/librustc_resolve/lib.rs
src/librustc_typeck/diagnostics.rs
src/librustc_typeck/lib.rs
src/libsyntax/diagnostics/plugin.rs
src/test/run-make/issue-19371/foo.rs

index 10452d9127501c85e51368f77c3871afe5a23962..7a7287a2fbfbb70fa3a6ff86783985586e23cda0 100644 (file)
@@ -302,6 +302,7 @@ tidy:
                | grep '^$(S)src/libbacktrace' -v \
                | grep '^$(S)src/rust-installer' -v \
                | xargs $(CFG_PYTHON) $(S)src/etc/check-binaries.py
+               $(Q) $(CFG_PYTHON) $(S)src/etc/errorck.py $(S)src/
 
 
 endif
diff --git a/src/etc/errorck.py b/src/etc/errorck.py
new file mode 100644 (file)
index 0000000..1765930
--- /dev/null
@@ -0,0 +1,70 @@
+# Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+# file at the top-level directory of this distribution and at
+# http://rust-lang.org/COPYRIGHT.
+#
+# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+# option. This file may not be copied, modified, or distributed
+# except according to those terms.
+
+# Digs error codes out of files named 'diagnostics.rs' across
+# the tree, and ensures thare are no duplicates.
+
+import sys, os, re
+
+src_dir = sys.argv[1]
+
+errcode_map = { }
+
+for (dirpath, dirnames, filenames) in os.walk(src_dir):
+
+    if "src/test" in dirpath or "src/llvm" in dirpath:
+        # Short circuit for fast
+        continue
+
+    for filename in filenames:
+        if filename != "diagnostics.rs":
+            continue
+
+        path = os.path.join(dirpath, filename)
+        line_num = 1
+        with open(path, 'r') as f:
+            for line in f:
+
+                p = re.compile("(E\d\d\d\d)")
+                m = p.search(line)
+                if not m is None:
+                    errcode = m.group(1)
+
+                    new_record = [(errcode, path, line_num, line)]
+                    existing = errcode_map.get(errcode)
+                    if existing is not None:
+                        # This is a dupe
+                        errcode_map[errcode] = existing + new_record
+                    else:
+                        errcode_map[errcode] = new_record
+
+                line_num += 1
+
+errors = False
+all_errors = []
+for errcode in errcode_map:
+    entries = errcode_map[errcode]
+    all_errors += [entries[0][0]]
+    if len(entries) > 1:
+        print "error: duplicate error code " + errcode
+        for entry in entries:
+            print entry[1] + ": " + str(entry[2])
+            print entry[3]
+        errors = True
+
+print str(len(errcode_map)) + " error codes"
+
+all_errors.sort()
+all_errors.reverse()
+
+print "highest error code: " + all_errors[0]
+
+if errors:
+    sys.exit(1)
index 1ea79bdf606dade4719c6cf7a3e9e39d2917fe74..c3b87fdd8aaf6476c7de32ca3e270bbee7cf8cc9 100644 (file)
@@ -31,7 +31,6 @@
     E0010,
     E0011,
     E0012,
-    E0013,
     E0014,
     E0015,
     E0016,
     E0137,
     E0138,
     E0139,
-    E0140,
     E0152,
-    E0153,
-    E0157,
     E0158,
     E0161,
     E0162,
     E0165,
-    E0166,
-    E0167,
-    E0168,
-    E0169,
-    E0170,
-    E0171,
-    E0172,
-    E0173,
-    E0174,
-    E0177,
-    E0178,
-    E0179
+    E0170
 }
+
+__build_diagnostic_array! { DIAGNOSTICS }
+
index 628690645514a2f28bb7c225d2a3449558637e59..377e5dd39ff57fe7ae0a4f033fffd8925ffa284d 100644 (file)
@@ -54,7 +54,9 @@
 
 pub use rustc_llvm as llvm;
 
-mod diagnostics;
+// NB: This module needs to be declared first so diagnostics are
+// registered before they are used.
+pub mod diagnostics;
 
 pub mod back {
     pub use rustc_back::abi;
@@ -132,8 +134,6 @@ pub mod lib {
     pub use llvm;
 }
 
-__build_diagnostic_array! { DIAGNOSTICS }
-
 // A private module so that macro-expanded idents like
 // `::rustc::lint::Lint` will also work in `rustc` itself.
 //
index 50ff4546c3783beca403127c8b0e0f16aad52bf7..f8e889fc7111b551a99be08c3cd0bfbdfd57ce65 100644 (file)
@@ -61,7 +61,6 @@
 use rustc::lint;
 use rustc::metadata;
 use rustc::metadata::creader::CrateOrString::Str;
-use rustc::DIAGNOSTICS;
 use rustc::util::common::time;
 
 use std::cmp::Ordering::Equal;
@@ -98,7 +97,7 @@ fn run_compiler(args: &[String]) {
         None => return
     };
 
-    let descriptions = diagnostics::registry::Registry::new(&DIAGNOSTICS);
+    let descriptions = diagnostics_registry();
     match matches.opt_str("explain") {
         Some(ref code) => {
             match descriptions.find_description(&code[]) {
@@ -659,8 +658,20 @@ pub fn monitor<F:FnOnce()+Send>(f: F) {
     }
 }
 
+pub fn diagnostics_registry() -> diagnostics::registry::Registry {
+    use syntax::diagnostics::registry::Registry;
+
+    let all_errors = Vec::new() +
+        rustc::diagnostics::DIAGNOSTICS.as_slice() +
+        rustc_typeck::diagnostics::DIAGNOSTICS.as_slice() +
+        rustc_resolve::diagnostics::DIAGNOSTICS.as_slice();
+
+    Registry::new(&*all_errors)
+}
+
 pub fn main() {
     let args = std::os::args();
     let result = run(args);
     std::os::set_exit_status(result);
 }
+
diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs
new file mode 100644 (file)
index 0000000..eed808b
--- /dev/null
@@ -0,0 +1,18 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![allow(non_snake_case)]
+
+register_diagnostics! {
+    E0157,
+    E0153
+}
+
+__build_diagnostic_array! { DIAGNOSTICS }
index 31999faa6dfeacd4171be041948f3cbed81c5808..19b93ab259954663cff06d3b5b88b0f8937fadce 100644 (file)
 use std::rc::{Rc, Weak};
 use std::uint;
 
+// NB: This module needs to be declared first so diagnostics are
+// registered before they are used.
+pub mod diagnostics;
+
 mod check_unused;
 mod record_exports;
 mod build_reduced_graph;
index c9e15b93ad4c5fa2dda4bbbdd97ff1bf408692b4..68cf9ce07075fc4a6fb6189e9066d04fe154943f 100644 (file)
 
 #![allow(non_snake_case)]
 
-register_diagnostic! {
-    E0001,
-r##"
-    This error suggests that the expression arm corresponding to the noted pattern
-    will never be reached as for all possible values of the expression being matched,
-    one of the preceeding patterns will match.
-
-    This means that perhaps some of the preceeding patterns are too general, this
-    one is too specific or the ordering is incorrect.
-"## }
-
 register_diagnostics! {
-    E0002,
-    E0003,
-    E0004,
-    E0005,
-    E0006,
-    E0007,
-    E0008,
-    E0009,
-    E0010,
-    E0011,
-    E0012,
-    E0013,
-    E0014,
-    E0015,
-    E0016,
-    E0017,
-    E0018,
-    E0019,
-    E0020,
-    E0022,
     E0023,
     E0024,
     E0025,
     E0046,
     E0049,
     E0050,
-    E0051,
-    E0052,
     E0053,
     E0054,
     E0055,
-    E0056,
     E0057,
     E0059,
     E0060,
     E0092,
     E0093,
     E0094,
-    E0100,
     E0101,
     E0102,
     E0103,
     E0104,
     E0106,
     E0107,
-    E0108,
-    E0109,
-    E0110,
     E0116,
     E0117,
     E0118,
     E0130,
     E0131,
     E0132,
-    E0133,
-    E0134,
-    E0135,
-    E0136,
-    E0137,
-    E0138,
-    E0139,
-    E0140,
     E0141,
-    E0152,
-    E0153,
-    E0157,
-    E0158,
     E0159,
-    E0161,
-    E0162,
     E0163,
     E0164,
-    E0165,
     E0166,
     E0167,
     E0168,
-    E0169,
-    E0171,
     E0172,
     E0173, // manual implementations of unboxed closure traits are experimental
     E0174, // explicit use of unboxed closure methods are experimental
-    E0177,
     E0178,
-    E0180,
-    E0181,
     E0182,
     E0183,
     E0184
 }
+
+__build_diagnostic_array! { DIAGNOSTICS }
+
index 47b5cd4b11e0f1a2b99c56ce85124fe8c985471e..1fb292b86bfbdb2ff16e68ba396c608bf4e1fb19 100644 (file)
 
 use std::cell::RefCell;
 
+// NB: This module needs to be declared first so diagnostics are
+// registered before they are used.
+pub mod diagnostics;
+
 mod check;
 mod rscope;
 mod astconv;
index 1469c50061cc75dc449bb1e11e339c24d7b9a159..0e99829fa1c66e477244b0cc9279164c6f0b2f51 100644 (file)
@@ -65,6 +65,13 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt,
         }
         ()
     });
+    with_registered_diagnostics(|diagnostics| {
+        if !diagnostics.contains_key(&code.name) {
+            ecx.span_err(span, &format!(
+                "used diagnostic code {} not registered", token::get_ident(code).get()
+            )[]);
+        }
+    });
     MacExpr::new(quote_expr!(ecx, ()))
 }
 
index fe7df6411599c6a5c8882aaa5e59fb32987cf4a7..867008cd25917f75195f72b833ad69eaf2ed80e8 100644 (file)
@@ -44,7 +44,7 @@ fn basic_sess(sysroot: Path) -> Session {
     opts.output_types = vec![OutputTypeExe];
     opts.maybe_sysroot = Some(sysroot);
 
-    let descriptions = Registry::new(&rustc::DIAGNOSTICS);
+    let descriptions = Registry::new(&rustc::diagnostics::DIAGNOSTICS);
     let sess = build_session(opts, None, descriptions);
     sess
 }