2015-04-07 06:10:53 -04:00
|
|
|
//! Various data structures used by the Rust compiler. The intention
|
2023-04-05 13:48:19 +00:00
|
|
|
//! is that code in here should not be *specific* to rustc, so that
|
2015-04-07 06:10:53 -04:00
|
|
|
//! it can be easily unit tested and so forth.
|
|
|
|
//!
|
|
|
|
//! # Note
|
|
|
|
//!
|
|
|
|
//! This API is completely unstable and subject to change.
|
|
|
|
|
2023-10-19 20:18:51 -03:00
|
|
|
// tidy-alphabetical-start
|
|
|
|
#![allow(internal_features)]
|
|
|
|
#![allow(rustc::default_hash_types)]
|
|
|
|
#![allow(rustc::potential_query_instability)]
|
|
|
|
#![deny(rustc::diagnostic_outside_of_impl)]
|
|
|
|
#![deny(rustc::untranslatable_diagnostic)]
|
|
|
|
#![deny(unsafe_op_in_unsafe_fn)]
|
2020-09-23 21:51:56 +02:00
|
|
|
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
2023-11-13 07:39:17 -05:00
|
|
|
#![doc(rust_logo)]
|
2023-10-19 20:18:51 -03:00
|
|
|
#![feature(allocator_api)]
|
2020-09-17 09:28:14 +02:00
|
|
|
#![feature(array_windows)]
|
2021-06-22 06:30:16 +09:00
|
|
|
#![feature(auto_traits)]
|
2021-07-12 22:19:25 +02:00
|
|
|
#![feature(cell_leak)]
|
2023-10-19 20:18:51 -03:00
|
|
|
#![feature(cfg_match)]
|
2023-02-01 04:49:09 +01:00
|
|
|
#![feature(core_intrinsics)]
|
2021-06-22 06:30:16 +09:00
|
|
|
#![feature(extend_one)]
|
|
|
|
#![feature(hash_raw_entry)]
|
2022-03-04 00:17:26 -08:00
|
|
|
#![feature(hasher_prefixfree_extras)]
|
2023-10-19 20:18:51 -03:00
|
|
|
#![feature(lazy_cell)]
|
|
|
|
#![feature(lint_reasons)]
|
|
|
|
#![feature(macro_metavar_expr)]
|
2021-06-22 06:30:16 +09:00
|
|
|
#![feature(maybe_uninit_uninit_array)]
|
2020-05-09 13:59:21 +02:00
|
|
|
#![feature(min_specialization)]
|
2023-10-19 20:18:51 -03:00
|
|
|
#![feature(negative_impls)]
|
2021-09-05 23:37:15 +03:00
|
|
|
#![feature(never_type)]
|
2023-10-19 20:18:51 -03:00
|
|
|
#![feature(ptr_alignment_type)]
|
2022-02-04 14:26:29 +11:00
|
|
|
#![feature(rustc_attrs)]
|
2023-11-13 07:39:17 -05:00
|
|
|
#![feature(rustdoc_internals)]
|
2023-10-19 20:18:51 -03:00
|
|
|
#![feature(strict_provenance)]
|
2019-07-27 15:06:49 +03:00
|
|
|
#![feature(test)]
|
2020-01-24 21:24:24 -05:00
|
|
|
#![feature(thread_id_value)]
|
2023-10-19 20:18:51 -03:00
|
|
|
#![feature(type_alias_impl_trait)]
|
2023-04-10 09:53:50 +08:00
|
|
|
#![feature(unwrap_infallible)]
|
2023-10-19 20:18:51 -03:00
|
|
|
// tidy-alphabetical-end
|
2019-02-09 01:36:22 +09:00
|
|
|
|
2016-03-05 08:40:33 -05:00
|
|
|
#[macro_use]
|
2020-08-05 17:05:53 +05:30
|
|
|
extern crate tracing;
|
2017-12-03 13:49:01 +01:00
|
|
|
#[macro_use]
|
2020-06-11 15:49:57 +01:00
|
|
|
extern crate rustc_macros;
|
2015-04-07 06:11:49 -04:00
|
|
|
|
2023-09-15 08:21:40 +02:00
|
|
|
use std::fmt;
|
|
|
|
|
2022-02-10 00:47:48 +11:00
|
|
|
pub use rustc_index::static_assert_size;
|
|
|
|
|
2023-09-25 03:27:25 +02:00
|
|
|
/// This calls the passed function while ensuring it won't be inlined into the caller.
|
2019-01-24 20:05:19 +01:00
|
|
|
#[inline(never)]
|
|
|
|
#[cold]
|
2023-09-25 03:27:25 +02:00
|
|
|
pub fn outline<F: FnOnce() -> R, R>(f: F) -> R {
|
2019-01-24 20:05:19 +01:00
|
|
|
f()
|
|
|
|
}
|
|
|
|
|
2016-11-04 17:37:42 -04:00
|
|
|
pub mod base_n;
|
2019-06-17 07:55:54 -04:00
|
|
|
pub mod binary_search_util;
|
2020-01-06 07:03:46 +01:00
|
|
|
pub mod captures;
|
2023-03-08 15:53:56 +11:00
|
|
|
pub mod flat_map_in_place;
|
2018-07-18 21:53:54 +03:00
|
|
|
pub mod flock;
|
|
|
|
pub mod fx;
|
|
|
|
pub mod graph;
|
2022-02-04 14:26:29 +11:00
|
|
|
pub mod intern;
|
2018-12-18 09:03:38 +01:00
|
|
|
pub mod jobserver;
|
2018-11-09 09:57:02 +11:00
|
|
|
pub mod macros;
|
2015-11-18 14:44:24 -05:00
|
|
|
pub mod obligation_forest;
|
2017-10-16 13:16:04 +02:00
|
|
|
pub mod sip128;
|
2018-08-07 16:04:34 +02:00
|
|
|
pub mod small_c_str;
|
2016-05-21 08:18:09 -04:00
|
|
|
pub mod snapshot_map;
|
2018-08-03 12:22:22 -06:00
|
|
|
pub mod svh;
|
2017-07-16 07:07:51 -04:00
|
|
|
pub use ena::snapshot_vec;
|
2021-03-29 11:18:52 +02:00
|
|
|
pub mod memmap;
|
2018-07-18 21:53:54 +03:00
|
|
|
pub mod sorted_map;
|
2018-08-03 18:34:23 -06:00
|
|
|
#[macro_use]
|
|
|
|
pub mod stable_hasher;
|
2020-09-19 17:27:13 +02:00
|
|
|
mod atomic_ref;
|
|
|
|
pub mod fingerprint;
|
2023-03-03 10:14:57 +08:00
|
|
|
pub mod marker;
|
2020-09-19 17:27:13 +02:00
|
|
|
pub mod profiling;
|
2019-06-12 14:39:12 +02:00
|
|
|
pub mod sharded;
|
2020-03-14 20:13:55 +02:00
|
|
|
pub mod stack;
|
2018-05-28 17:43:53 +02:00
|
|
|
pub mod sync;
|
2018-08-12 13:07:14 -04:00
|
|
|
pub mod tiny_list;
|
2018-07-18 21:53:54 +03:00
|
|
|
pub mod transitive_relation;
|
2018-08-12 13:07:14 -04:00
|
|
|
pub mod vec_linked_list;
|
2018-06-29 06:38:48 -04:00
|
|
|
pub mod work_queue;
|
2019-12-25 13:38:57 -05:00
|
|
|
pub use atomic_ref::AtomicRef;
|
2023-04-12 11:00:35 +00:00
|
|
|
pub mod aligned;
|
2020-03-13 13:28:25 -05:00
|
|
|
pub mod frozen;
|
2023-04-07 23:11:20 -04:00
|
|
|
mod hashes;
|
2023-04-05 13:25:04 +00:00
|
|
|
pub mod owned_slice;
|
2024-01-17 15:39:45 -08:00
|
|
|
pub mod packed;
|
2020-09-23 23:32:11 -05:00
|
|
|
pub mod sso;
|
2020-11-14 01:29:30 +01:00
|
|
|
pub mod steal;
|
2020-08-15 19:12:27 -04:00
|
|
|
pub mod tagged_ptr;
|
2020-08-08 21:05:50 -04:00
|
|
|
pub mod temp_dir;
|
2020-09-01 18:27:02 -07:00
|
|
|
pub mod unhash;
|
2022-10-27 13:23:26 +00:00
|
|
|
pub mod unord;
|
2015-08-11 11:48:43 -07:00
|
|
|
|
2020-09-19 17:27:13 +02:00
|
|
|
pub use ena::undo_log;
|
|
|
|
pub use ena::unify;
|
|
|
|
|
2023-05-23 14:53:36 +00:00
|
|
|
/// Returns a structure that calls `f` when dropped.
|
|
|
|
pub fn defer<F: FnOnce()>(f: F) -> OnDrop<F> {
|
|
|
|
OnDrop(Some(f))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct OnDrop<F: FnOnce()>(Option<F>);
|
2018-03-15 10:38:12 +01:00
|
|
|
|
2023-05-23 14:53:36 +00:00
|
|
|
impl<F: FnOnce()> OnDrop<F> {
|
|
|
|
/// Disables on-drop call.
|
2018-12-05 18:59:48 +01:00
|
|
|
#[inline]
|
2023-05-23 14:53:36 +00:00
|
|
|
pub fn disable(mut self) {
|
|
|
|
self.0.take();
|
2018-05-27 07:47:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-23 14:53:36 +00:00
|
|
|
impl<F: FnOnce()> Drop for OnDrop<F> {
|
2018-12-05 18:59:48 +01:00
|
|
|
#[inline]
|
2018-03-15 10:38:12 +01:00
|
|
|
fn drop(&mut self) {
|
2023-05-23 14:53:36 +00:00
|
|
|
if let Some(f) = self.0.take() {
|
|
|
|
f();
|
|
|
|
}
|
2018-03-15 10:38:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-03 10:56:30 +01:00
|
|
|
/// This is a marker for a fatal compiler error used with `resume_unwind`.
|
|
|
|
pub struct FatalErrorMarker;
|
|
|
|
|
2023-09-15 08:21:40 +02:00
|
|
|
/// 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 }
|
|
|
|
}
|
|
|
|
|
2020-03-29 15:24:45 +02:00
|
|
|
// See comments in src/librustc_middle/lib.rs
|
2015-08-11 11:48:43 -07:00
|
|
|
#[doc(hidden)]
|
|
|
|
pub fn __noop_fix_for_27438() {}
|
2023-12-30 17:09:02 +01:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! external_bitflags_debug {
|
|
|
|
($Name:ident) => {
|
|
|
|
impl ::std::fmt::Debug for $Name {
|
|
|
|
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
|
|
|
|
::bitflags::parser::to_writer(self, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|