Skip to content

Commit 58e0f34

Browse files
authored
Merge pull request rust-lang#1042 from LukasKalbertodt/patch-1
Clarify "string continue" for (byte) string literals
2 parents e558ec9 + efc277f commit 58e0f34

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Diff for: src/tokens.md

+14-4
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,28 @@ which must be _escaped_ by a preceding `U+005C` character (`\`).
148148
Line-breaks are allowed in string literals. A line-break is either a newline
149149
(`U+000A`) or a pair of carriage return and newline (`U+000D`, `U+000A`). Both
150150
byte sequences are normally translated to `U+000A`, but as a special exception,
151-
when an unescaped `U+005C` character (`\`) occurs immediately before the
152-
line-break, then the `U+005C` character, the line-break, and all whitespace at the
153-
beginning of the next line are ignored. Thus `a` and `b` are equal:
151+
when an unescaped `U+005C` character (`\`) occurs immediately before a line
152+
break, then the line break character(s), and all immediately following
153+
` ` (`U+0020`), `\t` (`U+0009`), `\n` (`U+000A`) and `\r` (`U+0000D`) characters
154+
are ignored. Thus `a`, `b` and `c` are equal:
154155

155156
```rust
156157
let a = "foobar";
157158
let b = "foo\
158159
bar";
160+
let c = "foo\
159161
160-
assert_eq!(a,b);
162+
bar";
163+
164+
assert_eq!(a, b);
165+
assert_eq!(b, c);
161166
```
162167

168+
> Note: Rust skipping additional newlines (like in example `c`) is potentially confusing and
169+
> unexpected. This behavior may be adjusted in the future. Until a decision is made, it is
170+
> recommended to avoid relying on this, i.e. skipping multiple newlines with line continuations.
171+
> See [this issue](https://github.com/rust-lang/reference/pull/1042) for more information.
172+
163173
#### Character escapes
164174

165175
Some additional _escapes_ are available in either character or non-raw string

0 commit comments

Comments
 (0)