diff options
| author | Harrison Kaiser <uwaces@gmail.com> | 2024-12-15 20:06:02 -0500 |
|---|---|---|
| committer | Harrison Kaiser <uwaces@gmail.com> | 2024-12-16 23:34:46 -0500 |
| commit | 1e33dd17115ca948c6e5ebf319695ed64490b2bf (patch) | |
| tree | 4913499178aa13e7f003fbbd22571585bb8a91d8 /tests/ui/errors | |
| parent | 13b77c687c0f5ad06a579af6d0787fe562747501 (diff) | |
| download | rust-1e33dd17115ca948c6e5ebf319695ed64490b2bf.tar.gz rust-1e33dd17115ca948c6e5ebf319695ed64490b2bf.zip | |
Fix logical error with what text is considered whitespace.
There is a logical issue around what counts as leading white-space. There is code which does a subtraction assuming that no errors will be reported inside the leading whitespace. However we compute the length of that whitespace with std::char::is_whitespace and not rustc_lexer::is_whitespace. The former will include a no-break space while later will excluded it. We can only safely make the assumption that no errors will be reported in whitespace if it is all "Rust Standard" whitespace. Indeed an error does occur in unicode whitespace if it contains a no-break space.
Diffstat (limited to 'tests/ui/errors')
| -rw-r--r-- | tests/ui/errors/emitter-overflow-bad-whitespace.rs | 11 | ||||
| -rw-r--r-- | tests/ui/errors/emitter-overflow-bad-whitespace.stderr | 13 |
2 files changed, 24 insertions, 0 deletions
diff --git a/tests/ui/errors/emitter-overflow-bad-whitespace.rs b/tests/ui/errors/emitter-overflow-bad-whitespace.rs new file mode 100644 index 00000000000..d024d1f3921 --- /dev/null +++ b/tests/ui/errors/emitter-overflow-bad-whitespace.rs @@ -0,0 +1,11 @@ +// Invalid whitespace (not listed here: https://doc.rust-lang.org/reference/whitespace.html +// e.g. \u{a0}) before any other syntax on the line should not cause any integer overflow +// in the emitter, even when the terminal width causes the line to be truncated. +// +// issue #132918 + +//@ check-fail +//@ needs-rustc-debug-assertions +//@ compile-flags: --diagnostic-width=1 + fn main() { return; } +//~^ ERROR unknown start of token: \u{a0} diff --git a/tests/ui/errors/emitter-overflow-bad-whitespace.stderr b/tests/ui/errors/emitter-overflow-bad-whitespace.stderr new file mode 100644 index 00000000000..8c0c097bcb9 --- /dev/null +++ b/tests/ui/errors/emitter-overflow-bad-whitespace.stderr @@ -0,0 +1,13 @@ +error: unknown start of token: \u{a0} + --> $DIR/emitter-overflow-bad-whitespace.rs:10:1 + | +LL | ... + | ^ + | +help: Unicode character ' ' (No-Break Space) looks like ' ' (Space), but it is not + | +LL | fn main() { return; } + | + + +error: aborting due to 1 previous error + |
