Skip to content

Commit

Permalink
Clarify "string continue" for (byte) string literals
Browse files Browse the repository at this point in the history
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
  • Loading branch information
LukasKalbertodt committed Jun 4, 2021
1 parent 8f598e2 commit 739e784
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,21 @@ which must be _escaped_ by a preceding `U+005C` character (`\`).
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 normally translated to `U+000A`, but as a special exception,
when an unescaped `U+005C` character (`\`) occurs immediately before the
line-break, then the `U+005C` character, the line-break, and all whitespace at the
beginning of the next line are ignored. Thus `a` and `b` are equal:
when an unescaped `U+005C` character (`\`) occurs immediately before a `\n`
(`U+000A`), then the `U+005C` character, and all immediately following
` ` (`U+0020`), `\t` (`U+0009`), `\n` (`U+000A`) and `\r` (`U+0000D`) characters
are ignored. Thus `a`, `b` and `c` are equal:

```rust
let a = "foobar";
let b = "foo\
bar";
let c = "foo\
assert_eq!(a,b);
bar";

assert_eq!(a, b);
assert_eq!(b, c);
```

#### Character escapes
Expand Down

0 comments on commit 739e784

Please sign in to comment.