]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_data_structures/src/lib.rs
Rollup merge of #94022 - jongiddy:cow-into-owned-docs, r=Dylan-DPC
[rust.git] / compiler / rustc_data_structures / src / lib.rs
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.
4 //!
5 //! # Note
6 //!
7 //! This API is completely unstable and subject to change.
8
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)]
19 #![feature(let_else)]
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)]
28 #![feature(test)]
29 #![feature(thread_id_value)]
30 #![feature(vec_into_raw_parts)]
31 #![allow(rustc::default_hash_types)]
32 #![allow(rustc::potential_query_instability)]
33
34 #[macro_use]
35 extern crate tracing;
36 #[macro_use]
37 extern crate cfg_if;
38 #[macro_use]
39 extern crate rustc_macros;
40
41 pub use rustc_index::static_assert_size;
42
43 #[inline(never)]
44 #[cold]
45 pub fn cold_path<F: FnOnce() -> R, R>(f: F) -> R {
46     f()
47 }
48
49 #[macro_export]
50 macro_rules! likely {
51     ($e:expr) => {
52         match $e {
53             #[allow(unused_unsafe)]
54             e => unsafe { std::intrinsics::likely(e) },
55         }
56     };
57 }
58
59 #[macro_export]
60 macro_rules! unlikely {
61     ($e:expr) => {
62         match $e {
63             #[allow(unused_unsafe)]
64             e => unsafe { std::intrinsics::unlikely(e) },
65         }
66     };
67 }
68
69 pub mod base_n;
70 pub mod binary_search_util;
71 pub mod captures;
72 pub mod flock;
73 pub mod functor;
74 pub mod fx;
75 pub mod graph;
76 pub mod intern;
77 pub mod jobserver;
78 pub mod macros;
79 pub mod map_in_place;
80 pub mod obligation_forest;
81 pub mod owning_ref;
82 pub mod sip128;
83 pub mod small_c_str;
84 pub mod small_str;
85 pub mod snapshot_map;
86 pub mod stable_map;
87 pub mod svh;
88 pub use ena::snapshot_vec;
89 pub mod memmap;
90 pub mod sorted_map;
91 pub mod stable_set;
92 #[macro_use]
93 pub mod stable_hasher;
94 mod atomic_ref;
95 pub mod fingerprint;
96 pub mod profiling;
97 pub mod sharded;
98 pub mod stack;
99 pub mod sync;
100 pub mod thin_vec;
101 pub mod tiny_list;
102 pub mod transitive_relation;
103 pub mod vec_linked_list;
104 pub mod vec_map;
105 pub mod work_queue;
106 pub use atomic_ref::AtomicRef;
107 pub mod frozen;
108 pub mod sso;
109 pub mod steal;
110 pub mod tagged_ptr;
111 pub mod temp_dir;
112 pub mod unhash;
113
114 pub use ena::undo_log;
115 pub use ena::unify;
116
117 use std::ops::{Generator, GeneratorState};
118 use std::pin::Pin;
119
120 pub struct OnDrop<F: Fn()>(pub F);
121
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.
125     #[inline]
126     pub fn disable(self) {
127         std::mem::forget(self);
128     }
129 }
130
131 impl<F: Fn()> Drop for OnDrop<F> {
132     #[inline]
133     fn drop(&mut self) {
134         (self.0)();
135     }
136 }
137
138 struct IterFromGenerator<G>(G);
139
140 impl<G: Generator<Return = ()> + Unpin> Iterator for IterFromGenerator<G> {
141     type Item = G::Yield;
142
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,
147         }
148     }
149 }
150
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>(
153     generator: G,
154 ) -> impl Iterator<Item = G::Yield> {
155     IterFromGenerator(generator)
156 }
157
158 // See comments in src/librustc_middle/lib.rs
159 #[doc(hidden)]
160 pub fn __noop_fix_for_27438() {}