Skip to content

Commit f483dc0

Browse files
committed
refactor(rustfix): simplify debug print for Span
1 parent 6ac20fd commit f483dc0

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

crates/rustfix/src/replace.rs

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl State {
2424
}
2525

2626
/// Span with a change [`State`].
27-
#[derive(Debug, Clone, PartialEq, Eq)]
27+
#[derive(Clone, PartialEq, Eq)]
2828
struct Span {
2929
/// Start of this span in parent data
3030
start: usize,
@@ -34,6 +34,17 @@ struct Span {
3434
data: State,
3535
}
3636

37+
impl std::fmt::Debug for Span {
38+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39+
let state = match self.data {
40+
State::Initial => "initial",
41+
State::Replaced(_) => "replaced",
42+
State::Inserted(_) => "inserted",
43+
};
44+
write!(f, "({}, {}: {state})", self.start, self.end)
45+
}
46+
}
47+
3748
/// A container that allows easily replacing chunks of its data
3849
#[derive(Debug, Clone, Default)]
3950
pub struct Data {
@@ -102,30 +113,12 @@ impl Data {
102113
.iter()
103114
.position(|p| !p.data.is_inserted() && p.start <= range.start && p.end >= range.end)
104115
else {
105-
if tracing::enabled!(tracing::Level::DEBUG) {
106-
let slices = self
107-
.parts
108-
.iter()
109-
.map(|p| {
110-
(
111-
p.start,
112-
p.end,
113-
match p.data {
114-
State::Initial => "initial",
115-
State::Replaced(..) => "replaced",
116-
State::Inserted(..) => "inserted",
117-
},
118-
)
119-
})
120-
.collect::<Vec<_>>();
121-
tracing::debug!(
122-
"no single slice covering {}..{}, current slices: {:?}",
123-
range.start,
124-
range.end,
125-
slices,
126-
);
127-
}
128-
116+
tracing::debug!(
117+
"no single slice covering {}..{}, current slices: {:?}",
118+
range.start,
119+
range.end,
120+
self.parts,
121+
);
129122
return Err(Error::MaybeAlreadyReplaced(range));
130123
};
131124

0 commit comments

Comments
 (0)