1 //! Various data structures used by the Rust compiler. The intention
2 //! is that code in here should be not be *specific* to rustc, so that
3 //! it can be easily unit tested and so forth.
7 //! This API is completely unstable and subject to change.
9 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
10 #![feature(array_windows)]
11 #![feature(associated_type_bounds)]
12 #![feature(auto_traits)]
13 #![feature(bool_to_option)]
14 #![feature(control_flow_enum)]
15 #![feature(core_intrinsics)]
16 #![feature(extend_one)]
17 #![feature(generator_trait)]
18 #![feature(generators)]
20 #![feature(hash_raw_entry)]
21 #![feature(maybe_uninit_uninit_array)]
22 #![feature(min_specialization)]
23 #![feature(never_type)]
24 #![feature(type_alias_impl_trait)]
25 #![feature(new_uninit)]
26 #![feature(once_cell)]
27 #![feature(rustc_attrs)]
29 #![feature(thread_id_value)]
30 #![feature(vec_into_raw_parts)]
31 #![allow(rustc::default_hash_types)]
32 #![allow(rustc::potential_query_instability)]
39 extern crate rustc_macros;
41 pub use rustc_index::static_assert_size;
45 pub fn cold_path<F: FnOnce() -> R, R>(f: F) -> R {
53 #[allow(unused_unsafe)]
54 e => unsafe { std::intrinsics::likely(e) },
60 macro_rules! unlikely {
63 #[allow(unused_unsafe)]
64 e => unsafe { std::intrinsics::unlikely(e) },
70 pub mod binary_search_util;
80 pub mod obligation_forest;
88 pub use ena::snapshot_vec;
93 pub mod stable_hasher;
102 pub mod transitive_relation;
103 pub mod vec_linked_list;
106 pub use atomic_ref::AtomicRef;
114 pub use ena::undo_log;
117 use std::ops::{Generator, GeneratorState};
120 pub struct OnDrop<F: Fn()>(pub F);
122 impl<F: Fn()> OnDrop<F> {
123 /// Forgets the function which prevents it from running.
124 /// Ensure that the function owns no memory, otherwise it will be leaked.
126 pub fn disable(self) {
127 std::mem::forget(self);
131 impl<F: Fn()> Drop for OnDrop<F> {
138 struct IterFromGenerator<G>(G);
140 impl<G: Generator<Return = ()> + Unpin> Iterator for IterFromGenerator<G> {
141 type Item = G::Yield;
143 fn next(&mut self) -> Option<Self::Item> {
144 match Pin::new(&mut self.0).resume(()) {
145 GeneratorState::Yielded(n) => Some(n),
146 GeneratorState::Complete(_) => None,
151 /// An adapter for turning a generator closure into an iterator, similar to `iter::from_fn`.
152 pub fn iter_from_generator<G: Generator<Return = ()> + Unpin>(
154 ) -> impl Iterator<Item = G::Yield> {
155 IterFromGenerator(generator)
158 // See comments in src/librustc_middle/lib.rs
160 pub fn __noop_fix_for_27438() {}