Skip to content

Commit 013a68c

Browse files
committed
Align all opening quotes with closing quotes. Match rustfmt
This formats all of the examples to be how rustfmt formats strings today.
1 parent 8b9bcc3 commit 013a68c

File tree

1 file changed

+67
-40
lines changed

1 file changed

+67
-40
lines changed

text/3830-dedented-string-literals.md

Lines changed: 67 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ This allows us to have a more readable version of the above:
233233

234234
```rust
235235
fn main() {
236-
println!(d"
236+
println!(
237+
d"
237238
create table student(
238239
id int primary key,
239240
name text
@@ -258,15 +259,17 @@ Now, consider the example with multiple nested scopes again:
258259
```rs
259260
fn main() {
260261
{
261-
println!(d"
262+
println!(
263+
d"
262264
create table student(
263265
id int primary key,
264266
name text
265267
)
266268
"
267269
);
268270
}
269-
println!(d"
271+
println!(
272+
d"
270273
create table student(
271274
id int primary key,
272275
name text
@@ -275,7 +278,8 @@ fn main() {
275278
);
276279
{
277280
{
278-
println!(d"
281+
println!(
282+
d"
279283
create table student(
280284
id int primary key,
281285
name text
@@ -303,7 +307,8 @@ This allows all lines to have a common indentation.
303307

304308
```rust
305309
fn main() {
306-
println!(d"
310+
println!(
311+
d"
307312
create table student(
308313
id int primary key,
309314
name text
@@ -333,13 +338,14 @@ In order to strip the first level of indentation, the ending quote is aligned to
333338

334339
```rust
335340
fn main() {
336-
println!(d"
337-
create table student(
338-
id int primary key,
339-
name text
340-
)
341-
"
342-
^^^^ // common leading whitespace (will be removed)
341+
println!(
342+
d"
343+
create table student(
344+
id int primary key,
345+
name text
346+
)
347+
"
348+
^^^^^^^^ // common leading whitespace (will be removed)
343349
);
344350
}
345351
```
@@ -363,7 +369,8 @@ All indentation can be stripped by placing the closing double quote on the same
363369

364370
```rust
365371
fn main() {
366-
println!(d"
372+
println!(
373+
d"
367374
create table student(
368375
id int primary key,
369376
name text
@@ -403,7 +410,8 @@ create table student(
403410

404411
```rs
405412
fn main() {
406-
println!(d"
413+
println!(
414+
d"
407415
create table student(
408416
id int primary key,
409417
name text
@@ -419,7 +427,8 @@ fn main() {
419427

420428
```rs
421429
fn main() {
422-
println!(d"
430+
println!(
431+
d"
423432
create table student(
424433
id int primary key,
425434
name text
@@ -434,7 +443,8 @@ fn main() {
434443

435444
```rs
436445
fn main() {
437-
println!(d"
446+
println!(
447+
d"
438448
create table student(
439449
id int primary key,
440450
name text
@@ -470,7 +480,8 @@ The `format_args!` macro, and by extension all wrapper macros that pass argument
470480
fn main() {
471481
let table_name = "student";
472482

473-
println!(d"
483+
println!(
484+
d"
474485
create table {table_name}(
475486
id int primary key,
476487
name text
@@ -566,7 +577,8 @@ You can use them in formatting macros, such as `println!`, `write!`, `assert_eq!
566577
```rs
567578
let message = "Hello, world!";
568579

569-
let py = format!(dr#"
580+
let py = format!(
581+
dr#"
570582
def hello():
571583
print("{message}")
572584
@@ -589,7 +601,9 @@ let mut py = String::new();
589601

590602
// Note: Using `writeln!` because the final newline from dedented strings is removed. (more info later)
591603

592-
writeln!(py, d"
604+
writeln!(
605+
py,
606+
d"
593607
def hello():
594608
"
595609
//^^ removed
@@ -601,14 +615,18 @@ writeln!(py, d"
601615
// to insert the 2nd newline
602616

603617
// Remember, dedented string literals strip the last newline.
604-
writeln!(py, dr#"
618+
writeln!(
619+
py,
620+
dr#"
605621
print("{message}")
606622
607623
"#
608624
//^^ kept
609625
);
610626

611-
write!(py, d"
627+
write!(
628+
py,
629+
d"
612630
hello()
613631
"
614632
);
@@ -959,7 +977,8 @@ Consider the following which is invalid:
959977
```rs
960978
fn main() {
961979
// ERROR
962-
println!(d"create table student(
980+
println!(
981+
d"create table student(
963982
id int primary key,
964983
name text
965984
)
@@ -975,7 +994,8 @@ The following is also incorrect, as there is no newline before the line containi
975994

976995
```rs
977996
fn main() {
978-
println!(d"
997+
println!(
998+
d"
979999
create table student(
9801000
id int primary key,
9811001
name text
@@ -995,7 +1015,8 @@ string content is allowed:
9951015

9961016
```rs
9971017
fn main() {
998-
println!(d"
1018+
println!(
1019+
d"
9991020
create table student(
10001021
id int primary key,
10011022
name text
@@ -1009,7 +1030,8 @@ Reason: turning this into a syntax error is too strict, when it can be auto-fixe
10091030

10101031
```rs
10111032
fn main() {
1012-
println!(d"
1033+
println!(
1034+
d"
10131035
create table student(
10141036
id int primary key,
10151037
name text
@@ -1068,7 +1090,8 @@ Differences:
10681090
However, in this RFC the following:
10691091
10701092
```rs
1071-
print!(d"
1093+
print!(
1094+
d"
10721095
a
10731096
"
10741097
^^^^ // common leading whitespace (will be removed)
@@ -1082,7 +1105,8 @@ Differences:
10821105
In order to add a newline at the end, you have to add a newline in the source code:
10831106
10841107
```rs
1085-
print!(d"
1108+
print!(
1109+
d"
10861110
a
10871111

10881112
"
@@ -1287,7 +1311,8 @@ One of the major benefits of having dedented string literals is that you'll be a
12871311
let message = "Hello, world!";
12881312

12891313
// `{message}` is interpolated
1290-
let py = format!(dr#"
1314+
let py = format!(
1315+
dr#"
12911316
def hello():
12921317
print("{message}")
12931318
@@ -1512,11 +1537,11 @@ With [postfix macros](https://github.com/rust-lang/rfcs/pull/2442), the situatio
15121537
fn main() {
15131538
println!(
15141539
"
1515-
create table student(
1516-
id int primary key,
1517-
name text
1518-
)
1519-
".dedent!()
1540+
create table student(
1541+
id int primary key,
1542+
name text
1543+
)
1544+
".dedent!()
15201545
);
15211546
}
15221547
```
@@ -1605,13 +1630,15 @@ If indentation of the dedented string does not match the surrounding code:
16051630

16061631
```rust
16071632
fn main() {
1608-
println!(d"
1609-
create table student(
1610-
id int primary key,
1611-
name text
1612-
)
1613-
");
1614-
^^^^ // common leading whitespace (will be removed)
1633+
println!(
1634+
d"
1635+
create table student(
1636+
id int primary key,
1637+
name text
1638+
)
1639+
"
1640+
^^^^^^^^ // common leading whitespace (will be removed)
1641+
);
16151642
}
16161643
```
16171644

0 commit comments

Comments
 (0)