Rollup merge of #81307 - estebank:invalid-byte-str-span, r=petrochenkov

Handle `Span`s for byte and raw strings and add more detail

CC #81208.
This commit is contained in:
Mara Bos 2021-02-05 12:25:53 +01:00 committed by GitHub
commit 8d49ca11a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 279 additions and 184 deletions

View file

@ -1,4 +1,4 @@
#![feature(rustc_attrs)]
#[rustc_dummy = b"ffi.rs"] //~ ERROR byte constant must be ASCII
#[rustc_dummy = b"ffi.rs"] //~ ERROR non-ASCII character in byte constant
fn main() {}

View file

@ -1,8 +1,11 @@
error: byte constant must be ASCII. Use a \xHH escape for a non-ASCII byte
error: non-ASCII character in byte constant
--> $DIR/key-value-non-ascii.rs:3:19
|
LL | #[rustc_dummy = b"ffi.rs"]
| ^
| |
| byte constant must be ASCII
| help: use a \xHH escape for a non-ASCII byte: `\xFB03`
error: aborting due to previous error

View file

@ -1,6 +1,6 @@
fn main() {
let x = "\x80"; //~ ERROR may only be used
let y = "\xff"; //~ ERROR may only be used
let z = "\xe2"; //~ ERROR may only be used
let x = "\x80"; //~ ERROR out of range hex escape
let y = "\xff"; //~ ERROR out of range hex escape
let z = "\xe2"; //~ ERROR out of range hex escape
let a = b"\x00e2"; // ok because byte literal
}

View file

@ -1,20 +1,20 @@
error: this form of character escape may only be used with characters in the range [\x00-\x7f]
error: out of range hex escape
--> $DIR/ascii-only-character-escape.rs:2:14
|
LL | let x = "\x80";
| ^^^^
| ^^^^ must be a character in the range [\x00-\x7f]
error: this form of character escape may only be used with characters in the range [\x00-\x7f]
error: out of range hex escape
--> $DIR/ascii-only-character-escape.rs:3:14
|
LL | let y = "\xff";
| ^^^^
| ^^^^ must be a character in the range [\x00-\x7f]
error: this form of character escape may only be used with characters in the range [\x00-\x7f]
error: out of range hex escape
--> $DIR/ascii-only-character-escape.rs:4:14
|
LL | let z = "\xe2";
| ^^^^
| ^^^^ must be a character in the range [\x00-\x7f]
error: aborting due to 3 previous errors

View file

@ -4,17 +4,17 @@
fn main() {
// these literals are just silly.
''';
//~^ ERROR: character constant must be escaped: '
//~^ ERROR: character constant must be escaped: `'`
// note that this is a literal "\n" byte
'
';
//~^^ ERROR: character constant must be escaped: \n
//~^^ ERROR: character constant must be escaped: `\n`
// note that this is a literal "\r" byte
' '; //~ ERROR: character constant must be escaped: \r
' '; //~ ERROR: character constant must be escaped: `\r`
// note that this is a literal tab character here
' ';
//~^ ERROR: character constant must be escaped: \t
//~^ ERROR: character constant must be escaped: `\t`
}

View file

@ -1,28 +1,28 @@
error: character constant must be escaped: '
error: character constant must be escaped: `'`
--> $DIR/bad-char-literals.rs:6:6
|
LL | ''';
| ^
| ^ help: escape the character: `\'`
error: character constant must be escaped: \n
error: character constant must be escaped: `\n`
--> $DIR/bad-char-literals.rs:10:6
|
LL | '
| ______^
LL | | ';
| |_
| |_ help: escape the character: `\n`
error: character constant must be escaped: \r
error: character constant must be escaped: `\r`
--> $DIR/bad-char-literals.rs:15:6
|
LL | ' ';
| ^
| ^ help: escape the character: `\r`
error: character constant must be escaped: \t
error: character constant must be escaped: `\t`
--> $DIR/bad-char-literals.rs:18:6
|
LL | ' ';
| ^^^^
| ^^^^ help: escape the character: `\t`
error: aborting due to 4 previous errors

View file

@ -4,9 +4,9 @@ static FOO: u8 = b'\f'; //~ ERROR unknown byte escape
pub fn main() {
b'\f'; //~ ERROR unknown byte escape
b'\x0Z'; //~ ERROR invalid character in numeric character escape: Z
b'\x0Z'; //~ ERROR invalid character in numeric character escape: `Z`
b' '; //~ ERROR byte constant must be escaped
b'''; //~ ERROR byte constant must be escaped
b'é'; //~ ERROR byte constant must be ASCII
b'é'; //~ ERROR non-ASCII character in byte constant
b'a //~ ERROR unterminated byte constant [E0763]
}

View file

@ -1,38 +1,45 @@
error: unknown byte escape: f
error: unknown byte escape: `f`
--> $DIR/byte-literals.rs:3:21
|
LL | static FOO: u8 = b'\f';
| ^ unknown byte escape
|
= help: for more information, visit <https://static.rust-lang.org/doc/master/reference.html#literals>
error: unknown byte escape: f
error: unknown byte escape: `f`
--> $DIR/byte-literals.rs:6:8
|
LL | b'\f';
| ^ unknown byte escape
|
= help: for more information, visit <https://static.rust-lang.org/doc/master/reference.html#literals>
error: invalid character in numeric character escape: Z
error: invalid character in numeric character escape: `Z`
--> $DIR/byte-literals.rs:7:10
|
LL | b'\x0Z';
| ^
| ^ invalid character in numeric character escape
error: byte constant must be escaped: \t
error: byte constant must be escaped: `\t`
--> $DIR/byte-literals.rs:8:7
|
LL | b' ';
| ^^^^
| ^^^^ help: escape the character: `\t`
error: byte constant must be escaped: '
error: byte constant must be escaped: `'`
--> $DIR/byte-literals.rs:9:7
|
LL | b''';
| ^
| ^ help: escape the character: `\'`
error: byte constant must be ASCII. Use a \xHH escape for a non-ASCII byte
error: non-ASCII character in byte constant
--> $DIR/byte-literals.rs:10:7
|
LL | b'é';
| ^
| |
| byte constant must be ASCII
| help: use a \xHH escape for a non-ASCII byte: `\xE9`
error[E0763]: unterminated byte constant
--> $DIR/byte-literals.rs:11:6

View file

@ -2,7 +2,8 @@ static FOO: &'static [u8] = b"\f"; //~ ERROR unknown byte escape
pub fn main() {
b"\f"; //~ ERROR unknown byte escape
b"\x0Z"; //~ ERROR invalid character in numeric character escape: Z
b"é"; //~ ERROR byte constant must be ASCII
b"\x0Z"; //~ ERROR invalid character in numeric character escape: `Z`
b"é"; //~ ERROR non-ASCII character in byte constant
br##"é"##; //~ ERROR raw byte string must be ASCII
b"a //~ ERROR unterminated double quote byte string
}

View file

@ -1,35 +1,48 @@
error: unknown byte escape: f
error: unknown byte escape: `f`
--> $DIR/byte-string-literals.rs:1:32
|
LL | static FOO: &'static [u8] = b"\f";
| ^ unknown byte escape
|
= help: for more information, visit <https://static.rust-lang.org/doc/master/reference.html#literals>
error: unknown byte escape: f
error: unknown byte escape: `f`
--> $DIR/byte-string-literals.rs:4:8
|
LL | b"\f";
| ^ unknown byte escape
|
= help: for more information, visit <https://static.rust-lang.org/doc/master/reference.html#literals>
error: invalid character in numeric character escape: Z
error: invalid character in numeric character escape: `Z`
--> $DIR/byte-string-literals.rs:5:10
|
LL | b"\x0Z";
| ^
| ^ invalid character in numeric character escape
error: byte constant must be ASCII. Use a \xHH escape for a non-ASCII byte
error: non-ASCII character in byte constant
--> $DIR/byte-string-literals.rs:6:7
|
LL | b"é";
| ^
| |
| byte constant must be ASCII
| help: use a \xHH escape for a non-ASCII byte: `\xE9`
error: raw byte string must be ASCII
--> $DIR/byte-string-literals.rs:7:10
|
LL | br##"é"##;
| ^ must be ASCII
error[E0766]: unterminated double quote byte string
--> $DIR/byte-string-literals.rs:7:6
--> $DIR/byte-string-literals.rs:8:6
|
LL | b"a
| ______^
LL | | }
| |__^
error: aborting due to 5 previous errors
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0766`.

View file

@ -1,9 +1,9 @@
fn main() {
let _ = b"\u{a66e}";
//~^ ERROR unicode escape sequences cannot be used as a byte or in a byte string
//~^ ERROR unicode escape in byte string
let _ = b'\u{a66e}';
//~^ ERROR unicode escape sequences cannot be used as a byte or in a byte string
//~^ ERROR unicode escape in byte string
let _ = b'\u';
//~^ ERROR incorrect unicode escape sequence
@ -12,21 +12,21 @@ fn main() {
//~^ ERROR numeric character escape is too short
let _ = b'\xxy';
//~^ ERROR invalid character in numeric character escape: x
//~^ ERROR invalid character in numeric character escape: `x`
let _ = '\x5';
//~^ ERROR numeric character escape is too short
let _ = '\xxy';
//~^ ERROR invalid character in numeric character escape: x
//~^ ERROR invalid character in numeric character escape: `x`
let _ = b"\u{a4a4} \xf \u";
//~^ ERROR unicode escape sequences cannot be used as a byte or in a byte string
//~^^ ERROR invalid character in numeric character escape:
//~^ ERROR unicode escape in byte string
//~^^ ERROR invalid character in numeric character escape: ` `
//~^^^ ERROR incorrect unicode escape sequence
let _ = "\xf \u";
//~^ ERROR invalid character in numeric character escape:
//~^ ERROR invalid character in numeric character escape: ` `
//~^^ ERROR incorrect unicode escape sequence
let _ = "\u8f";

View file

@ -1,14 +1,18 @@
error: unicode escape sequences cannot be used as a byte or in a byte string
error: unicode escape in byte string
--> $DIR/issue-23620-invalid-escapes.rs:2:15
|
LL | let _ = b"\u{a66e}";
| ^^^^^^^^
| ^^^^^^^^ unicode escape in byte string
|
= help: unicode escape sequences cannot be used as a byte or in a byte string
error: unicode escape sequences cannot be used as a byte or in a byte string
error: unicode escape in byte string
--> $DIR/issue-23620-invalid-escapes.rs:5:15
|
LL | let _ = b'\u{a66e}';
| ^^^^^^^^
| ^^^^^^^^ unicode escape in byte string
|
= help: unicode escape sequences cannot be used as a byte or in a byte string
error: incorrect unicode escape sequence
--> $DIR/issue-23620-invalid-escapes.rs:8:15
@ -24,11 +28,11 @@ error: numeric character escape is too short
LL | let _ = b'\x5';
| ^^^
error: invalid character in numeric character escape: x
error: invalid character in numeric character escape: `x`
--> $DIR/issue-23620-invalid-escapes.rs:14:17
|
LL | let _ = b'\xxy';
| ^
| ^ invalid character in numeric character escape
error: numeric character escape is too short
--> $DIR/issue-23620-invalid-escapes.rs:17:14
@ -36,23 +40,25 @@ error: numeric character escape is too short
LL | let _ = '\x5';
| ^^^
error: invalid character in numeric character escape: x
error: invalid character in numeric character escape: `x`
--> $DIR/issue-23620-invalid-escapes.rs:20:16
|
LL | let _ = '\xxy';
| ^
| ^ invalid character in numeric character escape
error: unicode escape sequences cannot be used as a byte or in a byte string
error: unicode escape in byte string
--> $DIR/issue-23620-invalid-escapes.rs:23:15
|
LL | let _ = b"\u{a4a4} \xf \u";
| ^^^^^^^^
| ^^^^^^^^ unicode escape in byte string
|
= help: unicode escape sequences cannot be used as a byte or in a byte string
error: invalid character in numeric character escape:
error: invalid character in numeric character escape: ` `
--> $DIR/issue-23620-invalid-escapes.rs:23:27
|
LL | let _ = b"\u{a4a4} \xf \u";
| ^
| ^ invalid character in numeric character escape
error: incorrect unicode escape sequence
--> $DIR/issue-23620-invalid-escapes.rs:23:28
@ -62,11 +68,11 @@ LL | let _ = b"\u{a4a4} \xf \u";
|
= help: format of unicode escape sequences is `\u{...}`
error: invalid character in numeric character escape:
error: invalid character in numeric character escape: ` `
--> $DIR/issue-23620-invalid-escapes.rs:28:17
|
LL | let _ = "\xf \u";
| ^
| ^ invalid character in numeric character escape
error: incorrect unicode escape sequence
--> $DIR/issue-23620-invalid-escapes.rs:28:18

View file

@ -1,8 +1,8 @@
error: invalid start of unicode escape
error: invalid start of unicode escape: `_`
--> $DIR/issue-43692.rs:2:9
|
LL | '\u{_10FFFF}';
| ^
| ^ invalid start of unicode escape
error: aborting due to previous error

View file

@ -10,7 +10,7 @@ error: invalid trailing slash in literal
--> $DIR/issue-62913.rs:1:5
|
LL | "\u\"
| ^
| ^ invalid trailing slash in literal
error: expected item, found `"\u\"`
--> $DIR/issue-62913.rs:1:1

View file

@ -1,13 +1,13 @@
error: character literal may only contain one codepoint
--> $DIR/issue-64732.rs:3:17
--> $DIR/issue-64732.rs:3:16
|
LL | let _foo = b'hello\0';
| ^^^^^^^^^
| ^^^^^^^^^^
|
help: if you meant to write a byte string literal, use double quotes
|
LL | let _foo = b"hello\0";
| ^^^^^^^^^
| ^^^^^^^^^^
error: character literal may only contain one codepoint
--> $DIR/issue-64732.rs:6:16

View file

@ -10,17 +10,21 @@ error: numeric character escape is too short
LL | "\x1"
| ^^^
error: unknown character escape: \u{25cf}
error: unknown character escape: `\u{25cf}`
--> $DIR/lex-bad-char-literals-1.rs:10:7
|
LL | '\●'
| ^ unknown character escape
|
= help: for more information, visit <https://static.rust-lang.org/doc/master/reference.html#literals>
error: unknown character escape: \u{25cf}
error: unknown character escape: `\u{25cf}`
--> $DIR/lex-bad-char-literals-1.rs:14:7
|
LL | "\●"
| ^ unknown character escape
|
= help: for more information, visit <https://static.rust-lang.org/doc/master/reference.html#literals>
error: aborting due to 4 previous errors

View file

@ -2,7 +2,7 @@ fn main() {
let _: char = '';
//~^ ERROR: empty character literal
let _: char = '\u{}';
//~^ ERROR: empty unicode escape (must have at least 1 hex digit)
//~^ ERROR: empty unicode escape
// Next two are OK, but may befool error recovery
let _ = '/';

View file

@ -2,13 +2,13 @@ error: empty character literal
--> $DIR/lex-bad-char-literals-7.rs:2:20
|
LL | let _: char = '';
| ^
| ^ empty character literal
error: empty unicode escape (must have at least 1 hex digit)
error: empty unicode escape
--> $DIR/lex-bad-char-literals-7.rs:4:20
|
LL | let _: char = '\u{}';
| ^^^^
| ^^^^ this escape must have at least 1 hex digit
error[E0762]: unterminated character literal
--> $DIR/lex-bad-char-literals-7.rs:11:13

View file

@ -22,5 +22,5 @@ fn main() {
let _s = r"bar foo"; //~ ERROR: bare CR not allowed in raw string
// the following string literal has a bare CR in it
let _s = "foo\ bar"; //~ ERROR: unknown character escape: \r
let _s = "foo\ bar"; //~ ERROR: unknown character escape: `\r`
}

View file

@ -22,11 +22,11 @@ error: bare CR not allowed in block doc-comment
LL | /*! block doc comment with bare CR: ' ' */
| ^
error: bare CR not allowed in string, use \r instead
error: bare CR not allowed in string, use `\r` instead
--> $DIR/lex-bare-cr-string-literal-doc-comment.rs:19:18
|
LL | let _s = "foo bar";
| ^
| ^ help: escape the character: `\r`
error: bare CR not allowed in raw string
--> $DIR/lex-bare-cr-string-literal-doc-comment.rs:22:19
@ -34,7 +34,7 @@ error: bare CR not allowed in raw string
LL | let _s = r"bar foo";
| ^
error: unknown character escape: \r
error: unknown character escape: `\r`
--> $DIR/lex-bare-cr-string-literal-doc-comment.rs:25:19
|
LL | let _s = "foo\ bar";

View file

@ -2,7 +2,7 @@ error: invalid unicode character escape
--> $DIR/literals-are-validated-before-expansion.rs:6:20
|
LL | black_hole! { '\u{FFFFFF}' }
| ^^^^^^^^^^
| ^^^^^^^^^^ invalid escape
|
= help: unicode escape must be at most 10FFFF
@ -10,7 +10,7 @@ error: invalid unicode character escape
--> $DIR/literals-are-validated-before-expansion.rs:8:39
|
LL | black_hole! { "this is surrogate: \u{DAAA}" }
| ^^^^^^^^
| ^^^^^^^^ invalid escape
|
= help: unicode escape must not be a surrogate

View file

@ -1,3 +1,3 @@
pub fn main() {
let s = "\u{2603"; //~ ERROR unterminated unicode escape (needed a `}`)
let s = "\u{2603"; //~ ERROR unterminated unicode escape
}

View file

@ -1,8 +1,13 @@
error: unterminated unicode escape (needed a `}`)
error: unterminated unicode escape
--> $DIR/new-unicode-escapes-1.rs:2:14
|
LL | let s = "\u{2603";
| ^^^^^^^
| ^^^^^^^ missing a closing `}`
|
help: terminate the unicode escape
|
LL | let s = "\u{2603}";
| ^
error: aborting due to previous error

View file

@ -1,3 +1,3 @@
pub fn main() {
let s = "\u{260311111111}"; //~ ERROR overlong unicode escape (must have at most 6 hex digits)
let s = "\u{260311111111}"; //~ ERROR overlong unicode escape
}

View file

@ -1,8 +1,8 @@
error: overlong unicode escape (must have at most 6 hex digits)
error: overlong unicode escape
--> $DIR/new-unicode-escapes-2.rs:2:14
|
LL | let s = "\u{260311111111}";
| ^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^ must have at most 6 hex digits
error: aborting due to previous error

View file

@ -2,7 +2,7 @@ error: invalid unicode character escape
--> $DIR/new-unicode-escapes-3.rs:2:15
|
LL | let s1 = "\u{d805}";
| ^^^^^^^^
| ^^^^^^^^ invalid escape
|
= help: unicode escape must not be a surrogate
@ -10,7 +10,7 @@ error: invalid unicode character escape
--> $DIR/new-unicode-escapes-3.rs:3:15
|
LL | let s2 = "\u{ffffff}";
| ^^^^^^^^^^
| ^^^^^^^^^^ invalid escape
|
= help: unicode escape must be at most 10FFFF

View file

@ -1,4 +1,4 @@
pub fn main() {
let s = "\u{lol}";
//~^ ERROR invalid character in unicode escape: l
//~^ ERROR invalid character in unicode escape: `l`
}

View file

@ -1,8 +1,8 @@
error: invalid character in unicode escape: l
error: invalid character in unicode escape: `l`
--> $DIR/new-unicode-escapes-4.rs:2:17
|
LL | let s = "\u{lol}";
| ^
| ^ invalid character in unicode escape
error: aborting due to previous error

View file

@ -8,7 +8,7 @@ error: raw byte string must be ASCII
--> $DIR/raw-byte-string-literals.rs:5:8
|
LL | br"é";
| ^
| ^ must be ASCII
error: found invalid character; only `#` is allowed in raw string delimitation: ~
--> $DIR/raw-byte-string-literals.rs:6:5

View file

@ -8,7 +8,7 @@ fn main() {
a test";
// \r only
let bad = "This is \ a test";
//~^ ERROR unknown character escape: \r
//~^^ HELP this is an isolated carriage return
//~^ ERROR unknown character escape: `\r`
//~| HELP this is an isolated carriage return
}

View file

@ -1,4 +1,4 @@
error: unknown character escape: \r
error: unknown character escape: `\r`
--> $DIR/trailing-carriage-return-in-string.rs:10:25
|
LL | let bad = "This is \ a test";

View file

@ -1,8 +1,8 @@
fn main() {
let ok = "{{everything fine}}";
let bad = "\{it is wrong\}";
//~^ ERROR unknown character escape: {
//~^^ HELP if used in a formatting string, curly braces are escaped with `{{` and `}}`
//~^^^ ERROR unknown character escape: }
//~^^^^ HELP if used in a formatting string, curly braces are escaped with `{{` and `}}`
//~^ ERROR unknown character escape: `{`
//~| HELP if used in a formatting string, curly braces are escaped with `{{` and `}}`
//~| ERROR unknown character escape: `}`
//~| HELP if used in a formatting string, curly braces are escaped with `{{` and `}}`
}

View file

@ -1,4 +1,4 @@
error: unknown character escape: {
error: unknown character escape: `{`
--> $DIR/wrong-escape-of-curly-braces.rs:3:17
|
LL | let bad = "\{it is wrong\}";
@ -6,7 +6,7 @@ LL | let bad = "\{it is wrong\}";
|
= help: if used in a formatting string, curly braces are escaped with `{{` and `}}`
error: unknown character escape: }
error: unknown character escape: `}`
--> $DIR/wrong-escape-of-curly-braces.rs:3:30
|
LL | let bad = "\{it is wrong\}";