Skip to content

Commit 27a7ced

Browse files
authored
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````
2 parents e98669a + d2dc0f3 commit 27a7ced

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

compiler/rustc_errors/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl CodeSuggestion {
341341
});
342342
buf.push_str(&part.snippet);
343343
let cur_hi = sm.lookup_char_pos(part.span.hi());
344-
if prev_hi.line == cur_lo.line {
344+
if prev_hi.line == cur_lo.line && cur_hi.line == cur_lo.line {
345345
// Account for the difference between the width of the current code and the
346346
// snippet being suggested, so that the *later* suggestions are correctly
347347
// aligned on the screen.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// check-pass
2+
3+
trait X {
4+
fn test(x: u32, (
5+
//~^ WARN anonymous parameters are deprecated and will be removed in the next edition
6+
//~^^ WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
7+
)) {}
8+
}
9+
10+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
warning: anonymous parameters are deprecated and will be removed in the next edition
2+
--> $DIR/issue-89280-emitter-overflow-splice-lines.rs:4:21
3+
|
4+
LL | fn test(x: u32, (
5+
| _____________________^
6+
LL | |
7+
LL | |
8+
LL | | )) {}
9+
| |_____^
10+
|
11+
= note: `#[warn(anonymous_parameters)]` on by default
12+
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
13+
= note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>
14+
help: try naming the parameter or explicitly ignoring it
15+
|
16+
LL ~ fn test(x: u32, _: (
17+
LL +
18+
LL +
19+
LL ~ )) {}
20+
|
21+
22+
warning: 1 warning emitted
23+

0 commit comments

Comments
 (0)