1 # Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 # file at the top-level directory of this distribution and at
3 # http://rust-lang.org/COPYRIGHT.
5 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 # option. This file may not be copied, modified, or distributed
9 # except according to those terms.
11 # Digs error codes out of files named 'diagnostics.rs' across
12 # the tree, and ensures thare are no duplicates.
18 error_re = re.compile("(E\d\d\d\d)")
20 for (dirpath, dirnames, filenames) in os.walk(src_dir):
21 if "src/test" in dirpath or "src/llvm" in dirpath:
22 # Short circuit for fast
25 for filename in filenames:
26 if filename != "diagnostics.rs":
29 path = os.path.join(dirpath, filename)
31 with open(path, 'r') as f:
32 for line_num, line in enumerate(f, start=1):
33 match = error_re.search(line)
35 errcode = match.group(1)
36 new_record = [(errcode, path, line_num, line)]
37 existing = errcode_map.get(errcode)
38 if existing is not None:
40 errcode_map[errcode] = existing + new_record
42 errcode_map[errcode] = new_record
47 for errcode, entries in errcode_map.items():
48 all_errors.append(entries[0][0])
50 print("error: duplicate error code " + errcode)
52 print("{1}: {2}\n{3}".format(*entry))
55 print("{0} error codes".format(len(errcode_map)))
56 print("highest error code: " + max(all_errors))