-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add warning when whitespace is not skipped after an escaped newline #87596
Conversation
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. |
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 |
This comment has been minimized.
This comment has been minimized.
Sorry, I missed the clippy code when testing locally. I'll update the PR and re-run the checks. |
53a297d
to
d7f524f
Compare
compiler/rustc_lexer/src/unescape.rs
Outdated
pub enum EscapeWarning { | ||
/// After a line ending with '\', the next line contains whitespace | ||
/// characters that are not skipped. | ||
UnskippedWhitespaceAfterEscapedNewline, | ||
} | ||
|
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.
In principle I'm ok with the approach of nested Result
s, 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.
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.
Makes sense, I've changed it to be a single type. Should I also change the name to EscapeDiagnostic, or is that too vague?
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.
I feel like EscapeError
is slightly misleading, but it'll make more sense than EscapeDiagnostic
.
fcd287c
to
bc8bbeb
Compare
This comment has been minimized.
This comment has been minimized.
bc8bbeb
to
5d59b44
Compare
@bors r+ |
📌 Commit 5d59b44 has been approved by |
…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.
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
Fixes issue #87318, also simplifies issue #87319.