Skip to content

Commit d101311

Browse files
committed
rustc_hir: replace debug_fn with unstable fmt::from_fn
1 parent 99768c8 commit d101311

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
@@ -1239,13 +1239,13 @@ impl fmt::Debug for OwnerNodes<'_> {
12391239
.field("node", &self.nodes[ItemLocalId::ZERO])
12401240
.field(
12411241
"parents",
1242-
&self
1243-
.nodes
1244-
.iter_enumerated()
1245-
.map(|(id, parented_node)| {
1246-
debug_fn(move |f| write!(f, "({id:?}, {:?})", parented_node.parent))
1247-
})
1248-
.collect::<Vec<_>>(),
1242+
&fmt::from_fn(|f| {
1243+
f.debug_list()
1244+
.entries(self.nodes.iter_enumerated().map(|(id, parented_node)| {
1245+
fmt::from_fn(move |f| write!(f, "({id:?}, {:?})", parented_node.parent))
1246+
}))
1247+
.finish()
1248+
}),
12491249
)
12501250
.field("bodies", &self.bodies)
12511251
.field("opt_hash_including_bodies", &self.opt_hash_including_bodies)
@@ -4527,13 +4527,3 @@ mod size_asserts {
45274527
static_assert_size!(TyKind<'_>, 32);
45284528
// tidy-alphabetical-end
45294529
}
4530-
4531-
fn debug_fn(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl fmt::Debug {
4532-
struct DebugFn<F>(F);
4533-
impl<F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result> fmt::Debug for DebugFn<F> {
4534-
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
4535-
(self.0)(fmt)
4536-
}
4537-
}
4538-
DebugFn(f)
4539-
}

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(let_chains)]
1011
#![feature(never_type)]
1112
#![feature(rustc_attrs)]

0 commit comments

Comments
 (0)