rust/compiler/rustc_data_structures/src/lib.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

150 lines
3.5 KiB
Rust
Raw Normal View History

2015-04-07 10:10:53 +00: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 10:10:53 +00:00
//! it can be easily unit tested and so forth.
//!
//! # Note
//!
//! This API is completely unstable and subject to change.
// tidy-alphabetical-start
#![allow(internal_features)]
#![allow(rustc::default_hash_types)]
#![allow(rustc::potential_query_instability)]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![deny(rustc::diagnostic_outside_of_impl)]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(unsafe_op_in_unsafe_fn)]
2020-09-23 19:51:56 +00:00
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(allocator_api)]
#![feature(array_windows)]
2021-06-21 21:30:16 +00:00
#![feature(auto_traits)]
#![feature(cell_leak)]
#![feature(cfg_match)]
#![feature(core_intrinsics)]
2021-06-21 21:30:16 +00:00
#![feature(extend_one)]
#![feature(hash_raw_entry)]
#![feature(hasher_prefixfree_extras)]
#![feature(lazy_cell)]
#![feature(lint_reasons)]
#![feature(macro_metavar_expr)]
2021-06-21 21:30:16 +00:00
#![feature(maybe_uninit_uninit_array)]
#![feature(min_specialization)]
#![feature(negative_impls)]
#![feature(never_type)]
#![feature(ptr_alignment_type)]
#![feature(rustc_attrs)]
#![feature(strict_provenance)]
#![feature(test)]
#![feature(thread_id_value)]
#![feature(type_alias_impl_trait)]
2023-04-10 01:53:50 +00:00
#![feature(unwrap_infallible)]
// tidy-alphabetical-end
2019-02-08 16:36:22 +00:00
#[macro_use]
2020-08-05 11:35:53 +00:00
extern crate tracing;
#[macro_use]
extern crate rustc_macros;
use std::fmt;
pub use rustc_index::static_assert_size;
2023-09-25 01:27:25 +00:00
/// This calls the passed function while ensuring it won't be inlined into the caller.
2019-01-24 19:05:19 +00:00
#[inline(never)]
#[cold]
2023-09-25 01:27:25 +00:00
pub fn outline<F: FnOnce() -> R, R>(f: F) -> R {
2019-01-24 19:05:19 +00:00
f()
}
pub mod base_n;
pub mod binary_search_util;
pub mod captures;
pub mod flat_map_in_place;
pub mod flock;
pub mod fx;
pub mod graph;
pub mod intern;
pub mod jobserver;
pub mod macros;
pub mod obligation_forest;
pub mod sip128;
pub mod small_c_str;
2016-05-21 12:18:09 +00:00
pub mod snapshot_map;
2018-08-03 18:22:22 +00:00
pub mod svh;
pub use ena::snapshot_vec;
pub mod memmap;
pub mod sorted_map;
2018-08-04 00:34:23 +00:00
#[macro_use]
pub mod stable_hasher;
2020-09-19 15:27:13 +00:00
mod atomic_ref;
pub mod fingerprint;
pub mod marker;
2020-09-19 15:27:13 +00:00
pub mod profiling;
2019-06-12 12:39:12 +00:00
pub mod sharded;
pub mod stack;
2018-05-28 15:43:53 +00:00
pub mod sync;
pub mod tiny_list;
pub mod transitive_relation;
pub mod vec_linked_list;
pub mod work_queue;
pub use atomic_ref::AtomicRef;
pub mod aligned;
2020-03-13 18:28:25 +00:00
pub mod frozen;
mod hashes;
2023-04-05 13:25:04 +00:00
pub mod owned_slice;
pub mod sso;
2020-11-14 00:29:30 +00:00
pub mod steal;
pub mod tagged_ptr;
pub mod temp_dir;
pub mod unhash;
pub mod unord;
2020-09-19 15:27:13 +00:00
pub use ena::undo_log;
pub use ena::unify;
/// 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 09:38:12 +00:00
impl<F: FnOnce()> OnDrop<F> {
/// Disables on-drop call.
2018-12-05 17:59:48 +00:00
#[inline]
pub fn disable(mut self) {
self.0.take();
2018-05-27 05:47:44 +00:00
}
}
impl<F: FnOnce()> Drop for OnDrop<F> {
2018-12-05 17:59:48 +00:00
#[inline]
2018-03-15 09:38:12 +00:00
fn drop(&mut self) {
if let Some(f) = self.0.take() {
f();
}
2018-03-15 09:38:12 +00: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 13:24:45 +00:00
// See comments in src/librustc_middle/lib.rs
#[doc(hidden)]
pub fn __noop_fix_for_27438() {}