Skip to content

Commit 815be93

Browse files
committed
rustc_hir: replace debug_fn with unstable fmt::from_fn
1 parent 8231e85 commit 815be93

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

compiler/rustc_hir/src/hir.rs

+7-17
Original file line numberDiff line numberDiff line change
@@ -1285,13 +1285,13 @@ impl fmt::Debug for OwnerNodes<'_> {
12851285
.field("node", &self.nodes[ItemLocalId::ZERO])
12861286
.field(
12871287
"parents",
1288-
&self
1289-
.nodes
1290-
.iter_enumerated()
1291-
.map(|(id, parented_node)| {
1292-
debug_fn(move |f| write!(f, "({id:?}, {:?})", parented_node.parent))
1293-
})
1294-
.collect::<Vec<_>>(),
1288+
&fmt::from_fn(|f| {
1289+
f.debug_list()
1290+
.entries(self.nodes.iter_enumerated().map(|(id, parented_node)| {
1291+
fmt::from_fn(move |f| write!(f, "({id:?}, {:?})", parented_node.parent))
1292+
}))
1293+
.finish()
1294+
}),
12951295
)
12961296
.field("bodies", &self.bodies)
12971297
.field("opt_hash_including_bodies", &self.opt_hash_including_bodies)
@@ -4638,15 +4638,5 @@ mod size_asserts {
46384638
// tidy-alphabetical-end
46394639
}
46404640

4641-
fn debug_fn(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl fmt::Debug {
4642-
struct DebugFn<F>(F);
4643-
impl<F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result> fmt::Debug for DebugFn<F> {
4644-
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
4645-
(self.0)(fmt)
4646-
}
4647-
}
4648-
DebugFn(f)
4649-
}
4650-
46514641
#[cfg(test)]
46524642
mod tests;

compiler/rustc_hir/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![allow(internal_features)]
77
#![feature(associated_type_defaults)]
88
#![feature(closure_track_caller)]
9+
#![feature(debug_closure_helpers)]
910
#![feature(exhaustive_patterns)]
1011
#![feature(let_chains)]
1112
#![feature(never_type)]

0 commit comments

Comments
 (0)