diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index af556c576c035..84d5a8df4adbe 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -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, diff --git a/src/test/ui/issue-47377.rs b/src/test/ui/issue-47377.rs new file mode 100644 index 0000000000000..f294008cfd0d5 --- /dev/null +++ b/src/test/ui/issue-47377.rs @@ -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 or the MIT license +// , 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 +} diff --git a/src/test/ui/issue-47377.stderr b/src/test/ui/issue-47377.stderr new file mode 100644 index 0000000000000..13b3ff5869783 --- /dev/null +++ b/src/test/ui/issue-47377.stderr @@ -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 + diff --git a/src/test/ui/issue-47380.rs b/src/test/ui/issue-47380.rs new file mode 100644 index 0000000000000..e43a967253ca8 --- /dev/null +++ b/src/test/ui/issue-47380.rs @@ -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 or the MIT license +// , 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 +} diff --git a/src/test/ui/issue-47380.stderr b/src/test/ui/issue-47380.stderr new file mode 100644 index 0000000000000..6c9f79b5a9417 --- /dev/null +++ b/src/test/ui/issue-47380.stderr @@ -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 +