]> git.lizzy.rs Git - rust.git/commit - src/tools/clippy
Auto merge of #66716 - derekdreery:debug_non_exhaustive, r=dtolnay
authorbors <bors@rust-lang.org>
Fri, 17 Jan 2020 00:20:48 +0000 (00:20 +0000)
committerbors <bors@rust-lang.org>
Fri, 17 Jan 2020 00:20:48 +0000 (00:20 +0000)
commit8cacf50563ba0f60855d3465f019290d29495ec1
tree9efd2b59f04a6da177d33545676bd1d346a5e83b
parentecbc222855c890c3aabe4848e8d8b312debcf0ff
parent73124df6eba9d81affb3ef597fdaeb4fce82f7af
Auto merge of #66716 - derekdreery:debug_non_exhaustive, r=dtolnay

Implement `DebugStruct::non_exhaustive`.

This patch adds a function (finish_non_exhaustive) to add ellipsis before the closing brace when formatting using `DebugStruct`.

 ## Example

 ```rust
 #![feature(debug_non_exhaustive)]
 use std::fmt;

 struct Bar {
     bar: i32,
     hidden: f32,
 }

 impl fmt::Debug for Bar {
     fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
         fmt.debug_struct("Bar")
            .field("bar", &self.bar)
            .non_exhaustive(true) // Show that some other field(s) exist.
            .finish()
     }
 }

 assert_eq!(
     format!("{:?}", Bar { bar: 10, hidden: 1.0 }),
     "Bar { bar: 10, .. }",
 );
 ```