Compiling a file with a non-ASCII name with --error-format=short
enabled makes error messages contain excessive spaces after "filename:line:column"
#65119
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-Unicode
Area: Unicode
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Consider the following rust source (in
test.rs
):It is obvious that it has syntax error. It also seems obvious that the generated error shouldn't depend on name of file except noting the name of file. However, it doesn't happen in practice:
Note extra spaces after
тест.rs:2:14:
.Rust version (although it is not strictly relevant, see below):
The core issue lies in the implementation of
StyledBuffer::prepend
method. The idea of the code is to make enough space in the beginning of line (filled with spaces) and then overwrite it character by character. However, in order to estimate the required space, it uses.len()
which is wrong sincestr
in Rust can contain non-ASCII which require more than one byte for storage andStyledBuffer
keeps lines inVec<char>
s. It means that this isuue reveals itself only when a non-ASCII string is passed as an argument — and that's exactly what's happening inEmitterWriter::emit_message_default
under very specific circumstances: when processing a primary file, whenself.short_message
is set (i. e.--error-message=short
) and when name of the primary file happens to have a non-ASCII name.The errorneous code for
StyledBuffer::prepend
was introduced in 2e8e73c. This bug landed in stable in 1.28.0.The obvious fix is to change the line in
prepend
intocc @estebank
The text was updated successfully, but these errors were encountered: