about summary refs log tree commit diff
path: root/src/librustc_errors
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2017-12-10 23:35:53 -0800
committerEsteban Küber <esteban@kuber.com.ar>2017-12-14 22:51:42 -0800
commitc60aab29f1a84b799d4b2a27ed26eeda29438eda (patch)
tree0e92783df5f21256b5059f20f9eed554364b3d90 /src/librustc_errors
parent933103190950c97b966e789e9206bff2f7bd6118 (diff)
downloadrust-c60aab29f1a84b799d4b2a27ed26eeda29438eda.tar.gz
rust-c60aab29f1a84b799d4b2a27ed26eeda29438eda.zip
When attempting to write str with single quote suggest double quotes
Diffstat (limited to 'src/librustc_errors')
-rw-r--r--src/librustc_errors/Cargo.toml1
-rw-r--r--src/librustc_errors/emitter.rs6
-rw-r--r--src/librustc_errors/lib.rs1
3 files changed, 7 insertions, 1 deletions
diff --git a/src/librustc_errors/Cargo.toml b/src/librustc_errors/Cargo.toml
index c72e9dd0ea3..3e15af7558d 100644
--- a/src/librustc_errors/Cargo.toml
+++ b/src/librustc_errors/Cargo.toml
@@ -12,3 +12,4 @@ crate-type = ["dylib"]
 serialize = { path = "../libserialize" }
 syntax_pos = { path = "../libsyntax_pos" }
 rustc_data_structures = { path = "../librustc_data_structures" }
+unicode-width = "0.1.4"
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs
index 6bba6fbc295..af556c576c0 100644
--- a/src/librustc_errors/emitter.rs
+++ b/src/librustc_errors/emitter.rs
@@ -23,6 +23,7 @@ use std::rc::Rc;
 use term;
 use std::collections::HashMap;
 use std::cmp::min;
+use unicode_width;
 
 /// Emitter trait for emitting errors.
 pub trait Emitter {
@@ -1182,7 +1183,10 @@ impl EmitterWriter {
                 if show_underline {
                     draw_col_separator(&mut buffer, row_num, max_line_num_len + 1);
                     let start = parts[0].snippet.len() - parts[0].snippet.trim_left().len();
-                    let sub_len = parts[0].snippet.trim().len();
+                    // account for substitutions containing unicode characters
+                    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;
                     for p in underline_start..underline_end {
diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs
index 605cfc5ed12..840346c447b 100644
--- a/src/librustc_errors/lib.rs
+++ b/src/librustc_errors/lib.rs
@@ -26,6 +26,7 @@ extern crate libc;
 extern crate rustc_data_structures;
 extern crate serialize as rustc_serialize;
 extern crate syntax_pos;
+extern crate unicode_width;
 
 pub use emitter::ColorConfig;