about summary refs log tree commit diff
path: root/compiler/rustc_data_structures/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-09-21 08:01:45 +0000
committerbors <bors@rust-lang.org>2023-09-21 08:01:45 +0000
commitd2db689e1efa5b3fff6b664b6d2dba0ef65b80e7 (patch)
treee947a059c42ff87214337cc3a825e0b338af394d /compiler/rustc_data_structures/src
parent70f3d3e6ad6656546f79fac961ed3a4316003fa3 (diff)
parented8fbcb05910f4439ec572bd163cc99a3603e378 (diff)
downloadrust-d2db689e1efa5b3fff6b664b6d2dba0ef65b80e7.tar.gz
rust-d2db689e1efa5b3fff6b664b6d2dba0ef65b80e7.zip
Auto merge of #3069 - rust-lang:rustup-2023-09-21, r=RalfJung
Automatic sync from rustc
Diffstat (limited to 'compiler/rustc_data_structures/src')
-rw-r--r--compiler/rustc_data_structures/src/lib.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs
index bee5a89c4c7..7d037ddfa98 100644
--- a/compiler/rustc_data_structures/src/lib.rs
+++ b/compiler/rustc_data_structures/src/lib.rs
@@ -47,6 +47,8 @@ extern crate cfg_if;
 #[macro_use]
 extern crate rustc_macros;
 
+use std::fmt;
+
 pub use rustc_index::static_assert_size;
 
 #[inline(never)]
@@ -126,6 +128,23 @@ impl<F: FnOnce()> Drop for OnDrop<F> {
     }
 }
 
+/// Turns a closure that takes an `&mut Formatter` into something that can be display-formatted.
+pub fn make_display(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl fmt::Display {
+    struct Printer<F> {
+        f: F,
+    }
+    impl<F> fmt::Display for Printer<F>
+    where
+        F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result,
+    {
+        fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
+            (self.f)(fmt)
+        }
+    }
+
+    Printer { f }
+}
+
 // See comments in src/librustc_middle/lib.rs
 #[doc(hidden)]
 pub fn __noop_fix_for_27438() {}