Skip to content

Commit

Permalink
Rollup merge of rust-lang#89912 - davidtwco:issue-89280-split-lines-m…
Browse files Browse the repository at this point in the history
…ultiple-lines, r=oli-obk

emitter: current substitution can be multi-line

Fixes rust-lang#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`
  • Loading branch information
matthiaskrgr authored Oct 15, 2021
2 parents d401815 + d2dc0f3 commit 817c69b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/errors/issue-89280-emitter-overflow-splice-lines.rs
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 817c69b

Please sign in to comment.