about summary refs log tree commit diff
path: root/compiler/rustc_errors
diff options
context:
space:
mode:
authorDavid Wood <david.wood@huawei.com>2021-10-15 14:48:57 +0000
committerDavid Wood <david.wood@huawei.com>2021-10-15 15:30:43 +0000
commitd2dc0f3b0f0267941b47bde7bd48d26b2c22ca6a (patch)
tree643d5a06e80f34854c30ed7d0f2a6aa199ea1a1b /compiler/rustc_errors
parent72d66064e77281536588189a916af28a1819b313 (diff)
downloadrust-d2dc0f3b0f0267941b47bde7bd48d26b2c22ca6a.tar.gz
rust-d2dc0f3b0f0267941b47bde7bd48d26b2c22ca6a.zip
emitter: current substitution can be multi-line
In `splice_lines`, there is some arithmetic to compute the required
alignment such that future substitutions in a suggestion are aligned
correctly. However, this assumed that the current substitution's span
was only on a single line. In circumstances where this was not true, it
could result in a arithmetic overflow when the substitution's end
column was less than the substitution's start column.

Signed-off-by: David Wood <david.wood@huawei.com>
Diffstat (limited to 'compiler/rustc_errors')
-rw-r--r--compiler/rustc_errors/src/lib.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs
index 60a48b5a2d9..9b2094adb15 100644
--- a/compiler/rustc_errors/src/lib.rs
+++ b/compiler/rustc_errors/src/lib.rs
@@ -341,7 +341,7 @@ impl CodeSuggestion {
                     });
                     buf.push_str(&part.snippet);
                     let cur_hi = sm.lookup_char_pos(part.span.hi());
-                    if prev_hi.line == cur_lo.line {
+                    if prev_hi.line == cur_lo.line && cur_hi.line == cur_lo.line {
                         // 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.