From 4cedbfc6ee8ef3d35abc22c69903ab3b9573939f Mon Sep 17 00:00:00 2001 From: Gauri Date: Sat, 13 Jan 2018 11:59:35 +0530 Subject: fix mispositioned span --- src/librustc_errors/emitter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/librustc_errors') diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index af556c576c0..ae0766eeeef 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -1187,7 +1187,7 @@ 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_start = span_start_pos.col_display + start; let underline_end = span_start_pos.col.0 + start + sub_len; for p in underline_start..underline_end { buffer.putc(row_num, -- cgit 1.4.1-3-g733a5 From 3c8c5051b18c604a4a1c0a01a6515ff3852341e1 Mon Sep 17 00:00:00 2001 From: Gauri Date: Sat, 13 Jan 2018 17:13:18 +0530 Subject: add ui test --- src/librustc_errors/emitter.rs | 2 +- src/test/ui/issue-47377-1.rs | 14 ++++++++++++++ src/test/ui/issue-47377-1.stderr | 12 ++++++++++++ src/test/ui/issue-47377.rs | 14 ++++++++++++++ src/test/ui/issue-47377.stderr | 12 ++++++++++++ 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/issue-47377-1.rs create mode 100644 src/test/ui/issue-47377-1.stderr create mode 100644 src/test/ui/issue-47377.rs create mode 100644 src/test/ui/issue-47377.stderr (limited to 'src/librustc_errors') diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index ae0766eeeef..84d5a8df4ad 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -1188,7 +1188,7 @@ impl EmitterWriter { acc + unicode_width::UnicodeWidthChar::width(ch).unwrap_or(0) }); let underline_start = span_start_pos.col_display + start; - let underline_end = span_start_pos.col.0 + start + sub_len; + 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-1.rs b/src/test/ui/issue-47377-1.rs new file mode 100644 index 00000000000..f173d009638 --- /dev/null +++ b/src/test/ui/issue-47377-1.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 13:37: 13:51: binary operation `+` cannot be applied to type `&str` [E0369] +} \ No newline at end of file diff --git a/src/test/ui/issue-47377-1.stderr b/src/test/ui/issue-47377-1.stderr new file mode 100644 index 00000000000..aad5373ae00 --- /dev/null +++ b/src/test/ui/issue-47377-1.stderr @@ -0,0 +1,12 @@ +error[E0369]: binary operation `+` cannot be applied to type `&str` + --> $DIR/issue-47377-1.rs:13:37 + | +13 | println!("🦀🦀🦀🦀🦀"); let _a = b + ", World!"; //~ERROR 13:37: 13:51: binary operation `+` cannot be applied to type `&str` [E0369] + | ^^^^^^^^^^^^^^ `+` 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 | println!("🦀🦀🦀🦀🦀"); let _a = b.to_owned() + ", World!"; //~ERROR 13:37: 13:51: binary operation `+` cannot be applied to type `&str` [E0369] + | ^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/issue-47377.rs b/src/test/ui/issue-47377.rs new file mode 100644 index 00000000000..2a8f2e30c0e --- /dev/null +++ b/src/test/ui/issue-47377.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"; + let _a = b + ", World!"; //~ERROR 13:14: 13:28: binary operation `+` cannot be applied to type `&str` [E0369] +} \ No newline at end of file diff --git a/src/test/ui/issue-47377.stderr b/src/test/ui/issue-47377.stderr new file mode 100644 index 00000000000..e9f285a19c3 --- /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:14 + | +13 | let _a = b + ", World!"; //~ERROR 13:14: 13:28: binary operation `+` cannot be applied to type `&str` [E0369] + | ^^^^^^^^^^^^^^ `+` 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 13:14: 13:28: binary operation `+` cannot be applied to type `&str` [E0369] + | ^^^^^^^^^^^^ + +error: aborting due to previous error + -- cgit 1.4.1-3-g733a5