Skip to content

Commit

Permalink
Rollup merge of rust-lang#47407 - gaurikholkar:master, r=estebank
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kennytm authored Jan 17, 2018
2 parents e8774b4 + efe3d69 commit 9d5dc17
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1187,8 +1187,8 @@ impl EmitterWriter {
let sub_len = parts[0].snippet.trim().chars().fold(0, |acc, ch| {
acc + unicode_width::UnicodeWidthChar::width(ch).unwrap_or(0)
});
let underline_start = span_start_pos.col.0 + start;
let underline_end = span_start_pos.col.0 + start + sub_len;
let underline_start = span_start_pos.col_display + start;
let underline_end = span_start_pos.col_display + start + sub_len;
for p in underline_start..underline_end {
buffer.putc(row_num,
max_line_num_len + 3 + p,
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/issue-47377.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-tidy-tab
fn main() {
let b = "hello";
let _a = b + ", World!";
//~^ ERROR E0369
}
12 changes: 12 additions & 0 deletions src/test/ui/issue-47377.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0369]: binary operation `+` cannot be applied to type `&str`
--> $DIR/issue-47377.rs:13:12
|
13 | 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
|
13 | let _a = b.to_owned() + ", World!";
| ^^^^^^^^^^^^

error: aborting due to previous error

14 changes: 14 additions & 0 deletions src/test/ui/issue-47380.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
let b = "hello";
println!("πŸ¦€πŸ¦€πŸ¦€πŸ¦€πŸ¦€"); let _a = b + ", World!";
//~^ ERROR E0369
}
12 changes: 12 additions & 0 deletions src/test/ui/issue-47380.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0369]: binary operation `+` cannot be applied to type `&str`
--> $DIR/issue-47380.rs:12:33
|
12 | println!("πŸ¦€πŸ¦€πŸ¦€πŸ¦€πŸ¦€"); 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
|
12 | println!("πŸ¦€πŸ¦€πŸ¦€πŸ¦€πŸ¦€"); let _a = b.to_owned() + ", World!";
| ^^^^^^^^^^^^

error: aborting due to previous error

0 comments on commit 9d5dc17

Please sign in to comment.