From 35192ff574c3706646e2f4be16d5c22c4f8b60b1 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 5 Oct 2020 11:19:08 -0700 Subject: [PATCH] Fix span for unicode escape suggestion. --- compiler/rustc_parse/src/lexer/unescape_error_reporting.rs | 5 ++--- src/test/ui/fmt/format-string-error-2.stderr | 4 +--- src/test/ui/parser/issue-23620-invalid-escapes.stderr | 6 +++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs b/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs index 6f249f491a647..47d317f918865 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, diff --git a/src/test/ui/fmt/format-string-error-2.stderr b/src/test/ui/fmt/format-string-error-2.stderr index d202044a2bb97..c421fe49ef0a4 100644 --- a/src/test/ui/fmt/format-string-error-2.stderr +++ b/src/test/ui/fmt/format-string-error-2.stderr @@ -2,9 +2,7 @@ error: incorrect unicode escape sequence --> $DIR/format-string-error-2.rs:77:20 | LL | println!("\x7B}\u8 {", 1); - | ^^- - | | - | help: format of unicode escape sequences uses braces: `\u{8}` + | ^^^ help: format of unicode escape sequences uses braces: `\u{8}` error: invalid format string: expected `'}'`, found `'a'` --> $DIR/format-string-error-2.rs:5:5 diff --git a/src/test/ui/parser/issue-23620-invalid-escapes.stderr b/src/test/ui/parser/issue-23620-invalid-escapes.stderr index b391ac75bf8d1..8c924ad0330e9 100644 --- a/src/test/ui/parser/issue-23620-invalid-escapes.stderr +++ b/src/test/ui/parser/issue-23620-invalid-escapes.stderr @@ -80,9 +80,9 @@ error: incorrect unicode escape sequence --> $DIR/issue-23620-invalid-escapes.rs:32:14 | LL | let _ = "\u8f"; - | ^^-- - | | - | help: format of unicode escape sequences uses braces: `\u{8f}` + | ^^^- + | | + | help: format of unicode escape sequences uses braces: `\u{8f}` error: aborting due to 13 previous errors