refactor(rustfix): simplify debug print for Span

This commit is contained in:
Weihang Lo 2024-10-20 11:57:15 -04:00
parent 6ac20fd1be
commit f483dc0b95
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7

View File

@ -24,7 +24,7 @@ impl State {
} }
/// Span with a change [`State`]. /// Span with a change [`State`].
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Clone, PartialEq, Eq)]
struct Span { struct Span {
/// Start of this span in parent data /// Start of this span in parent data
start: usize, start: usize,
@ -34,6 +34,17 @@ struct Span {
data: State, data: State,
} }
impl std::fmt::Debug for Span {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let state = match self.data {
State::Initial => "initial",
State::Replaced(_) => "replaced",
State::Inserted(_) => "inserted",
};
write!(f, "({}, {}: {state})", self.start, self.end)
}
}
/// A container that allows easily replacing chunks of its data /// A container that allows easily replacing chunks of its data
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
pub struct Data { pub struct Data {
@ -102,30 +113,12 @@ impl Data {
.iter() .iter()
.position(|p| !p.data.is_inserted() && p.start <= range.start && p.end >= range.end) .position(|p| !p.data.is_inserted() && p.start <= range.start && p.end >= range.end)
else { else {
if tracing::enabled!(tracing::Level::DEBUG) { tracing::debug!(
let slices = self "no single slice covering {}..{}, current slices: {:?}",
.parts range.start,
.iter() range.end,
.map(|p| { self.parts,
( );
p.start,
p.end,
match p.data {
State::Initial => "initial",
State::Replaced(..) => "replaced",
State::Inserted(..) => "inserted",
},
)
})
.collect::<Vec<_>>();
tracing::debug!(
"no single slice covering {}..{}, current slices: {:?}",
range.start,
range.end,
slices,
);
}
return Err(Error::MaybeAlreadyReplaced(range)); return Err(Error::MaybeAlreadyReplaced(range));
}; };