Skip to content

Add warning when whitespace is not skipped after an escaped newline - #87596

Merged
bors merged 1 commit into
rust-lang:masterfrom
jesyspa:issue-87318-hidden-whitespace
Jul 30, 2021
Merged

Add warning when whitespace is not skipped after an escaped newline#87596
bors merged 1 commit into
rust-lang:masterfrom
jesyspa:issue-87318-hidden-whitespace

Conversation

@jesyspa

Copy link
Copy Markdown
Contributor

Fixes issue #87318, also simplifies issue #87319.

  • Add support to the lexer to emit warnings as well as errors.
  • Emit a warning when a string literal contains an escaped newline, but when (some of) the whitespace on the next line is not skipped due to it being non-ASCII.

@rust-highfive

Copy link
Copy Markdown
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @estebank (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 29, 2021
@jesyspa

jesyspa commented Jul 29, 2021

Copy link
Copy Markdown
ContributorAuthor

One thing I was wondering about: prior to this PR, the lexer only has support for emitting errors. I've added warnings by changing the callback, but I'm not sure it's the best approach. Is it too messy?

One other option would be to pass an emit_char and an emit_err callback, since those require mostly orthogonal code, but that would require a bit more reworking of the unescape.rs internals.

@rust-log-analyzer

This comment has been minimized.

@jesyspa

Copy link
Copy Markdown
ContributorAuthor

Sorry, I missed the clippy code when testing locally. I'll update the PR and re-run the checks.

@jesyspa
jesyspaforce-pushed the issue-87318-hidden-whitespace branch 2 times, most recently from 53a297d to d7f524fCompareJuly 29, 2021 18:51
Comment threadcompiler/rustc_lexer/src/unescape.rs Outdated
Comment threadcompiler/rustc_lexer/src/unescape.rs Outdated
Comment threadcompiler/rustc_lexer/src/unescape.rs Outdated
Comment threadcompiler/rustc_lexer/src/unescape.rs Outdated
Comment on lines 63 to 74

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle I'm ok with the approach of nested Results, but in this case it feels like a better way would be to make UnskippedWhitespaceAfterEscapedNewline a variant of EscapeError. I know it muddles the waters a little bit by mixing warnings and errors, but I feel it is worth it due to the flattening of the code in this PR.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I've changed it to be a single type. Should I also change the name to EscapeDiagnostic, or is that too vague?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like EscapeError is slightly misleading, but it'll make more sense than EscapeDiagnostic.

@jesyspa
jesyspaforce-pushed the issue-87318-hidden-whitespace branch from fcd287c to bc8bbebCompareJuly 30, 2021 14:11
@rust-log-analyzer

This comment has been minimized.

@jesyspa
jesyspaforce-pushed the issue-87318-hidden-whitespace branch from bc8bbeb to 5d59b44CompareJuly 30, 2021 14:27
@estebank

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Jul 30, 2021

Copy link
Copy Markdown
Collaborator

📌 Commit 5d59b44 has been approved by estebank

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 30, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jul 30, 2021
…ce, r=estebank
Add warning when whitespace is not skipped after an escaped newline
Fixes issue rust-lang#87318, also simplifies issue rust-lang#87319.
* Add support to the lexer to emit warnings as well as errors.
* Emit a warning when a string literal contains an escaped newline, but when (some of) the whitespace on the next line is not skipped due to it being non-ASCII.
This was referenced Jul 30, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 30, 2021
Rollup of 9 pull requests
Successful merges:
- rust-lang#86072 (Cross compiling rustc_llvm on Darwin requires zlib.)
- rust-lang#87385 (Make `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` warn by default)
- rust-lang#87547 (Add missing examples for NonNull)
- rust-lang#87557 (Fix issue with autofix for ambiguous associated function from Rust 2021 prelude when struct is generic)
- rust-lang#87559 (Tweak borrowing suggestion in `for` loop)
- rust-lang#87596 (Add warning when whitespace is not skipped after an escaped newline)
- rust-lang#87606 (Add some TAIT-related regression tests)
- rust-lang#87609 (Add docs about performance and `Iterator::map` to `[T; N]::map`)
- rust-lang#87616 (Fix missing word in rustdoc book)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit aa9e6aa into rust-lang:masterJul 30, 2021
@rustbotrustbot added this to the 1.56.0 milestone Jul 30, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Aug 3, 2021
…whitespace, r=estebank"
This reverts commit aa9e6aa, reversing
changes made to 5e2655d.
@jesyspa
jesyspa deleted the issue-87318-hidden-whitespace branch August 20, 2021 09:39
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@jesyspa@rust-highfive@rust-log-analyzer@estebank@bors@rustbot