summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_data_structures/src/lib.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
commitc23a457e72abe608715ac76f076f47dc42af07a5 (patch)
tree2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /compiler/rustc_data_structures/src/lib.rs
parentReleasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz
rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_data_structures/src/lib.rs')
-rw-r--r--compiler/rustc_data_structures/src/lib.rs24
1 files changed, 22 insertions, 2 deletions
diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs
index 337720897..461ec3a90 100644
--- a/compiler/rustc_data_structures/src/lib.rs
+++ b/compiler/rustc_data_structures/src/lib.rs
@@ -37,7 +37,7 @@
#![allow(rustc::potential_query_instability)]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
-#![cfg_attr(not(bootstrap), allow(internal_features))]
+#![allow(internal_features)]
#![deny(unsafe_op_in_unsafe_fn)]
#[macro_use]
@@ -47,11 +47,14 @@ extern crate cfg_if;
#[macro_use]
extern crate rustc_macros;
+use std::fmt;
+
pub use rustc_index::static_assert_size;
+/// This calls the passed function while ensuring it won't be inlined into the caller.
#[inline(never)]
#[cold]
-pub fn cold_path<F: FnOnce() -> R, R>(f: F) -> R {
+pub fn outline<F: FnOnce() -> R, R>(f: F) -> R {
f()
}
@@ -126,6 +129,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() {}