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

String literal expressions #1452

Merged
merged 4 commits into from
Jan 27, 2024

Conversation

mattheww
Copy link
Contributor

This fills in most of what is still missing for #939.

I haven't tried to cover C string literals at this stage, as they haven't quite settled down yet.

I haven't removed much of the text in tokens.md which is discussing what string literal tokens "represent" or "denote", although I think strictly speaking that applies to literal expressions rather than literal tokens.

I think the best course would be think about that after, or together with, making the Tokens chapter correct (which is #626).

src/expressions/literal-expr.md Outdated Show resolved Hide resolved
src/expressions/literal-expr.md Outdated Show resolved Hide resolved

> **Note**: This section is incomplete.
The expression's type is a shared reference (with `static` lifetime) to an array whose element type is [`u8`][numeric types].
That is, the type is `&'static [u8; N]`, where `N` is the number of characters in the represented string described below.
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps to avoid confusion here?

Suggested change
That is, the type is `&'static [u8; N]`, where `N` is the number of characters in the represented string described below.
That is, the type is `&'static [u8; N]`, where `N` is the number of bytes in the represented string described below.

Also, this may become a little more confusing after RFC 3349 is implemented/stabilized.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After RFC 3349 I think the byte and byte-string literals will need a different approach, with a separate version of the whole "Escapes" section. But that will be easier to describe when the new forms of escape are there.

Comment on lines +159 to +161
Line-breaks are allowed in string literals.
A line-break is either a newline (`U+000A`) or a pair of carriage return and newline (`U+000D`, `U+000A`).
Both byte sequences are translated to `U+000A`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is fine to keep. Just a note that my preference longer-term would be to have some global explanation of the CRLF→LF conversion in a single place so it doesn't need to be repeated in multiple places. For example, this is relevant for all string types (raw strings, byte strings, c-strings, etc.), but they don't currently mention this in the same way.

If there is a section somewhere in the lexing chapter that talks about this translation, I think these sentences could be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm thinking of looking at documenting CRLF conversion properly next (rather than trying to fight all of #626 in one go).

@ehuss
Copy link
Contributor

ehuss commented Jan 25, 2024

Thanks!

I think it would be fine to also include the c-string section if you want. I believe the discussion has settled on that.

@mattheww
Copy link
Contributor Author

I've force-pushed with your suggested changes.

I think I'd better look at C strings separately. I think I'm going to need some help with the "The expression's value is …" part.

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!

@ehuss ehuss added this pull request to the merge queue Jan 27, 2024
Merged via the queue into rust-lang:master with commit d4eac74 Jan 27, 2024
1 check passed
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jan 30, 2024
Update books

## rust-lang/edition-guide

1 commits in bbffb074e16bef89772818b400b6c76a65eac126..baafacc6d8701269dab1e1e333f3547fb54b5a59
2024-01-18 18:44:06 UTC to 2024-01-18 18:44:06 UTC

- Update c-string literal stabilization release number. (rust-lang/edition-guide#289)

## rust-embedded/book

1 commits in 3f9df2b9885c6741365da2e12ed6662cd0e827d6..2e95fc2fd31d669947e993aa07ef10dc9828bee7
2024-01-29 07:19:07 UTC to 2024-01-29 07:19:07 UTC

- Mention generics in "optimizing dependencies" (rust-embedded/book#366)

## rust-lang/reference

3 commits in 8c77e8be9da1a9c70545556218d563c8d061f1fd..a0b119535e7740f68494c4f0582f7ad008b00ccd
2024-01-27 19:22:06 UTC to 2024-01-27 16:43:49 UTC

- Update C-String literals to reject NUL (rust-lang/reference#1450)
- pure asm blocks must terminate (rust-lang/reference#1442)
- String literal expressions (rust-lang/reference#1452)

## rust-lang/rust-by-example

4 commits in ddf5cb0e6ee54ba2dd84c8ca3e1314120014e20d..179256a445d6144f5f371fdefb993f48f33978b0
2024-01-22 12:21:42 UTC to 2024-01-20 23:10:42 UTC

- Updated first sentence of "parsing a string" in string.md (rust-lang/rust-by-example#1805)
- Update the rustdoc example to match best practice (rust-lang/rust-by-example#1804)
- Add reference to crates.io error handling crates (rust-lang/rust-by-example#1803)
- fix(str.md): avoid misunderstanding that there were only two string types (rust-lang/rust-by-example#1802)

## rust-lang/rustc-dev-guide

15 commits in 4af29d1a7f64f88a36539662c6a84fe1fbe6cde1..ec287e332777627185be4798ad22599ffe7b84aa
2024-01-28 22:45:18 UTC to 2024-01-15 17:44:49 UTC

- Upgrade actions to use Node.js v20 (rust-lang/rustc-dev-guide#1863)
- Fix some links (rust-lang/rustc-dev-guide#1865)
- Add link in salsa (rust-lang/rustc-dev-guide#1866)
- Clarify what rt.rs is. (rust-lang/rustc-dev-guide#1876)
- update link to rustc dependencies (rust-lang/rustc-dev-guide#1869)
- Followup to rust-lang#1862 (rust-lang/rustc-dev-guide#1864)
- Clarify debugging graph dependency (rust-lang/rustc-dev-guide#1862)
- Get diagnostics directly in `rustc-driver-getting-diagnostics` example (rust-lang/rustc-dev-guide#1857)
- Update examples (rust-lang/rustc-dev-guide#1856)
- Add a perf. bot command and a link to its help page (rust-lang/rustc-dev-guide#1855)
- Add some explanations for frequently used rustbot commands (rust-lang/rustc-dev-guide#1849)
- update some of the diagnostic translations info (rust-lang/rustc-dev-guide#1711)
- Document unsafety checking (rust-lang/rustc-dev-guide#1847)
- Remove outdated references to `-Z dump-mir-spanview` (rust-lang/rustc-dev-guide#1853)
- update old bootstrap docs (rust-lang/rustc-dev-guide#1852)
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 30, 2024
Rollup merge of rust-lang#120467 - rustbot:docs-update, r=ehuss

Update books

## rust-lang/edition-guide

1 commits in bbffb074e16bef89772818b400b6c76a65eac126..baafacc6d8701269dab1e1e333f3547fb54b5a59
2024-01-18 18:44:06 UTC to 2024-01-18 18:44:06 UTC

- Update c-string literal stabilization release number. (rust-lang/edition-guide#289)

## rust-embedded/book

1 commits in 3f9df2b9885c6741365da2e12ed6662cd0e827d6..2e95fc2fd31d669947e993aa07ef10dc9828bee7
2024-01-29 07:19:07 UTC to 2024-01-29 07:19:07 UTC

- Mention generics in "optimizing dependencies" (rust-embedded/book#366)

## rust-lang/reference

3 commits in 8c77e8be9da1a9c70545556218d563c8d061f1fd..a0b119535e7740f68494c4f0582f7ad008b00ccd
2024-01-27 19:22:06 UTC to 2024-01-27 16:43:49 UTC

- Update C-String literals to reject NUL (rust-lang/reference#1450)
- pure asm blocks must terminate (rust-lang/reference#1442)
- String literal expressions (rust-lang/reference#1452)

## rust-lang/rust-by-example

4 commits in ddf5cb0e6ee54ba2dd84c8ca3e1314120014e20d..179256a445d6144f5f371fdefb993f48f33978b0
2024-01-22 12:21:42 UTC to 2024-01-20 23:10:42 UTC

- Updated first sentence of "parsing a string" in string.md (rust-lang/rust-by-example#1805)
- Update the rustdoc example to match best practice (rust-lang/rust-by-example#1804)
- Add reference to crates.io error handling crates (rust-lang/rust-by-example#1803)
- fix(str.md): avoid misunderstanding that there were only two string types (rust-lang/rust-by-example#1802)

## rust-lang/rustc-dev-guide

15 commits in 4af29d1a7f64f88a36539662c6a84fe1fbe6cde1..ec287e332777627185be4798ad22599ffe7b84aa
2024-01-28 22:45:18 UTC to 2024-01-15 17:44:49 UTC

- Upgrade actions to use Node.js v20 (rust-lang/rustc-dev-guide#1863)
- Fix some links (rust-lang/rustc-dev-guide#1865)
- Add link in salsa (rust-lang/rustc-dev-guide#1866)
- Clarify what rt.rs is. (rust-lang/rustc-dev-guide#1876)
- update link to rustc dependencies (rust-lang/rustc-dev-guide#1869)
- Followup to rust-lang#1862 (rust-lang/rustc-dev-guide#1864)
- Clarify debugging graph dependency (rust-lang/rustc-dev-guide#1862)
- Get diagnostics directly in `rustc-driver-getting-diagnostics` example (rust-lang/rustc-dev-guide#1857)
- Update examples (rust-lang/rustc-dev-guide#1856)
- Add a perf. bot command and a link to its help page (rust-lang/rustc-dev-guide#1855)
- Add some explanations for frequently used rustbot commands (rust-lang/rustc-dev-guide#1849)
- update some of the diagnostic translations info (rust-lang/rustc-dev-guide#1711)
- Document unsafety checking (rust-lang/rustc-dev-guide#1847)
- Remove outdated references to `-Z dump-mir-spanview` (rust-lang/rustc-dev-guide#1853)
- update old bootstrap docs (rust-lang/rustc-dev-guide#1852)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants