mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-01 17:42:47 +00:00
Rollup merge of #81856 - Smittyvb:utf16-warn, r=matthewjasper
Suggest character encoding is incorrect when encountering random null bytes This adds a note whenever null bytes are seen at the start of a token unexpectedly, since those tend to come from UTF-16 encoded files without a [BOM](https://en.wikipedia.org/wiki/Byte_order_mark) (if a UTF-16 BOM appears it won't be valid UTF-8, but if there is no BOM it be both valid UTF-16 and valid but garbled UTF-8). This approach was suggested in https://github.com/rust-lang/rust/issues/73979#issuecomment-653976451. Closes #73979.
This commit is contained in:
commit
be3d1eb301
@ -268,6 +268,9 @@ impl<'a> StringReader<'a> {
|
||||
// tokens like `<<` from `rustc_lexer`, and then add fancier error recovery to it,
|
||||
// as there will be less overall work to do this way.
|
||||
let token = unicode_chars::check_for_substitution(self, start, c, &mut err);
|
||||
if c == '\x00' {
|
||||
err.help("source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used");
|
||||
}
|
||||
err.emit();
|
||||
token?
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
src/test/ui/parser/utf16-be-without-bom.rs
Normal file
BIN
src/test/ui/parser/utf16-be-without-bom.rs
Normal file
Binary file not shown.
BIN
src/test/ui/parser/utf16-be-without-bom.stderr
Normal file
BIN
src/test/ui/parser/utf16-be-without-bom.stderr
Normal file
Binary file not shown.
BIN
src/test/ui/parser/utf16-le-without-bom.rs
Normal file
BIN
src/test/ui/parser/utf16-le-without-bom.rs
Normal file
Binary file not shown.
BIN
src/test/ui/parser/utf16-le-without-bom.stderr
Normal file
BIN
src/test/ui/parser/utf16-le-without-bom.stderr
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user