Skip to content

Commit 659f856

Browse files
committed
Move discussion of string continuations from tokens.md to literal-expr.md
1 parent 7e3c5c3 commit 659f856

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

src/expressions/literal-expr.md

+19
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,25 @@ For this purpose, the whitespace characters are `U+0009` (HT), `U+000A` (LF), `U
8787

8888
The escaped value is an empty sequence of characters.
8989

90+
> **Note**: The effect of this form of escape is that a string continuation skips following whitespace, including additional newlines.
91+
> Thus `a`, `b` and `c` are equal:
92+
> ```rust
93+
> let a = "foobar";
94+
> let b = "foo\
95+
> bar";
96+
> let c = "foo\
97+
>
98+
> bar";
99+
>
100+
> assert_eq!(a, b);
101+
> assert_eq!(b, c);
102+
> ```
103+
>
104+
> Skipping additional newlines (as in example c) is potentially confusing and unexpected.
105+
> This behavior may be adjusted in the future.
106+
> Until a decision is made, it is recommended to avoid relying on skipping multiple newlines with line continuations.
107+
> See [this issue](https://github.com/rust-lang/reference/pull/1042) for more information.
108+
90109
## Character literal expressions
91110
92111
A character literal expression consists of a single [CHAR_LITERAL] token.

src/tokens.md

+6-22
Original file line numberDiff line numberDiff line change
@@ -156,30 +156,13 @@ A _string literal_ is a sequence of any Unicode characters enclosed within two
156156
`U+0022` (double-quote) characters, with the exception of `U+0022` itself,
157157
which must be _escaped_ by a preceding `U+005C` character (`\`).
158158

159-
Line-breaks are allowed in string literals. A line-break is either a newline
160-
(`U+000A`) or a pair of carriage return and newline (`U+000D`, `U+000A`). Both
161-
byte sequences are normally translated to `U+000A`, but as a special exception,
162-
when an unescaped `U+005C` character (`\`) occurs immediately before a line
163-
break, then the line break character(s), and all immediately following
164-
` ` (`U+0020`), `\t` (`U+0009`), `\n` (`U+000A`) and `\r` (`U+0000D`) characters
165-
are ignored. Thus `a`, `b` and `c` are equal:
159+
Line-breaks are allowed in string literals.
160+
A line-break is either a newline (`U+000A`) or a pair of carriage return and newline (`U+000D`, `U+000A`).
161+
Both byte sequences are translated to `U+000A`.
166162

167-
```rust
168-
let a = "foobar";
169-
let b = "foo\
170-
bar";
171-
let c = "foo\
172-
173-
bar";
174-
175-
assert_eq!(a, b);
176-
assert_eq!(b, c);
177-
```
163+
When an unescaped `U+005C` character (`\`) occurs immediately before a line break, the line break does not appear in the string represented by the token.
164+
See [String continuation escapes] for details.
178165

179-
> Note: Rust skipping additional newlines (like in example `c`) is potentially confusing and
180-
> unexpected. This behavior may be adjusted in the future. Until a decision is made, it is
181-
> recommended to avoid relying on this, i.e. skipping multiple newlines with line continuations.
182-
> See [this issue](https://github.com/rust-lang/reference/pull/1042) for more information.
183166

184167
#### Character escapes
185168

@@ -808,6 +791,7 @@ Similarly the `r`, `b`, `br`, `c`, and `cr` prefixes used in raw string literals
808791
[raw pointers]: types/pointer.md#raw-pointers-const-and-mut
809792
[references]: types/pointer.md
810793
[sized]: trait-bounds.md#sized
794+
[String continuation escapes]: expressions/literal-expr.md#string-continuation-escapes
811795
[struct expressions]: expressions/struct-expr.md
812796
[trait bounds]: trait-bounds.md
813797
[tuple index]: expressions/tuple-expr.md#tuple-indexing-expressions

0 commit comments

Comments
 (0)