-
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
Warn about strings that skip multiple newlines with one backslash #87319
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
joshtriplett
added
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
labels
Jul 20, 2021
@rustbot claim |
Discussed in Zulip:
|
JohnTitor
added a commit
to JohnTitor/rust
that referenced
this issue
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.
JohnTitor
added a commit
to JohnTitor/rust
that referenced
this issue
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.
JohnTitor
added a commit
to JohnTitor/rust
that referenced
this issue
Aug 11, 2021
…es, r=estebank Warn when an escaped newline skips multiple lines Resolves rust-lang#87319
JohnTitor
added a commit
to JohnTitor/rust
that referenced
this issue
Aug 11, 2021
…es, r=estebank Warn when an escaped newline skips multiple lines Resolves rust-lang#87319
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
(This came up in today's @rust-lang/lang meeting.)
Given the following code:
Playground link
The compiler interprets both of the string literals as
"ab"
, omitting multiple newlines after the\
.This seems confusing, and different from the behavior of other languages. For instance, C and Python both produce parse errors for such string literals. Or, for a Python multi-line string literal, the backslash escapes the immediately following newline but not the subsequent newline.
Rust does allow unescaped newlines in string literals, which is useful. The ability to escape a newline can also be useful sometimes. But the combination of both escaped and unescaped newlines seems sufficiently confusing and surprising to merit a warning.
We'd ideally like to work towards this being an error. Depending on the presence of existing usage in the ecosystem, that might or might not require an edition.
The text was updated successfully, but these errors were encountered: