diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2012-02-15 10:19:51 +0100 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2012-02-15 11:53:32 +0100 |
| commit | 9ff5ba085de572f8efaf501b88eb831d8ee40d47 (patch) | |
| tree | 03f7e1cbb33736bd9be7e1d0b974cf7f5aaf8711 /src/comp | |
| parent | 6627890f6bcbf2a2b71229572023cfaec91ab805 (diff) | |
Fix bad line printing for parse errors
The code that extracted lines from partially-parsed files was broken. Closes #1848
Diffstat (limited to 'src/comp')
| -rw-r--r-- | src/comp/driver/diagnostic.rs | 3 | ||||
| -rw-r--r-- | src/comp/syntax/codemap.rs | 15 |
2 files changed, 6 insertions, 12 deletions
diff --git a/src/comp/driver/diagnostic.rs b/src/comp/driver/diagnostic.rs index a0f97842546..8f0570a4349 100644 --- a/src/comp/driver/diagnostic.rs +++ b/src/comp/driver/diagnostic.rs @@ -204,8 +204,7 @@ fn highlight_lines(cm: codemap::codemap, sp: span, // Print the offending lines for line: uint in display_lines { io::stderr().write_str(#fmt["%s:%u ", fm.name, line + 1u]); - let s = codemap::get_line(fm, line as int); - if !str::ends_with(s, "\n") { s += "\n"; } + let s = codemap::get_line(fm, line as int) + "\n"; io::stderr().write_str(s); } if elided { diff --git a/src/comp/syntax/codemap.rs b/src/comp/syntax/codemap.rs index 03ade9a6931..7e153839448 100644 --- a/src/comp/syntax/codemap.rs +++ b/src/comp/syntax/codemap.rs @@ -157,16 +157,11 @@ fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines { fn get_line(fm: filemap, line: int) -> str unsafe { let begin: uint = fm.lines[line].byte - fm.start_pos.byte; - let end: uint; - if line as uint < vec::len(fm.lines) - 1u { - end = fm.lines[line + 1].byte - fm.start_pos.byte; - ret str::unsafe::slice_bytes(*fm.src, begin, end); - } else { - // If we're not done parsing the file, we're at the limit of what's - // parsed. If we just slice the rest of the string, we'll print out - // the remainder of the file, which is undesirable. - ret str::splitn_char(*fm.src, '\n', 1u)[0]; - } + let end = alt str::byte_index(*fm.src, '\n' as u8, begin) { + some(e) { e } + none { str::len(*fm.src) } + }; + str::unsafe::slice_bytes(*fm.src, begin, end) } fn lookup_byte_offset(cm: codemap::codemap, chpos: uint) |
