diff options
| author | Fabian Wolff <fabian.wolff@alumni.ethz.ch> | 2021-07-31 14:37:01 +0200 |
|---|---|---|
| committer | Fabian Wolff <fabian.wolff@alumni.ethz.ch> | 2021-07-31 15:21:11 +0200 |
| commit | c1abb6f4d6756086d74008cacf51e42ae2cda7bb (patch) | |
| tree | eeacf856c8aff267961e10762e82865e7779f192 /src | |
| parent | fc24bcead1d401ae061538d011e4a319c4195b56 (diff) | |
| download | rust-c1abb6f4d6756086d74008cacf51e42ae2cda7bb.tar.gz rust-c1abb6f4d6756086d74008cacf51e42ae2cda7bb.zip | |
Fix invalid suggestions for non-ASCII characters in byte constants
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/attributes/key-value-non-ascii.stderr | 10 | ||||
| -rw-r--r-- | src/test/ui/parser/byte-literals.stderr | 10 | ||||
| -rw-r--r-- | src/test/ui/parser/byte-string-literals.stderr | 10 | ||||
| -rw-r--r-- | src/test/ui/suggestions/multibyte-escapes.rs | 18 | ||||
| -rw-r--r-- | src/test/ui/suggestions/multibyte-escapes.stderr | 33 |
5 files changed, 69 insertions, 12 deletions
diff --git a/src/test/ui/attributes/key-value-non-ascii.stderr b/src/test/ui/attributes/key-value-non-ascii.stderr index 1d4b0d5b2b1..01a07ad3b0e 100644 --- a/src/test/ui/attributes/key-value-non-ascii.stderr +++ b/src/test/ui/attributes/key-value-non-ascii.stderr @@ -2,10 +2,12 @@ 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` + | ^ byte constant must be ASCII + | +help: if you meant to use the UTF-8 encoding of 'ffi', use \xHH escapes + | +LL | #[rustc_dummy = b"/xEF/xAC/x83.rs"] + | ^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/parser/byte-literals.stderr b/src/test/ui/parser/byte-literals.stderr index 55be113e16b..b9fb42088d9 100644 --- a/src/test/ui/parser/byte-literals.stderr +++ b/src/test/ui/parser/byte-literals.stderr @@ -36,10 +36,12 @@ 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` + | ^ byte constant must be ASCII + | +help: if you meant to use the unicode code point for 'é', use a \xHH escape + | +LL | b'\xE9'; + | ^^^^ error[E0763]: unterminated byte constant --> $DIR/byte-literals.rs:11:6 diff --git a/src/test/ui/parser/byte-string-literals.stderr b/src/test/ui/parser/byte-string-literals.stderr index 3a5a8b331d3..4f22a16224f 100644 --- a/src/test/ui/parser/byte-string-literals.stderr +++ b/src/test/ui/parser/byte-string-literals.stderr @@ -24,10 +24,12 @@ 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` + | ^ byte constant must be ASCII + | +help: if you meant to use the unicode code point for 'é', use a \xHH escape + | +LL | b"\xE9"; + | ^^^^ error: raw byte string must be ASCII --> $DIR/byte-string-literals.rs:7:10 diff --git a/src/test/ui/suggestions/multibyte-escapes.rs b/src/test/ui/suggestions/multibyte-escapes.rs new file mode 100644 index 00000000000..fd5d46a4e92 --- /dev/null +++ b/src/test/ui/suggestions/multibyte-escapes.rs @@ -0,0 +1,18 @@ +// Regression test for #87397. + +fn main() { + b'µ'; + //~^ ERROR: non-ASCII character in byte constant + //~| HELP: if you meant to use the unicode code point for 'µ', use a \xHH escape + //~| NOTE: byte constant must be ASCII + + b'字'; + //~^ ERROR: non-ASCII character in byte constant + //~| NOTE: this multibyte character does not fit into a single byte + //~| NOTE: byte constant must be ASCII + + b"字"; + //~^ ERROR: non-ASCII character in byte constant + //~| HELP: if you meant to use the UTF-8 encoding of '字', use \xHH escapes + //~| NOTE: byte constant must be ASCII +} diff --git a/src/test/ui/suggestions/multibyte-escapes.stderr b/src/test/ui/suggestions/multibyte-escapes.stderr new file mode 100644 index 00000000000..bb4f8e8c304 --- /dev/null +++ b/src/test/ui/suggestions/multibyte-escapes.stderr @@ -0,0 +1,33 @@ +error: non-ASCII character in byte constant + --> $DIR/multibyte-escapes.rs:4:7 + | +LL | b'µ'; + | ^ byte constant must be ASCII + | +help: if you meant to use the unicode code point for 'µ', use a \xHH escape + | +LL | b'\xB5'; + | ^^^^ + +error: non-ASCII character in byte constant + --> $DIR/multibyte-escapes.rs:9:7 + | +LL | b'字'; + | ^^ + | | + | byte constant must be ASCII + | this multibyte character does not fit into a single byte + +error: non-ASCII character in byte constant + --> $DIR/multibyte-escapes.rs:14:7 + | +LL | b"字"; + | ^^ byte constant must be ASCII + | +help: if you meant to use the UTF-8 encoding of '字', use \xHH escapes + | +LL | b"\xE5\xAD\x97"; + | ^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + |
