-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Fix logical error with what text is considered whitespace. #134366
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @jieyouxu (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
Addresses: #132918 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. We'll need to add a regression test for #132918 to prevent it from happening again in the future. Note that the test probably will need to be marked with
//@ needs-rustc-debug-assertions
to catch the overflow assertion that only happens if rustc was built with debug assertions.
Might also need to artificially constrain diagnostics width with something like
//@ compile-flags: --diagnostics-width=80
to prevent terminal size from interfering with test outcome. I'm not super familiar with what the logic here is intended to do, so I'm going to reroll a WG-diagnostics reviewer.
r? diagnostics |
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.
155565f
to
1e33dd1
Compare
Thank you for the prompt response and guidance on adding a compilation tests. I've fixed the typo and added a test case and confirmed that it doesn't pass on master and does pass on this branch. |
This comment has been minimized.
This comment has been minimized.
2d0fc53
to
1e33dd1
Compare
I noticed also that rust/compiler/rustc_errors/src/emitter.rs Line 789 in 1e33dd1
rustc_lexer::is_whitespace . I figured I'd stick to the failure case I could re-produce.
|
@rustbot review |
I'd be happy to see this changed to @bors r+ rollup |
Rollup of 5 pull requests Successful merges: - rust-lang#134366 (Fix logical error with what text is considered whitespace.) - rust-lang#134514 (Improve dependency_format a bit) - rust-lang#134519 (ci: use ubuntu `24` instead of `latest`) - rust-lang#134551 (coverage: Rename `basic_coverage_blocks` to just `graph`) - rust-lang#134553 (add member constraints comment) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 5 pull requests Successful merges: - rust-lang#134366 (Fix logical error with what text is considered whitespace.) - rust-lang#134514 (Improve dependency_format a bit) - rust-lang#134519 (ci: use ubuntu `24` instead of `latest`) - rust-lang#134551 (coverage: Rename `basic_coverage_blocks` to just `graph`) - rust-lang#134553 (add member constraints comment) r? `@ghost` `@rustbot` modify labels: rollup
…avidtwco Fix logical error with what text is considered whitespace. There appears to be 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. In that case the subtraction will cause a ICE (for a compiler in debug mode) as described in rust-lang#132918.
…avidtwco Fix logical error with what text is considered whitespace. There appears to be 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. In that case the subtraction will cause a ICE (for a compiler in debug mode) as described in rust-lang#132918.
Rollup merge of rust-lang#134366 - harrisonkaiser:no-break-space, r=davidtwco Fix logical error with what text is considered whitespace. There appears to be 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. In that case the subtraction will cause a ICE (for a compiler in debug mode) as described in rust-lang#132918.
There appears to be 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. In that case the subtraction will cause a ICE (for a compiler in debug mode) as described in #132918.