Skip to content

Commit 4a3c011

Browse files
committed
document behavior of \r\n in string literals
1 parent 1944efe commit 4a3c011

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/tokens.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ A suffix is a non-raw identifier immediately (without whitespace)
9292
following the primary part of a literal.
9393

9494
Any kind of literal (string, integer, etc) with any suffix is valid as a token,
95-
and can be passed to a macro without producing an error.
95+
and can be passed to a macro without producing an error.
9696
The macro itself will decide how to interpret such a token and whether to produce an error or not.
9797

9898
```rust
@@ -101,7 +101,7 @@ macro_rules! blackhole { ($tt:tt) => () }
101101
blackhole!("string"suffix); // OK
102102
```
103103

104-
However, suffixes on literal tokens parsed as Rust code are restricted.
104+
However, suffixes on literal tokens parsed as Rust code are restricted.
105105
Any suffixes are rejected on non-numeric literal tokens,
106106
and numeric literal tokens are accepted only with suffixes from the list below.
107107

@@ -150,11 +150,12 @@ A _string literal_ is a sequence of any Unicode characters enclosed within two
150150
`U+0022` (double-quote) characters, with the exception of `U+0022` itself,
151151
which must be _escaped_ by a preceding `U+005C` character (`\`).
152152

153-
Line-break characters are allowed in string literals. Normally they represent
154-
themselves (i.e. no translation), but as a special exception, when an unescaped
155-
`U+005C` character (`\`) occurs immediately before the newline (`U+000A`), the
156-
`U+005C` character, the newline, and all whitespace at the beginning of the
157-
next line are ignored. Thus `a` and `b` are equal:
153+
Line-breaks are allowed in string literals. A line-break is either a newline
154+
(`U+000A`) or a pair of carriage return and newline (`U+000D`, `U+000A`). Both
155+
byte sequences are normally translated to `U+000A`, but as a special exception,
156+
when an unescaped `U+005C` character (`\`) occurs immediately before the
157+
line-break, the `U+005C` character, the line-break, and all whitespace at the
158+
beginning of the next line are ignored. Thus `a` and `b` are equal:
158159

159160
```rust
160161
let a = "foobar";

0 commit comments

Comments
 (0)