about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
diff options
context:
space:
mode:
authorYuki Okushi <huyuumi.dev@gmail.com>2020-10-06 16:26:14 +0900
committerGitHub <noreply@github.com>2020-10-06 16:26:14 +0900
commitcc908f3b7005eb9762f81148e3668603edd92003 (patch)
treea86e43aed454006d920707a213e974d77bd69dcb /compiler/rustc_parse/src
parentcdaf8c5f7164b6ea940ebdb066833895719e09f1 (diff)
parent35192ff574c3706646e2f4be16d5c22c4f8b60b1 (diff)
downloadrust-cc908f3b7005eb9762f81148e3668603edd92003.tar.gz
rust-cc908f3b7005eb9762f81148e3668603edd92003.zip
Rollup merge of #77587 - ehuss:unicode-escape-span, r=ecstatic-morse
Fix span for unicode escape suggestion.

If a unicode escape is missing the curly braces, the suggested fix is to add the curly braces, but the span for the fix was incorrect. It was not covering the `\u`, but the suggested text includes the `\u`, causing the resulting fix to be `"\u\u{1234}"`. This changes it so that the span includes the `\u`. An alternate fix would be to remove `\u` from the suggested fix, but I think the error message reads better if the entire escape is included.
Diffstat (limited to 'compiler/rustc_parse/src')
-rw-r--r--compiler/rustc_parse/src/lexer/unescape_error_reporting.rs5
1 files changed, 2 insertions, 3 deletions
diff --git a/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs b/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs
index 6f249f491a6..47d317f9188 100644
--- a/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs
+++ b/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs
@@ -181,10 +181,9 @@ pub(crate) fn emit_unescape_error(
 
             if suggestion_len > 0 {
                 suggestion.push('}');
-                let lo = char_span.lo();
-                let hi = lo + BytePos(suggestion_len as u32);
+                let hi = char_span.lo() + BytePos(suggestion_len as u32);
                 diag.span_suggestion(
-                    span.with_lo(lo).with_hi(hi),
+                    span.with_hi(hi),
                     "format of unicode escape sequences uses braces",
                     suggestion,
                     Applicability::MaybeIncorrect,