Skip to content

Commit

Permalink
Auto merge of rust-lang#26984 - nham:errorck-ignore-long-diag, r=brson
Browse files Browse the repository at this point in the history
Currently errorck yields bogus `duplicate error code` messages when an error code occurs inside of a long diagnostic message (see rust-lang#26982), because errorck just goes line by line checking for error codes and recording them all.

A simplistic approach to fixing this is just to detect the beginning of a long diagnostic raw string literal (`r##"`) and skip lines until the end of the raw string literal is encountered. I'm not completely confident in this approach, but I think a more robust approach would be more complicated and I wanted to get feedback before pursuing that.
  • Loading branch information
bors committed Jul 13, 2015
2 parents 0fbceba + 4630fc7 commit 6800538
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/etc/errorck.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@
errcode_map = {}
error_re = re.compile("(E\d\d\d\d)")

# In the register_long_diagnostics! macro, entries look like this:
#
# EXXXX: r##"
# <Long diagnostic message>
# "##,
#
# These two variables are for detecting the beginning and end of diagnostic
# messages so that duplicate error codes are not reported when a code occurs
# inside a diagnostic message
long_diag_begin = "r##\""
long_diag_end = "\"##"

for (dirpath, dirnames, filenames) in os.walk(src_dir):
if "src/test" in dirpath or "src/llvm" in dirpath:
# Short circuit for fast
Expand All @@ -35,7 +47,14 @@
path = os.path.join(dirpath, filename)

with open(path, 'r') as f:
inside_long_diag = False
for line_num, line in enumerate(f, start=1):
if inside_long_diag:
# Skip duplicate error code checking for this line
if long_diag_end in line:
inside_long_diag = False
continue

match = error_re.search(line)
if match:
errcode = match.group(1)
Expand All @@ -47,6 +66,9 @@
else:
errcode_map[errcode] = new_record

if long_diag_begin in line:
inside_long_diag = True

errors = False
all_errors = []

Expand Down

0 comments on commit 6800538

Please sign in to comment.