Skip to content

Commit ce6baa7

Browse files
committed
Clarify how Rust treats backslashes at end of line in string literals
Rust differs in that behavior from C: In C, the newline escapes are resolved before anything else, and in Rust this depends on whether the backslash is escaped itself. A difference can be observed in the following two programs: ```c #include <stdio.h> int main() { printf("\\ n\n"); return 0; } ``` ```rust fn main() { println!("\\ n"); } ``` The first program prints two newlines, the second one prints a backslash, a newline, the latin character n and a final newline.
1 parent 5253294 commit ce6baa7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/doc/reference.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,10 @@ A _string literal_ is a sequence of any Unicode characters enclosed within two
208208
which must be _escaped_ by a preceding `U+005C` character (`\`).
209209

210210
Line-break characters are allowed in string literals. Normally they represent
211-
themselves (i.e. no translation), but as a special exception, when a `U+005C`
212-
character (`\`) occurs immediately before the newline, the `U+005C` character,
213-
the newline, and all whitespace at the beginning of the next line are ignored.
214-
Thus `a` and `b` are equal:
211+
themselves (i.e. no translation), but as a special exception, when an unescaped
212+
`U+005C` character (`\`) occurs immediately before the newline (`U+000A`), the
213+
`U+005C` character, the newline, and all whitespace at the beginning of the
214+
next line are ignored. Thus `a` and `b` are equal:
215215

216216
```rust
217217
let a = "foobar";

0 commit comments

Comments
 (0)