Skip to content

Suggest character encoding is incorrect when encountering random null bytes #81856

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 28, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/rustc_parse/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 be encoded in UTF-8, unexpected null bytes might occur when the wrong text encoding is used");
}
err.emit();
token?
}
Expand Down
Binary file modified src/test/ui/parser/issue-66473.stderr
Binary file not shown.
Binary file modified src/test/ui/parser/issue-68629.stderr
Binary file not shown.
Binary file modified src/test/ui/parser/issue-68730.stderr
Binary file not shown.
Binary file added src/test/ui/parser/utf16-be-without-bom.rs
Binary file not shown.
Binary file added src/test/ui/parser/utf16-be-without-bom.stderr
Binary file not shown.
Binary file added src/test/ui/parser/utf16-le-without-bom.rs
Binary file not shown.
Binary file added src/test/ui/parser/utf16-le-without-bom.stderr
Binary file not shown.