mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
implement custom Debug for MiniCore
When the contents correspond to the default, just output
`MiniCore("<default>")` instead of the whole thing.
Helps reduce the length of the debug output in the common case.
This commit is contained in:
@@ -385,7 +385,7 @@ pub enum Severity {
|
||||
Allow,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct MiniCore<'a>(&'a str);
|
||||
|
||||
impl<'a> MiniCore<'a> {
|
||||
@@ -400,6 +400,15 @@ pub const fn default() -> Self {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for MiniCore<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_tuple("MiniCore")
|
||||
// don't print the whole contents if they correspond to the default
|
||||
.field(if self.0 == test_utils::MiniCore::RAW_SOURCE { &"<default>" } else { &self.0 })
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Default for MiniCore<'a> {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
|
||||
Reference in New Issue
Block a user