Skip to content

Commit bd8aa02

Browse files
authored
Rollup merge of rust-lang#47407 - gaurikholkar:master, r=estebank
fix mispositioned span This fixes rust-lang#47377 The output now looks like this ``` error[E0369]: binary operation `+` cannot be applied to type `&str` --> h.rs:3:11 | 3 | let _a = b + ", World!"; | ^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left | 3 | let _a = b.to_owned() + ", World!"; | ^^^^^^^^^ error: aborting due to previous error ``` For the case when emojis are involved, it gives the new output for proper indentation. But for an indentation as follows, ``` fn main() { let b = "hello"; let _a = b + ", World!"; } ``` it still mispositions the span ``` 3 | println!("πŸ¦€πŸ¦€πŸ¦€πŸ¦€πŸ¦€"); let _a = b + ", World!"; | ^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings | 3 | println!("πŸ¦€πŸ¦€πŸ¦€πŸ¦€πŸ¦€"); let _a = b.to_owned() + ", World!"; | ^^^^^^^ error: aborting due to previous erro ``` cc @estebank @est31
2 parents e7087f0 + efe3d69 commit bd8aa02

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

β€Žsrc/librustc_errors/emitter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1187,8 +1187,8 @@ impl EmitterWriter {
11871187
let sub_len = parts[0].snippet.trim().chars().fold(0, |acc, ch| {
11881188
acc + unicode_width::UnicodeWidthChar::width(ch).unwrap_or(0)
11891189
});
1190-
let underline_start = span_start_pos.col.0 + start;
1191-
let underline_end = span_start_pos.col.0 + start + sub_len;
1190+
let underline_start = span_start_pos.col_display + start;
1191+
let underline_end = span_start_pos.col_display + start + sub_len;
11921192
for p in underline_start..underline_end {
11931193
buffer.putc(row_num,
11941194
max_line_num_len + 3 + p,

β€Žsrc/test/ui/issue-47377.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
// ignore-tidy-tab
11+
fn main() {
12+
let b = "hello";
13+
let _a = b + ", World!";
14+
//~^ ERROR E0369
15+
}

β€Žsrc/test/ui/issue-47377.stderr

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0369]: binary operation `+` cannot be applied to type `&str`
2+
--> $DIR/issue-47377.rs:13:12
3+
|
4+
13 | let _a = b + ", World!";
5+
| ^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings
6+
help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
7+
|
8+
13 | let _a = b.to_owned() + ", World!";
9+
| ^^^^^^^^^^^^
10+
11+
error: aborting due to previous error
12+

β€Žsrc/test/ui/issue-47380.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
fn main() {
11+
let b = "hello";
12+
println!("πŸ¦€πŸ¦€πŸ¦€πŸ¦€πŸ¦€"); let _a = b + ", World!";
13+
//~^ ERROR E0369
14+
}

β€Žsrc/test/ui/issue-47380.stderr

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0369]: binary operation `+` cannot be applied to type `&str`
2+
--> $DIR/issue-47380.rs:12:33
3+
|
4+
12 | println!("πŸ¦€πŸ¦€πŸ¦€πŸ¦€πŸ¦€"); let _a = b + ", World!";
5+
| ^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings
6+
help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
7+
|
8+
12 | println!("πŸ¦€πŸ¦€πŸ¦€πŸ¦€πŸ¦€"); let _a = b.to_owned() + ", World!";
9+
| ^^^^^^^^^^^^
10+
11+
error: aborting due to previous error
12+

0 commit comments

Comments
Β (0)