mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
refactor(rustfix): simplify debug print for Span
This commit is contained in:
parent
6ac20fd1be
commit
f483dc0b95
@ -24,7 +24,7 @@ impl State {
|
||||
}
|
||||
|
||||
/// Span with a change [`State`].
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
struct Span {
|
||||
/// Start of this span in parent data
|
||||
start: usize,
|
||||
@ -34,6 +34,17 @@ struct Span {
|
||||
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
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct Data {
|
||||
@ -102,30 +113,12 @@ impl Data {
|
||||
.iter()
|
||||
.position(|p| !p.data.is_inserted() && p.start <= range.start && p.end >= range.end)
|
||||
else {
|
||||
if tracing::enabled!(tracing::Level::DEBUG) {
|
||||
let slices = self
|
||||
.parts
|
||||
.iter()
|
||||
.map(|p| {
|
||||
(
|
||||
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,
|
||||
);
|
||||
}
|
||||
|
||||
tracing::debug!(
|
||||
"no single slice covering {}..{}, current slices: {:?}",
|
||||
range.start,
|
||||
range.end,
|
||||
self.parts,
|
||||
);
|
||||
return Err(Error::MaybeAlreadyReplaced(range));
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user