Skip to content
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

Clarify "string continue" for (byte) string literals #1042

Merged
merged 2 commits into from
Jun 13, 2022

Conversation

LukasKalbertodt
Copy link
Member

The previous version just said "whitespace at the beginning of the next
line is ignored", but that is not quite correct. Currently, exactly four
characters are ignored in that position. This is different from the
definition of char::is_whitespace and char::is_ascii_whitespace.

Additionally "at the beginning of the next line" is confusing as
additional \n are also ignored.

See the lexer implementation:

https://github.com/rust-lang/rust/blob/595088d602049d821bf9a217f2d79aea40715208/compiler/rustc_lexer/src/unescape.rs#L281-L287

https://github.com/rust-lang/rust/blob/595088d602049d821bf9a217f2d79aea40715208/compiler/rustc_lexer/src/unescape.rs#L300-L307

Copy link
Contributor

@ehuss ehuss left a 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! This behavior is a little surprising to me, since that is not how it works in other languages (like Python). It looks like this has been in Rust ever since the beginning (rust-lang/rust@df9cf0b), and I'm guessing the initial docs (rust-lang/rust#22748) were just confused?

src/tokens.md Outdated Show resolved Hide resolved
The previous version just said "whitespace at the beginning of the next
line is ignored", but that is not quite correct. Currently, exactly four
characters are ignored in that position. This is different from the
definition of `char::is_whitespace` and `char::is_ascii_whitespace`.

Additionally "at the beginning of the next line" is confusing as
additional \n are also ignored.

https://github.com/rust-lang/rust/blob/595088d602049d821bf9a217f2d79aea40715208/compiler/rustc_lexer/src/unescape.rs#L281-L287

https://github.com/rust-lang/rust/blob/595088d602049d821bf9a217f2d79aea40715208/compiler/rustc_lexer/src/unescape.rs#L300-L307
@LukasKalbertodt
Copy link
Member Author

@ehuss It is a bit surprising to me too. Do you suspect that this might still change in the Rust compiler? Would you suggest not merging this PR until we are sure that this is the behavior we want in the compiler?

@ehuss
Copy link
Contributor

ehuss commented Jun 9, 2021

Hm, yea, I'm not sure. I asked on Zulip if anyone has any input.

Usually we lean towards documenting what rustc does, but in the cases of bugs or unintended behavior, it can be difficult to know how to proceed. I would suspect this should be merged as-is, since it has had this behavior for 10 years, and breaking language changes are difficult (and this probably isn't important enough to put any time and energy into).

We'll see if anyone chimes in on Zulip.

@ehuss ehuss added the T-lang Team: Lang label Jul 6, 2021
@joshtriplett
Copy link
Member

Skipping multiple newlines in a row seems like really surprising behavior in the Rust compiler. I don't know if we can fix that easily, but we could at least warn about it, and perhaps improve the behavior over an edition.

@joshtriplett
Copy link
Member

We discussed this in the @rust-lang/lang meeting today, and we'd prefer to actually have the Rust compiler warn if it encounters this case, to avoid confusion.

We will leave it up to the reference team how to flag such things; if you'd like to merge this as-is that's fine, or if you'd like to flag this somehow as "potentially surprising/undesirable behavior that the compiler may warn about" that'd be fine too. How, in general, would the reference team like to handle "this is the current behavior but it's weird and we might want to address that"?

Meanwhile, we'd love to see a warning added to the compiler. Once that warning exists, we could consider changing this in an edition, or potentially use a crater run (with the warning made into an error) to determine if this could change in all versions of Rust to minimize confusion.

@joshtriplett
Copy link
Member

See rust-lang/rust#87319, which requests a warning (and later error) for this.

Also see rust-lang/rust#87318, which flags a related issue @scottmcm noticed while we poked at this.

@LukasKalbertodt
Copy link
Member Author

What's the status here? Rust now warns about this confusing behavior and there are maybe (?) plans to change the behavior in an upcoming edition. Should this PR still be merged as it described the current behavior? Should I add a note about "this might change later because it's confusing"?

@ehuss
Copy link
Contributor

ehuss commented Jun 12, 2022

Sorry for the delay. Yea, can you add a small note? Maybe something like:

Note: For clarity, it is recommended to avoid using multiple line breaks with line continuations. rustc will produce a warning in that situation to point out the possible confusion.

Or feel free to rewrite that from scratch. I'm not sure how to say that succinctly and clearly.

@LukasKalbertodt
Copy link
Member Author

Pushed a commit with a note. I came up with some text on my own now, but if you think it has problems, I can easily just use your text as well.

Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@ehuss ehuss merged commit 58e0f34 into rust-lang:master Jun 13, 2022
@LukasKalbertodt LukasKalbertodt deleted the patch-1 branch June 13, 2022 18:40
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 23, 2022
Update books

## reference

6 commits in 683bfe5cd64d589c6a1645312ab5f93b6385ccbb..9fce337a55ee4a4629205f6094656195cecad231
2022-05-27 11:54:20 -0700 to 2022-06-22 13:59:28 -0700
- Remove outdated restriction on recursive types (rust-lang/reference#1231)
- Clarify "string continue" for (byte) string literals (rust-lang/reference#1042)
- Add a note to the turbofish section about impl Trait (rust-lang/reference#1212)
- modify confusing variance example (rust-lang/reference#1224)
- Add stable references of `macro_metavar_expr` (rust-lang/reference#1192)
- Document native library modifier `bundle` (rust-lang/reference#1210)

## book

33 commits in 396fdb69de7fb18f24b15c7ad13491b1c1fa7231..efbafdba3618487fbc9305318fcab9775132ac15
2022-06-08 10:02:35 -0400 to 2022-06-19 21:06:50 -0400
- Propagate tech review edits to appendices to src
- Tech review comments and further edits to the appendices
- Duplicate fragment "mutation and borrowing"
- Propagate ch20 tech review edits to src
- Edits in response to tech review of chapter 20
- Comments from tech review on chapter 20
- Propagate ch7 tech review edits to src
- Responding to tech review of ch7
- Tech review comments on ch7
- Propagate ch19 tech review edits to src
- Responses to tech review of ch19
- Tech review comments on ch 19
- Update ch03-01-variables-and-mutability.md
- Add more explanation to CONTRIBUTING about the nostarch directory
- Duplicate sentence
- Missing period
- Regenerate ch09-02 error messages
- Change some print formatting styles in ch18
- Propagate tech review ch18 edits to src
- Responses to tech review comments of chapter 18
- Chapter 18 from tech review
- Snapshot of introduction for nostarch
- Propagate edits of ch1 to src
- Edits to edits to chapter 1
- Edits from nostarch for chapter 1
- Update Visual Studio instructions for 2022
- bugfix/typo-ch10-01 Fix typo in chapter ch10-01
- Tweak rustfmt slightly for these listings
- Propagate edits to ch13 to src
- Responses to nostarch edits to ch13
- Edits to ch13 from nostarch
- Apply complex Clippy recommendation
- Apply Clippy recommendations: `cargo clippy --fix`

## rust-by-example

4 commits in dbb7e5e2345ee26199ffba218156b6009016a20c..1095df2a5850f2d345fad43a30633133365875ba
2022-06-02 16:30:51 -0300 to 2022-06-18 21:47:12 -0300
- Add example for `array.get()` (rust-lang/rust-by-example#1554)
- Example improvements (rust-lang/rust-by-example#1552)
- Fix for a set of typos (rust-lang/rust-by-example#1551)
- Make guard examples clearer around `_` (rust-lang/rust-by-example#1550)

## rustc-dev-guide

11 commits in 6e4d6435db89bcc027b1bba9742e4f59666f5412..048d925f0a955aac601c4160c0e7f05771bcf63b
2022-06-08 08:06:32 +0900 to 2022-06-21 22:25:34 +0900
- not obvious what Ex is, so rather get rid (rust-lang/rustc-dev-guide#1372)
- small improves (rust-lang/rustc-dev-guide#1371)
- make clear that other versions can work (rust-lang/rustc-dev-guide#1373)
- Fix small `src/diagnostics.md` typo (rust-lang/rustc-dev-guide#1370)
- Add an "is" and rearange "We next" to "Next, we" (rust-lang/rustc-dev-guide#1369)
- diagnostics: add translation documentation
- diagnostics: line wrapping/heading changes
- later -> latter
- Remove mention of -Zborrowck=mir with Polonius. (rust-lang/rustc-dev-guide#1367)
- Remove nll compare mode. (rust-lang/rustc-dev-guide#1366)
- add section on user types (rust-lang/rustc-dev-guide#1359)

## embedded-book

1 commits in cbb494f96da3268c2925bdadc65ca83d42f2d4ef..e17dcef5e96346ee3d7fa56820ddc7e5c39636bc
2022-05-26 06:58:43 +0000 to 2022-06-19 10:28:00 +0000
- Fix a typo  (rust-embedded/book#319)
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Jun 23, 2022
Update books

## reference

6 commits in 683bfe5cd64d589c6a1645312ab5f93b6385ccbb..9fce337a55ee4a4629205f6094656195cecad231
2022-05-27 11:54:20 -0700 to 2022-06-22 13:59:28 -0700
- Remove outdated restriction on recursive types (rust-lang/reference#1231)
- Clarify "string continue" for (byte) string literals (rust-lang/reference#1042)
- Add a note to the turbofish section about impl Trait (rust-lang/reference#1212)
- modify confusing variance example (rust-lang/reference#1224)
- Add stable references of `macro_metavar_expr` (rust-lang/reference#1192)
- Document native library modifier `bundle` (rust-lang/reference#1210)

## book

33 commits in 396fdb69de7fb18f24b15c7ad13491b1c1fa7231..efbafdba3618487fbc9305318fcab9775132ac15
2022-06-08 10:02:35 -0400 to 2022-06-19 21:06:50 -0400
- Propagate tech review edits to appendices to src
- Tech review comments and further edits to the appendices
- Duplicate fragment "mutation and borrowing"
- Propagate ch20 tech review edits to src
- Edits in response to tech review of chapter 20
- Comments from tech review on chapter 20
- Propagate ch7 tech review edits to src
- Responding to tech review of ch7
- Tech review comments on ch7
- Propagate ch19 tech review edits to src
- Responses to tech review of ch19
- Tech review comments on ch 19
- Update ch03-01-variables-and-mutability.md
- Add more explanation to CONTRIBUTING about the nostarch directory
- Duplicate sentence
- Missing period
- Regenerate ch09-02 error messages
- Change some print formatting styles in ch18
- Propagate tech review ch18 edits to src
- Responses to tech review comments of chapter 18
- Chapter 18 from tech review
- Snapshot of introduction for nostarch
- Propagate edits of ch1 to src
- Edits to edits to chapter 1
- Edits from nostarch for chapter 1
- Update Visual Studio instructions for 2022
- bugfix/typo-ch10-01 Fix typo in chapter ch10-01
- Tweak rustfmt slightly for these listings
- Propagate edits to ch13 to src
- Responses to nostarch edits to ch13
- Edits to ch13 from nostarch
- Apply complex Clippy recommendation
- Apply Clippy recommendations: `cargo clippy --fix`

## rust-by-example

4 commits in dbb7e5e2345ee26199ffba218156b6009016a20c..1095df2a5850f2d345fad43a30633133365875ba
2022-06-02 16:30:51 -0300 to 2022-06-18 21:47:12 -0300
- Add example for `array.get()` (rust-lang/rust-by-example#1554)
- Example improvements (rust-lang/rust-by-example#1552)
- Fix for a set of typos (rust-lang/rust-by-example#1551)
- Make guard examples clearer around `_` (rust-lang/rust-by-example#1550)

## rustc-dev-guide

11 commits in 6e4d6435db89bcc027b1bba9742e4f59666f5412..048d925f0a955aac601c4160c0e7f05771bcf63b
2022-06-08 08:06:32 +0900 to 2022-06-21 22:25:34 +0900
- not obvious what Ex is, so rather get rid (rust-lang/rustc-dev-guide#1372)
- small improves (rust-lang/rustc-dev-guide#1371)
- make clear that other versions can work (rust-lang/rustc-dev-guide#1373)
- Fix small `src/diagnostics.md` typo (rust-lang/rustc-dev-guide#1370)
- Add an "is" and rearange "We next" to "Next, we" (rust-lang/rustc-dev-guide#1369)
- diagnostics: add translation documentation
- diagnostics: line wrapping/heading changes
- later -> latter
- Remove mention of -Zborrowck=mir with Polonius. (rust-lang/rustc-dev-guide#1367)
- Remove nll compare mode. (rust-lang/rustc-dev-guide#1366)
- add section on user types (rust-lang/rustc-dev-guide#1359)

## embedded-book

1 commits in cbb494f96da3268c2925bdadc65ca83d42f2d4ef..e17dcef5e96346ee3d7fa56820ddc7e5c39636bc
2022-05-26 06:58:43 +0000 to 2022-06-19 10:28:00 +0000
- Fix a typo  (rust-embedded/book#319)
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Jun 23, 2022
Update books

## reference

6 commits in 683bfe5cd64d589c6a1645312ab5f93b6385ccbb..9fce337a55ee4a4629205f6094656195cecad231
2022-05-27 11:54:20 -0700 to 2022-06-22 13:59:28 -0700
- Remove outdated restriction on recursive types (rust-lang/reference#1231)
- Clarify "string continue" for (byte) string literals (rust-lang/reference#1042)
- Add a note to the turbofish section about impl Trait (rust-lang/reference#1212)
- modify confusing variance example (rust-lang/reference#1224)
- Add stable references of `macro_metavar_expr` (rust-lang/reference#1192)
- Document native library modifier `bundle` (rust-lang/reference#1210)

## book

33 commits in 396fdb69de7fb18f24b15c7ad13491b1c1fa7231..efbafdba3618487fbc9305318fcab9775132ac15
2022-06-08 10:02:35 -0400 to 2022-06-19 21:06:50 -0400
- Propagate tech review edits to appendices to src
- Tech review comments and further edits to the appendices
- Duplicate fragment "mutation and borrowing"
- Propagate ch20 tech review edits to src
- Edits in response to tech review of chapter 20
- Comments from tech review on chapter 20
- Propagate ch7 tech review edits to src
- Responding to tech review of ch7
- Tech review comments on ch7
- Propagate ch19 tech review edits to src
- Responses to tech review of ch19
- Tech review comments on ch 19
- Update ch03-01-variables-and-mutability.md
- Add more explanation to CONTRIBUTING about the nostarch directory
- Duplicate sentence
- Missing period
- Regenerate ch09-02 error messages
- Change some print formatting styles in ch18
- Propagate tech review ch18 edits to src
- Responses to tech review comments of chapter 18
- Chapter 18 from tech review
- Snapshot of introduction for nostarch
- Propagate edits of ch1 to src
- Edits to edits to chapter 1
- Edits from nostarch for chapter 1
- Update Visual Studio instructions for 2022
- bugfix/typo-ch10-01 Fix typo in chapter ch10-01
- Tweak rustfmt slightly for these listings
- Propagate edits to ch13 to src
- Responses to nostarch edits to ch13
- Edits to ch13 from nostarch
- Apply complex Clippy recommendation
- Apply Clippy recommendations: `cargo clippy --fix`

## rust-by-example

4 commits in dbb7e5e2345ee26199ffba218156b6009016a20c..1095df2a5850f2d345fad43a30633133365875ba
2022-06-02 16:30:51 -0300 to 2022-06-18 21:47:12 -0300
- Add example for `array.get()` (rust-lang/rust-by-example#1554)
- Example improvements (rust-lang/rust-by-example#1552)
- Fix for a set of typos (rust-lang/rust-by-example#1551)
- Make guard examples clearer around `_` (rust-lang/rust-by-example#1550)

## rustc-dev-guide

11 commits in 6e4d6435db89bcc027b1bba9742e4f59666f5412..048d925f0a955aac601c4160c0e7f05771bcf63b
2022-06-08 08:06:32 +0900 to 2022-06-21 22:25:34 +0900
- not obvious what Ex is, so rather get rid (rust-lang/rustc-dev-guide#1372)
- small improves (rust-lang/rustc-dev-guide#1371)
- make clear that other versions can work (rust-lang/rustc-dev-guide#1373)
- Fix small `src/diagnostics.md` typo (rust-lang/rustc-dev-guide#1370)
- Add an "is" and rearange "We next" to "Next, we" (rust-lang/rustc-dev-guide#1369)
- diagnostics: add translation documentation
- diagnostics: line wrapping/heading changes
- later -> latter
- Remove mention of -Zborrowck=mir with Polonius. (rust-lang/rustc-dev-guide#1367)
- Remove nll compare mode. (rust-lang/rustc-dev-guide#1366)
- add section on user types (rust-lang/rustc-dev-guide#1359)

## embedded-book

1 commits in cbb494f96da3268c2925bdadc65ca83d42f2d4ef..e17dcef5e96346ee3d7fa56820ddc7e5c39636bc
2022-05-26 06:58:43 +0000 to 2022-06-19 10:28:00 +0000
- Fix a typo  (rust-embedded/book#319)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Team: Lang
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants