about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2021-10-16 08:02:24 +0200
committerGitHub <noreply@github.com>2021-10-16 08:02:24 +0200
commit27a7ced29f952fc73adb25231f52c8b2d9535497 (patch)
tree7c36a1691bbc0eda28710b83043f4a0b376e7b1f
parente98669a51a1e0d11cbec7640a747ac0e79ffa289 (diff)
parentd2dc0f3b0f0267941b47bde7bd48d26b2c22ca6a (diff)
downloadrust-27a7ced29f952fc73adb25231f52c8b2d9535497.tar.gz
rust-27a7ced29f952fc73adb25231f52c8b2d9535497.zip
Rollup merge of #89912 - davidtwco:issue-89280-split-lines-multiple-lines, r=oli-obk
emitter: current substitution can be multi-line

Fixes #89280.

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.

r? ````@oli-obk````
-rw-r--r--compiler/rustc_errors/src/lib.rs2
-rw-r--r--src/test/ui/errors/issue-89280-emitter-overflow-splice-lines.rs10
-rw-r--r--src/test/ui/errors/issue-89280-emitter-overflow-splice-lines.stderr23
3 files changed, 34 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.
diff --git a/src/test/ui/errors/issue-89280-emitter-overflow-splice-lines.rs b/src/test/ui/errors/issue-89280-emitter-overflow-splice-lines.rs
new file mode 100644
index 00000000000..a1c7af128d2
--- /dev/null
+++ b/src/test/ui/errors/issue-89280-emitter-overflow-splice-lines.rs
@@ -0,0 +1,10 @@
+// check-pass
+
+trait X {
+    fn test(x: u32, (
+//~^ WARN anonymous parameters are deprecated and will be removed in the next edition
+//~^^ WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
+    )) {}
+}
+
+fn main() {}
diff --git a/src/test/ui/errors/issue-89280-emitter-overflow-splice-lines.stderr b/src/test/ui/errors/issue-89280-emitter-overflow-splice-lines.stderr
new file mode 100644
index 00000000000..4ec78a298fe
--- /dev/null
+++ b/src/test/ui/errors/issue-89280-emitter-overflow-splice-lines.stderr
@@ -0,0 +1,23 @@
+warning: anonymous parameters are deprecated and will be removed in the next edition
+  --> $DIR/issue-89280-emitter-overflow-splice-lines.rs:4:21
+   |
+LL |       fn test(x: u32, (
+   |  _____________________^
+LL | |
+LL | |
+LL | |     )) {}
+   | |_____^
+   |
+   = note: `#[warn(anonymous_parameters)]` on by default
+   = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
+   = note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>
+help: try naming the parameter or explicitly ignoring it
+   |
+LL ~     fn test(x: u32, _: (
+LL +
+LL +
+LL ~     )) {}
+   |
+
+warning: 1 warning emitted
+