Auto merge of #129365 - matthiaskrgr:rollup-ebwx6ya, r=matthiaskrgr · patricklam/verify-rust-std@f671c11 (original) (raw)

`@@ -78,7 +78,7 @@ impl fmt::Write for PadAdapter<'_, '_> {

`

78

78

`///

`

79

79

`/// assert_eq!(

`

80

80

`/// format!("{:?}", Foo { bar: 10, baz: "Hello World".to_string() }),

`

81

``

`-

/// "Foo { bar: 10, baz: "Hello World" }",

`

``

81

`+

/// r#"Foo { bar: 10, baz: "Hello World" }"#,

`

82

82

`/// );

`

83

83

```` /// ```


`84`

`84`

`` #[must_use = "must eventually call `finish()` on Debug builders"]

``

`@@ -125,7 +125,7 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {

`

`125`

`125`

`///

`

`126`

`126`

`/// assert_eq!(

`

`127`

`127`

`/// 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 }"#,

`

`129`

`129`

`/// );

`

`130`

`130`

```` /// ```

131

131

`#[stable(feature = "debug_builders", since = "1.2.0")]

`

`@@ -237,7 +237,7 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {

`

237

237

`///

`

238

238

`/// assert_eq!(

`

239

239

`/// format!("{:?}", Bar { bar: 10, baz: "Hello World".to_string() }),

`

240

``

`-

/// "Bar { bar: 10, baz: "Hello World" }",

`

``

240

`+

/// r#"Bar { bar: 10, baz: "Hello World" }"#,

`

241

241

`/// );

`

242

242

```` /// ```


`243`

`243`

`#[stable(feature = "debug_builders", since = "1.2.0")]

`

`@@ -280,7 +280,7 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {

`

`280`

`280`

`///

`

`281`

`281`

`/// assert_eq!(

`

`282`

`282`

`/// format!("{:?}", Foo(10, "Hello World".to_string())),

`

`283`

``

`-

/// "Foo(10, \"Hello World\")",

`

``

`283`

`+

/// r#"Foo(10, "Hello World")"#,

`

`284`

`284`

`/// );

`

`285`

`285`

```` /// ```

286

286

`` #[must_use = "must eventually call finish() on Debug builders"]

``

`@@ -322,7 +322,7 @@ impl<'a, 'b: 'a> DebugTuple<'a, 'b> {

`

322

322

`///

`

323

323

`/// assert_eq!(

`

324

324

`/// format!("{:?}", Foo(10, "Hello World".to_string())),

`

325

``

`-

/// "Foo(10, "Hello World")",

`

``

325

`+

/// r#"Foo(10, "Hello World")"#,

`

326

326

`/// );

`

327

327

```` /// ```


`328`

`328`

`#[stable(feature = "debug_builders", since = "1.2.0")]

`

`@@ -360,6 +360,51 @@ impl<'a, 'b: 'a> DebugTuple<'a, 'b> {

`

`360`

`360`

`self

`

`361`

`361`

`}

`

`362`

`362`

``

``

`363`

`+

/// Marks the tuple struct as non-exhaustive, indicating to the reader that there are some

`

``

`364`

`+

/// other fields that are not shown in the debug representation.

`

``

`365`

`+

///

`

``

`366`

`+

/// # Examples

`

``

`367`

`+

///

`

``

`368`

```` +

/// ```

``

369

`+

/// #![feature(debug_more_non_exhaustive)]

`

``

370

`+

///

`

``

371

`+

/// use std::fmt;

`

``

372

`+

///

`

``

373

`+

/// struct Foo(i32, String);

`

``

374

`+

///

`

``

375

`+

/// impl fmt::Debug for Foo {

`

``

376

`+

/// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {

`

``

377

`+

/// fmt.debug_tuple("Foo")

`

``

378

`+

/// .field(&self.0)

`

``

379

`+

/// .finish_non_exhaustive() // Show that some other field(s) exist.

`

``

380

`+

/// }

`

``

381

`+

/// }

`

``

382

`+

///

`

``

383

`+

/// assert_eq!(

`

``

384

`+

/// format!("{:?}", Foo(10, "secret!".to_owned())),

`

``

385

`+

/// "Foo(10, ..)",

`

``

386

`+

/// );

`

``

387


/// ```

``

388

`+

#[unstable(feature = "debug_more_non_exhaustive", issue = "127942")]

`

``

389

`+

pub fn finish_non_exhaustive(&mut self) -> fmt::Result {

`

``

390

`+

self.result = self.result.and_then(|_| {

`

``

391

`+

if self.fields > 0 {

`

``

392

`+

if self.is_pretty() {

`

``

393

`+

let mut slot = None;

`

``

394

`+

let mut state = Default::default();

`

``

395

`+

let mut writer = PadAdapter::wrap(self.fmt, &mut slot, &mut state);

`

``

396

`+

writer.write_str("..\n")?;

`

``

397

`+

self.fmt.write_str(")")

`

``

398

`+

} else {

`

``

399

`+

self.fmt.write_str(", ..)")

`

``

400

`+

}

`

``

401

`+

} else {

`

``

402

`+

self.fmt.write_str("(..)")

`

``

403

`+

}

`

``

404

`+

});

`

``

405

`+

self.result

`

``

406

`+

}

`

``

407

+

363

408

`/// Finishes output and returns any error encountered.

`

364

409

`///

`

365

410

`/// # Examples

`

`@@ -381,7 +426,7 @@ impl<'a, 'b: 'a> DebugTuple<'a, 'b> {

`

381

426

`///

`

382

427

`/// assert_eq!(

`

383

428

`/// format!("{:?}", Foo(10, "Hello World".to_string())),

`

384

``

`-

/// "Foo(10, "Hello World")",

`

``

429

`+

/// r#"Foo(10, "Hello World")"#,

`

385

430

`/// );

`

386

431

```` /// ```


`387`

`432`

`#[stable(feature = "debug_builders", since = "1.2.0")]

`

`@@ -555,6 +600,56 @@ impl<'a, 'b: 'a> DebugSet<'a, 'b> {

`

`555`

`600`

`self

`

`556`

`601`

`}

`

`557`

`602`

``

``

`603`

`+

/// Marks the set as non-exhaustive, indicating to the reader that there are some other

`

``

`604`

`+

/// elements that are not shown in the debug representation.

`

``

`605`

`+

///

`

``

`606`

`+

/// # Examples

`

``

`607`

`+

///

`

``

`608`

```` +

/// ```

``

609

`+

/// #![feature(debug_more_non_exhaustive)]

`

``

610

`+

///

`

``

611

`+

/// use std::fmt;

`

``

612

`+

///

`

``

613

`+

/// struct Foo(Vec);

`

``

614

`+

///

`

``

615

`+

/// impl fmt::Debug for Foo {

`

``

616

`+

/// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {

`

``

617

`+

/// // Print at most two elements, abbreviate the rest

`

``

618

`+

/// let mut f = fmt.debug_set();

`

``

619

`+

/// let mut f = f.entries(self.0.iter().take(2));

`

``

620

`+

/// if self.0.len() > 2 {

`

``

621

`+

/// f.finish_non_exhaustive()

`

``

622

`+

/// } else {

`

``

623

`+

/// f.finish()

`

``

624

`+

/// }

`

``

625

`+

/// }

`

``

626

`+

/// }

`

``

627

`+

///

`

``

628

`+

/// assert_eq!(

`

``

629

`+

/// format!("{:?}", Foo(vec![1, 2, 3, 4])),

`

``

630

`+

/// "{1, 2, ..}",

`

``

631

`+

/// );

`

``

632


/// ```

``

633

`+

#[unstable(feature = "debug_more_non_exhaustive", issue = "127942")]

`

``

634

`+

pub fn finish_non_exhaustive(&mut self) -> fmt::Result {

`

``

635

`+

self.inner.result = self.inner.result.and_then(|_| {

`

``

636

`+

if self.inner.has_fields {

`

``

637

`+

if self.inner.is_pretty() {

`

``

638

`+

let mut slot = None;

`

``

639

`+

let mut state = Default::default();

`

``

640

`+

let mut writer = PadAdapter::wrap(self.inner.fmt, &mut slot, &mut state);

`

``

641

`+

writer.write_str("..\n")?;

`

``

642

`+

self.inner.fmt.write_str("}")

`

``

643

`+

} else {

`

``

644

`+

self.inner.fmt.write_str(", ..}")

`

``

645

`+

}

`

``

646

`+

} else {

`

``

647

`+

self.inner.fmt.write_str("..}")

`

``

648

`+

}

`

``

649

`+

});

`

``

650

`+

self.inner.result

`

``

651

`+

}

`

``

652

+

558

653

`/// Finishes output and returns any error encountered.

`

559

654

`///

`

560

655

`/// # Examples

`

`@@ -699,6 +794,55 @@ impl<'a, 'b: 'a> DebugList<'a, 'b> {

`

699

794

`self

`

700

795

`}

`

701

796

``

``

797

`+

/// Marks the list as non-exhaustive, indicating to the reader that there are some other

`

``

798

`+

/// elements that are not shown in the debug representation.

`

``

799

`+

///

`

``

800

`+

/// # Examples

`

``

801

`+

///

`

``

802


/// ```

``

803

`+

/// #![feature(debug_more_non_exhaustive)]

`

``

804

`+

///

`

``

805

`+

/// use std::fmt;

`

``

806

`+

///

`

``

807

`+

/// struct Foo(Vec);

`

``

808

`+

///

`

``

809

`+

/// impl fmt::Debug for Foo {

`

``

810

`+

/// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {

`

``

811

`+

/// // Print at most two elements, abbreviate the rest

`

``

812

`+

/// let mut f = fmt.debug_list();

`

``

813

`+

/// let mut f = f.entries(self.0.iter().take(2));

`

``

814

`+

/// if self.0.len() > 2 {

`

``

815

`+

/// f.finish_non_exhaustive()

`

``

816

`+

/// } else {

`

``

817

`+

/// f.finish()

`

``

818

`+

/// }

`

``

819

`+

/// }

`

``

820

`+

/// }

`

``

821

`+

///

`

``

822

`+

/// assert_eq!(

`

``

823

`+

/// format!("{:?}", Foo(vec![1, 2, 3, 4])),

`

``

824

`+

/// "[1, 2, ..]",

`

``

825

`+

/// );

`

``

826


/// ```

``

827

`+

#[unstable(feature = "debug_more_non_exhaustive", issue = "127942")]

`

``

828

`+

pub fn finish_non_exhaustive(&mut self) -> fmt::Result {

`

``

829

`+

self.inner.result.and_then(|_| {

`

``

830

`+

if self.inner.has_fields {

`

``

831

`+

if self.inner.is_pretty() {

`

``

832

`+

let mut slot = None;

`

``

833

`+

let mut state = Default::default();

`

``

834

`+

let mut writer = PadAdapter::wrap(self.inner.fmt, &mut slot, &mut state);

`

``

835

`+

writer.write_str("..\n")?;

`

``

836

`+

self.inner.fmt.write_str("]")

`

``

837

`+

} else {

`

``

838

`+

self.inner.fmt.write_str(", ..]")

`

``

839

`+

}

`

``

840

`+

} else {

`

``

841

`+

self.inner.fmt.write_str("..]")

`

``

842

`+

}

`

``

843

`+

})

`

``

844

`+

}

`

``

845

+

702

846

`/// Finishes output and returns any error encountered.

`

703

847

`///

`

704

848

`/// # Examples

`

`@@ -750,7 +894,7 @@ impl<'a, 'b: 'a> DebugList<'a, 'b> {

`

750

894

`///

`

751

895

`/// assert_eq!(

`

752

896

`/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),

`

753

``

`-

/// "{"A": 10, "B": 11}",

`

``

897

`+

/// r#"{"A": 10, "B": 11}"#,

`

754

898

`/// );

`

755

899

```` /// ```


`756`

`900`

`` #[must_use = "must eventually call `finish()` on Debug builders"]

``

`@@ -790,7 +934,7 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {

`

`790`

`934`

`///

`

`791`

`935`

`/// assert_eq!(

`

`792`

`936`

`/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),

`

`793`

``

`-

/// "{\"whole\": [(\"A\", 10), (\"B\", 11)]}",

`

``

`937`

`+

/// r#"{"whole": [("A", 10), ("B", 11)]}"#,

`

`794`

`938`

`/// );

`

`795`

`939`

```` /// ```

796

940

`#[stable(feature = "debug_builders", since = "1.2.0")]

`

`@@ -826,7 +970,7 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {

`

826

970

`///

`

827

971

`/// assert_eq!(

`

828

972

`/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),

`

829

``

`-

/// "{"whole": [("A", 10), ("B", 11)]}",

`

``

973

`+

/// r#"{"whole": [("A", 10), ("B", 11)]}"#,

`

830

974

`/// );

`

831

975

```` /// ```


`832`

`976`

`#[stable(feature = "debug_map_key_value", since = "1.42.0")]

`

`@@ -902,7 +1046,7 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {

`

`902`

`1046`

`///

`

`903`

`1047`

`/// assert_eq!(

`

`904`

`1048`

`/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),

`

`905`

``

`-

/// "{\"whole\": [(\"A\", 10), (\"B\", 11)]}",

`

``

`1049`

`+

/// r#"{"whole": [("A", 10), ("B", 11)]}"#,

`

`906`

`1050`

`/// );

`

`907`

`1051`

```` /// ```

908

1052

`#[stable(feature = "debug_map_key_value", since = "1.42.0")]

`

`@@ -960,7 +1104,7 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {

`

960

1104

`///

`

961

1105

`/// assert_eq!(

`

962

1106

`/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),

`

963

``

`-

/// "{"A": 10, "B": 11}",

`

``

1107

`+

/// r#"{"A": 10, "B": 11}"#,

`

964

1108

`/// );

`

965

1109

```` /// ```


`966`

`1110`

`#[stable(feature = "debug_builders", since = "1.2.0")]

`

`@@ -976,6 +1120,62 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {

`

`976`

`1120`

`self

`

`977`

`1121`

`}

`

`978`

`1122`

``

``

`1123`

`+

/// Marks the map as non-exhaustive, indicating to the reader that there are some other

`

``

`1124`

`+

/// entries that are not shown in the debug representation.

`

``

`1125`

`+

///

`

``

`1126`

`+

/// # Examples

`

``

`1127`

`+

///

`

``

`1128`

```` +

/// ```

``

1129

`+

/// #![feature(debug_more_non_exhaustive)]

`

``

1130

`+

///

`

``

1131

`+

/// use std::fmt;

`

``

1132

`+

///

`

``

1133

`+

/// struct Foo(Vec<(String, i32)>);

`

``

1134

`+

///

`

``

1135

`+

/// impl fmt::Debug for Foo {

`

``

1136

`+

/// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {

`

``

1137

`+

/// // Print at most two elements, abbreviate the rest

`

``

1138

`+

/// let mut f = fmt.debug_map();

`

``

1139

`+

/// let mut f = f.entries(self.0.iter().take(2).map(|&(ref k, ref v)| (k, v)));

`

``

1140

`+

/// if self.0.len() > 2 {

`

``

1141

`+

/// f.finish_non_exhaustive()

`

``

1142

`+

/// } else {

`

``

1143

`+

/// f.finish()

`

``

1144

`+

/// }

`

``

1145

`+

/// }

`

``

1146

`+

/// }

`

``

1147

`+

///

`

``

1148

`+

/// assert_eq!(

`

``

1149

`+

/// format!("{:?}", Foo(vec![

`

``

1150

`+

/// ("A".to_string(), 10),

`

``

1151

`+

/// ("B".to_string(), 11),

`

``

1152

`+

/// ("C".to_string(), 12),

`

``

1153

`+

/// ])),

`

``

1154

`+

/// r#"{"A": 10, "B": 11, ..}"#,

`

``

1155

`+

/// );

`

``

1156


/// ```

``

1157

`+

#[unstable(feature = "debug_more_non_exhaustive", issue = "127942")]

`

``

1158

`+

pub fn finish_non_exhaustive(&mut self) -> fmt::Result {

`

``

1159

`+

self.result = self.result.and_then(|_| {

`

``

1160

`+

assert!(!self.has_key, "attempted to finish a map with a partial entry");

`

``

1161

+

``

1162

`+

if self.has_fields {

`

``

1163

`+

if self.is_pretty() {

`

``

1164

`+

let mut slot = None;

`

``

1165

`+

let mut state = Default::default();

`

``

1166

`+

let mut writer = PadAdapter::wrap(self.fmt, &mut slot, &mut state);

`

``

1167

`+

writer.write_str("..\n")?;

`

``

1168

`+

self.fmt.write_str("}")

`

``

1169

`+

} else {

`

``

1170

`+

self.fmt.write_str(", ..}")

`

``

1171

`+

}

`

``

1172

`+

} else {

`

``

1173

`+

self.fmt.write_str("..}")

`

``

1174

`+

}

`

``

1175

`+

});

`

``

1176

`+

self.result

`

``

1177

`+

}

`

``

1178

+

979

1179

`/// Finishes output and returns any error encountered.

`

980

1180

`///

`

981

1181

`/// # Panics

`

`@@ -1000,7 +1200,7 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {

`

1000

1200

`///

`

1001

1201

`/// assert_eq!(

`

1002

1202

`/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),

`

1003

``

`-

/// "{"A": 10, "B": 11}",

`

``

1203

`+

/// r#"{"A": 10, "B": 11}"#,

`

1004

1204

`/// );

`

1005

1205

```` /// ```

````

1006

1206

`#[stable(feature = "debug_builders", since = "1.2.0")]

`