Skip to content

Commit b405024

Browse files
committed
Make use of raw strings in core::fmt::builders
There are quite a few uses of escaped quotes. Turn these into raw strings within documentation and tests to make things easier to read.
1 parent d1d9893 commit b405024

File tree

2 files changed

+49
-49
lines changed

2 files changed

+49
-49
lines changed

Diff for: core/src/fmt/builders.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl fmt::Write for PadAdapter<'_, '_> {
7878
///
7979
/// assert_eq!(
8080
/// format!("{:?}", Foo { bar: 10, baz: "Hello World".to_string() }),
81-
/// "Foo { bar: 10, baz: \"Hello World\" }",
81+
/// r#"Foo { bar: 10, baz: "Hello World" }"#,
8282
/// );
8383
/// ```
8484
#[must_use = "must eventually call `finish()` on Debug builders"]
@@ -125,7 +125,7 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
125125
///
126126
/// assert_eq!(
127127
/// format!("{:?}", Bar { bar: 10, another: "Hello World".to_string() }),
128-
/// "Bar { bar: 10, another: \"Hello World\", nonexistent_field: 1 }",
128+
/// r#"Bar { bar: 10, another: "Hello World", nonexistent_field: 1 }"#,
129129
/// );
130130
/// ```
131131
#[stable(feature = "debug_builders", since = "1.2.0")]
@@ -237,7 +237,7 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
237237
///
238238
/// assert_eq!(
239239
/// format!("{:?}", Bar { bar: 10, baz: "Hello World".to_string() }),
240-
/// "Bar { bar: 10, baz: \"Hello World\" }",
240+
/// r#"Bar { bar: 10, baz: "Hello World" }"#,
241241
/// );
242242
/// ```
243243
#[stable(feature = "debug_builders", since = "1.2.0")]
@@ -280,7 +280,7 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
280280
///
281281
/// assert_eq!(
282282
/// format!("{:?}", Foo(10, "Hello World".to_string())),
283-
/// "Foo(10, \"Hello World\")",
283+
/// r#"Foo(10, "Hello World")"#,
284284
/// );
285285
/// ```
286286
#[must_use = "must eventually call `finish()` on Debug builders"]
@@ -322,7 +322,7 @@ impl<'a, 'b: 'a> DebugTuple<'a, 'b> {
322322
///
323323
/// assert_eq!(
324324
/// format!("{:?}", Foo(10, "Hello World".to_string())),
325-
/// "Foo(10, \"Hello World\")",
325+
/// r#"Foo(10, "Hello World")"#,
326326
/// );
327327
/// ```
328328
#[stable(feature = "debug_builders", since = "1.2.0")]
@@ -381,7 +381,7 @@ impl<'a, 'b: 'a> DebugTuple<'a, 'b> {
381381
///
382382
/// assert_eq!(
383383
/// format!("{:?}", Foo(10, "Hello World".to_string())),
384-
/// "Foo(10, \"Hello World\")",
384+
/// r#"Foo(10, "Hello World")"#,
385385
/// );
386386
/// ```
387387
#[stable(feature = "debug_builders", since = "1.2.0")]
@@ -747,7 +747,7 @@ impl<'a, 'b: 'a> DebugList<'a, 'b> {
747747
///
748748
/// assert_eq!(
749749
/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),
750-
/// "{\"A\": 10, \"B\": 11}",
750+
/// r#"{"A": 10, "B": 11}"#,
751751
/// );
752752
/// ```
753753
#[must_use = "must eventually call `finish()` on Debug builders"]
@@ -787,7 +787,7 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
787787
///
788788
/// assert_eq!(
789789
/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),
790-
/// "{\"whole\": [(\"A\", 10), (\"B\", 11)]}",
790+
/// r#"{"whole": [("A", 10), ("B", 11)]}"#,
791791
/// );
792792
/// ```
793793
#[stable(feature = "debug_builders", since = "1.2.0")]
@@ -823,7 +823,7 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
823823
///
824824
/// assert_eq!(
825825
/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),
826-
/// "{\"whole\": [(\"A\", 10), (\"B\", 11)]}",
826+
/// r#"{"whole": [("A", 10), ("B", 11)]}"#,
827827
/// );
828828
/// ```
829829
#[stable(feature = "debug_map_key_value", since = "1.42.0")]
@@ -899,7 +899,7 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
899899
///
900900
/// assert_eq!(
901901
/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),
902-
/// "{\"whole\": [(\"A\", 10), (\"B\", 11)]}",
902+
/// r#"{"whole": [("A", 10), ("B", 11)]}"#,
903903
/// );
904904
/// ```
905905
#[stable(feature = "debug_map_key_value", since = "1.42.0")]
@@ -957,7 +957,7 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
957957
///
958958
/// assert_eq!(
959959
/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),
960-
/// "{\"A\": 10, \"B\": 11}",
960+
/// r#"{"A": 10, "B": 11}"#,
961961
/// );
962962
/// ```
963963
#[stable(feature = "debug_builders", since = "1.2.0")]
@@ -997,7 +997,7 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
997997
///
998998
/// assert_eq!(
999999
/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),
1000-
/// "{\"A\": 10, \"B\": 11}",
1000+
/// r#"{"A": 10, "B": 11}"#,
10011001
/// );
10021002
/// ```
10031003
#[stable(feature = "debug_builders", since = "1.2.0")]

Diff for: core/tests/fmt/builders.rs

+37-37
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,23 @@ mod debug_struct {
7979
}
8080

8181
assert_eq!(
82-
"Bar { foo: Foo { bar: true, baz: 10/20 }, hello: \"world\" }",
82+
r#"Bar { foo: Foo { bar: true, baz: 10/20 }, hello: "world" }"#,
8383
format!("{Bar:?}")
8484
);
8585
assert_eq!(
86-
"Bar {
86+
r#"Bar {
8787
foo: Foo {
8888
bar: true,
8989
baz: 10/20,
9090
},
91-
hello: \"world\",
92-
}",
91+
hello: "world",
92+
}"#,
9393
format!("{Bar:#?}")
9494
);
9595
}
9696

9797
#[test]
98-
fn test_only_non_exhaustive() {
98+
fn test_empty_non_exhaustive() {
9999
struct Foo;
100100

101101
impl fmt::Debug for Foo {
@@ -157,19 +157,19 @@ mod debug_struct {
157157
}
158158

159159
assert_eq!(
160-
"Bar { foo: Foo { bar: true, baz: 10/20, .. }, hello: \"world\", .. }",
160+
r#"Bar { foo: Foo { bar: true, baz: 10/20, .. }, hello: "world", .. }"#,
161161
format!("{Bar:?}")
162162
);
163163
assert_eq!(
164-
"Bar {
164+
r#"Bar {
165165
foo: Foo {
166166
bar: true,
167167
baz: 10/20,
168168
..
169169
},
170-
hello: \"world\",
170+
hello: "world",
171171
..
172-
}",
172+
}"#,
173173
format!("{Bar:#?}")
174174
);
175175
}
@@ -249,15 +249,15 @@ mod debug_tuple {
249249
}
250250
}
251251

252-
assert_eq!("Bar(Foo(true, 10/20), \"world\")", format!("{Bar:?}"));
252+
assert_eq!(r#"Bar(Foo(true, 10/20), "world")"#, format!("{Bar:?}"));
253253
assert_eq!(
254-
"Bar(
254+
r#"Bar(
255255
Foo(
256256
true,
257257
10/20,
258258
),
259-
\"world\",
260-
)",
259+
"world",
260+
)"#,
261261
format!("{Bar:#?}")
262262
);
263263
}
@@ -301,11 +301,11 @@ mod debug_map {
301301
assert_eq!(format!("{Entry:?}"), format!("{KeyValue:?}"));
302302
assert_eq!(format!("{Entry:#?}"), format!("{KeyValue:#?}"));
303303

304-
assert_eq!("{\"bar\": true}", format!("{Entry:?}"));
304+
assert_eq!(r#"{"bar": true}"#, format!("{Entry:?}"));
305305
assert_eq!(
306-
"{
307-
\"bar\": true,
308-
}",
306+
r#"{
307+
"bar": true,
308+
}"#,
309309
format!("{Entry:#?}")
310310
);
311311
}
@@ -339,12 +339,12 @@ mod debug_map {
339339
assert_eq!(format!("{Entry:?}"), format!("{KeyValue:?}"));
340340
assert_eq!(format!("{Entry:#?}"), format!("{KeyValue:#?}"));
341341

342-
assert_eq!("{\"bar\": true, 10: 10/20}", format!("{Entry:?}"));
342+
assert_eq!(r#"{"bar": true, 10: 10/20}"#, format!("{Entry:?}"));
343343
assert_eq!(
344-
"{
345-
\"bar\": true,
344+
r#"{
345+
"bar": true,
346346
10: 10/20,
347-
}",
347+
}"#,
348348
format!("{Entry:#?}")
349349
);
350350
}
@@ -371,21 +371,21 @@ mod debug_map {
371371
}
372372

373373
assert_eq!(
374-
"{\"foo\": {\"bar\": true, 10: 10/20}, \
375-
{\"bar\": true, 10: 10/20}: \"world\"}",
374+
r#"{"foo": {"bar": true, 10: 10/20}, \
375+
{"bar": true, 10: 10/20}: "world"}"#,
376376
format!("{Bar:?}")
377377
);
378378
assert_eq!(
379-
"{
380-
\"foo\": {
381-
\"bar\": true,
379+
r#"{
380+
"foo": {
381+
"bar": true,
382382
10: 10/20,
383383
},
384384
{
385-
\"bar\": true,
385+
"bar": true,
386386
10: 10/20,
387-
}: \"world\",
388-
}",
387+
}: "world",
388+
}"#,
389389
format!("{Bar:#?}")
390390
);
391391
}
@@ -547,15 +547,15 @@ mod debug_set {
547547
}
548548
}
549549

550-
assert_eq!("{{true, 10/20}, \"world\"}", format!("{Bar:?}"));
550+
assert_eq!(r#"{{true, 10/20}, "world"}"#, format!("{Bar:?}"));
551551
assert_eq!(
552-
"{
552+
r#"{
553553
{
554554
true,
555555
10/20,
556556
},
557-
\"world\",
558-
}",
557+
"world",
558+
}"#,
559559
format!("{Bar:#?}")
560560
);
561561
}
@@ -635,15 +635,15 @@ mod debug_list {
635635
}
636636
}
637637

638-
assert_eq!("[[true, 10/20], \"world\"]", format!("{Bar:?}"));
638+
assert_eq!(r#"[[true, 10/20], "world"]"#, format!("{Bar:?}"));
639639
assert_eq!(
640-
"[
640+
r#"[
641641
[
642642
true,
643643
10/20,
644644
],
645-
\"world\",
646-
]",
645+
"world",
646+
]"#,
647647
format!("{Bar:#?}")
648648
);
649649
}

0 commit comments

Comments
 (0)