Commit f4e3da2
committed
Fix and clarify CR LF normalization and CR in string literals
This was slightly incorrect before. Relevant commits changing this:
- fa56fdb
- 27e1ec9
The normalization is not applied repeatedly, so CR LF pairs can still
exist. Further, given that the normalization happens before lexing,
the part "other than as part of such a string continuation escape" is
not useful. Either it was CR LF in the raw input, but has already been
transformed already (so the lexical grammar does not see CR). Or there
is a surviving CR LF pair after the normalization, which is disallowed
tho.
Here are two test programs showing this behavior:
printf 'fn main() { "a\r\r\n\nb"; }' > code.rs | rustc -
Results in:
error: bare CR not allowed in string, use `\r` instead
--> <anon>:1:15
|
1 | fn main() { "a␍
| ^
|
help: escape the character
|
1 | fn main() { "a\r
| ++
And
printf 'fn main() { "a\\\r\r\n\nb"; }' > code.rs | rustc -
Results in
error: unknown character escape: `\r`
--> <anon>:1:16
|
1 | fn main() { "a\␍
| ^ unknown character escape
|
= help: this is an isolated carriage return; consider checking your editor and version control settings1 parent e0625a7 commit f4e3da2
2 files changed
+4
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
64 | | - | |
65 | 63 | | |
66 | 64 | | |
67 | 65 | | |
| |||
198 | 196 | | |
199 | 197 | | |
200 | 198 | | |
| 199 | + | |
201 | 200 | | |
202 | 201 | | |
203 | | - | |
204 | 202 | | |
205 | 203 | | |
206 | 204 | | |
| |||
323 | 321 | | |
324 | 322 | | |
325 | 323 | | |
| 324 | + | |
326 | 325 | | |
327 | 326 | | |
328 | | - | |
329 | 327 | | |
330 | 328 | | |
331 | 329 | | |
| |||
429 | 427 | | |
430 | 428 | | |
431 | 429 | | |
| 430 | + | |
432 | 431 | | |
433 | 432 | | |
434 | | - | |
435 | 433 | | |
436 | 434 | | |
437 | 435 | | |
| |||
0 commit comments