diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs index b5b34c7338d88..b2604ea690851 100644 --- a/compiler/rustc_parse/src/lexer/mod.rs +++ b/compiler/rustc_parse/src/lexer/mod.rs @@ -532,10 +532,15 @@ impl<'a> StringReader<'a> { if let Err(err) = result { let span_with_quotes = self.mk_sp(content_start - BytePos(1), content_end + BytePos(1)); + let (start, end) = (range.start as u32, range.end as u32); + let lo = content_start + BytePos(start); + let hi = lo + BytePos(end - start); + let span = self.mk_sp(lo, hi); emit_unescape_error( &self.sess.span_diagnostic, lit_content, span_with_quotes, + span, mode, range, err, diff --git a/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs b/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs index 47d317f918865..6a890be36956a 100644 --- a/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs +++ b/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs @@ -13,6 +13,8 @@ pub(crate) fn emit_unescape_error( lit: &str, // full span of the literal, including quotes span_with_quotes: Span, + // interior span of the literal, without quotes + span: Span, mode: Mode, // range of the error inside `lit` range: Range, @@ -26,13 +28,6 @@ pub(crate) fn emit_unescape_error( range, error ); - let span = { - let Range { start, end } = range; - let (start, end) = (start as u32, end as u32); - let lo = span_with_quotes.lo() + BytePos(start + 1); - let hi = lo + BytePos(end - start); - span_with_quotes.with_lo(lo).with_hi(hi) - }; let last_char = || { let c = lit[range.clone()].chars().rev().next().unwrap(); let span = span.with_lo(span.hi() - BytePos(c.len_utf8() as u32)); diff --git a/src/test/ui/attributes/key-value-non-ascii.rs b/src/test/ui/attributes/key-value-non-ascii.rs new file mode 100644 index 0000000000000..96c77f4f865e4 --- /dev/null +++ b/src/test/ui/attributes/key-value-non-ascii.rs @@ -0,0 +1,5 @@ +#![feature(rustc_attrs)] + +#[rustc_dummy = b"ffi.rs"] //~ ERROR byte constant must be ASCII + //~| ERROR byte constant must be ASCII +fn main() {} diff --git a/src/test/ui/attributes/key-value-non-ascii.stderr b/src/test/ui/attributes/key-value-non-ascii.stderr new file mode 100644 index 0000000000000..43df0e453bb04 --- /dev/null +++ b/src/test/ui/attributes/key-value-non-ascii.stderr @@ -0,0 +1,14 @@ +error: byte constant must be ASCII. Use a \xHH escape for a non-ASCII byte + --> $DIR/key-value-non-ascii.rs:3:19 + | +LL | #[rustc_dummy = b"ffi.rs"] + | ^ + +error: byte constant must be ASCII. Use a \xHH escape for a non-ASCII byte + --> $DIR/key-value-non-ascii.rs:3:21 + | +LL | #[rustc_dummy = b"ffi.rs"] + | ^^^ + +error: aborting due to 2 previous errors +