diff options
| author | Badel2 <2badel2@gmail.com> | 2023-05-19 00:44:14 +0200 |
|---|---|---|
| committer | Badel2 <2badel2@gmail.com> | 2023-05-19 20:58:06 +0200 |
| commit | cbb41008fd43b512ffdbd35cebee2e4518b2181e (patch) | |
| tree | be9a0219f072c1d5ab0480dcf7b7e34c18424b94 /compiler/rustc_errors/src/lib.rs | |
| parent | 8a281f9c796ee8cbebb07bbeec04ef2f2dd8db45 (diff) | |
| download | rust-cbb41008fd43b512ffdbd35cebee2e4518b2181e.tar.gz rust-cbb41008fd43b512ffdbd35cebee2e4518b2181e.zip | |
Fix overflow in error emitter
Diffstat (limited to 'compiler/rustc_errors/src/lib.rs')
| -rw-r--r-- | compiler/rustc_errors/src/lib.rs | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 0f360473619..b1ee222b7c4 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -330,12 +330,11 @@ impl CodeSuggestion { }); buf.push_str(&part.snippet); let cur_hi = sm.lookup_char_pos(part.span.hi()); - if cur_hi.line == cur_lo.line && !part.snippet.is_empty() { - // Account for the difference between the width of the current code and the - // snippet being suggested, so that the *later* suggestions are correctly - // aligned on the screen. - acc += len - (cur_hi.col.0 - cur_lo.col.0) as isize; - } + // Account for the difference between the width of the current code and the + // snippet being suggested, so that the *later* suggestions are correctly + // aligned on the screen. Note that cur_hi and cur_lo can be on different + // lines, so cur_hi.col can be smaller than cur_lo.col + acc += len - (cur_hi.col.0 as isize - cur_lo.col.0 as isize); prev_hi = cur_hi; prev_line = sf.get_line(prev_hi.line - 1); for line in part.snippet.split('\n').skip(1) { |
