Skip to content

Commit c8673ad

Browse files
Disallow whitespace escapes in the closing line
Co-authored-by: Jacob Lifshay <[email protected]>
1 parent b4dcfd0 commit c8673ad

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

text/3830-dedented-string-literals.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -806,9 +806,14 @@ Note: **Literal newlines** (*not* escaped newlines: `\n`) are represented with `
806806
- Only the amount equal to the closing indentation, or less, will be removed.
807807
- Never more than the line actually has.
808808

809-
### Treatment of literal escapes: `\t`, `\r` and `\n`
809+
### Treatment of literal whitespace escapes: `\t`, `\r` and `\n`
810810

811-
`\t` is allowed in the line which contains the closing quote. Writing it is equivalent to inserting a literal tab.
811+
#### On the line containing the closing quote
812+
813+
- Only whitespace is allowed before the closing quote.
814+
- Escapes are not permitted even if they are escapes for whitespace (e.g. a tab escape `\t`), because escapes are processed after dedenting, so they are not yet whitespace when the line with the closing quote is processed.
815+
816+
#### In the content of the string
812817

813818
The escaped characters `\t`, `\r` and `\n` are treated as regular characters for the purposes of dedentation.
814819

@@ -820,7 +825,7 @@ println!(
820825
\ta
821826
\tb
822827
\tc
823-
\t"
828+
" // the indent here is a tab
824829
);
825830
```
826831

@@ -832,7 +837,7 @@ Prints, with each indentation being **1 tab**:
832837
c
833838
```
834839

835-
The indentation is not removed, because common indentation in this example is 0.
840+
The indentation is not removed, because common indentation in this example is 0. (closing indentation is 1 tab).
836841

837842
Escaped characters at the beginning of the string are interpreted as any other character, and **not** whitespace.
838843

0 commit comments

Comments
 (0)