]> git.lizzy.rs Git - rust.git/blob - library/core/src/intrinsics.rs
Fix naming format of IEEE 754 standard
[rust.git] / library / core / src / intrinsics.rs
1 //! Compiler intrinsics.
2 //!
3 //! The corresponding definitions are in <https://github.com/rust-lang/rust/blob/master/compiler/rustc_codegen_llvm/src/intrinsic.rs>.
4 //! The corresponding const implementations are in <https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs>.
5 //!
6 //! # Const intrinsics
7 //!
8 //! Note: any changes to the constness of intrinsics should be discussed with the language team.
9 //! This includes changes in the stability of the constness.
10 //!
11 //! In order to make an intrinsic usable at compile-time, one needs to copy the implementation
12 //! from <https://github.com/rust-lang/miri/blob/master/src/shims/intrinsics.rs> to
13 //! <https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs> and add a
14 //! `#[rustc_const_unstable(feature = "const_such_and_such", issue = "01234")]` to the intrinsic declaration.
15 //!
16 //! If an intrinsic is supposed to be used from a `const fn` with a `rustc_const_stable` attribute,
17 //! the intrinsic's attribute must be `rustc_const_stable`, too. Such a change should not be done
18 //! without T-lang consultation, because it bakes a feature into the language that cannot be
19 //! replicated in user code without compiler support.
20 //!
21 //! # Volatiles
22 //!
23 //! The volatile intrinsics provide operations intended to act on I/O
24 //! memory, which are guaranteed to not be reordered by the compiler
25 //! across other volatile intrinsics. See the LLVM documentation on
26 //! [[volatile]].
27 //!
28 //! [volatile]: https://llvm.org/docs/LangRef.html#volatile-memory-accesses
29 //!
30 //! # Atomics
31 //!
32 //! The atomic intrinsics provide common atomic operations on machine
33 //! words, with multiple possible memory orderings. They obey the same
34 //! semantics as C++11. See the LLVM documentation on [[atomics]].
35 //!
36 //! [atomics]: https://llvm.org/docs/Atomics.html
37 //!
38 //! A quick refresher on memory ordering:
39 //!
40 //! * Acquire - a barrier for acquiring a lock. Subsequent reads and writes
41 //!   take place after the barrier.
42 //! * Release - a barrier for releasing a lock. Preceding reads and writes
43 //!   take place before the barrier.
44 //! * Sequentially consistent - sequentially consistent operations are
45 //!   guaranteed to happen in order. This is the standard mode for working
46 //!   with atomic types and is equivalent to Java's `volatile`.
47
48 #![unstable(
49     feature = "core_intrinsics",
50     reason = "intrinsics are unlikely to ever be stabilized, instead \
51                       they should be used through stabilized interfaces \
52                       in the rest of the standard library",
53     issue = "none"
54 )]
55 #![allow(missing_docs)]
56
57 #[cfg(bootstrap)]
58 use crate::marker::Destruct;
59 use crate::marker::DiscriminantKind;
60 use crate::mem;
61
62 // These imports are used for simplifying intra-doc links
63 #[allow(unused_imports)]
64 #[cfg(all(target_has_atomic = "8", target_has_atomic = "32", target_has_atomic = "ptr"))]
65 use crate::sync::atomic::{self, AtomicBool, AtomicI32, AtomicIsize, AtomicU32, Ordering};
66
67 #[stable(feature = "drop_in_place", since = "1.8.0")]
68 #[rustc_allowed_through_unstable_modules]
69 #[deprecated(note = "no longer an intrinsic - use `ptr::drop_in_place` directly", since = "1.52.0")]
70 #[inline]
71 pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
72     // SAFETY: see `ptr::drop_in_place`
73     unsafe { crate::ptr::drop_in_place(to_drop) }
74 }
75
76 extern "rust-intrinsic" {
77     // N.B., these intrinsics take raw pointers because they mutate aliased
78     // memory, which is not valid for either `&` or `&mut`.
79
80     /// Stores a value if the current value is the same as the `old` value.
81     ///
82     /// The stabilized version of this intrinsic is available on the
83     /// [`atomic`] types via the `compare_exchange` method by passing
84     /// [`Ordering::Relaxed`] as both the success and failure parameters.
85     /// For example, [`AtomicBool::compare_exchange`].
86     pub fn atomic_cxchg_relaxed_relaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
87     /// Stores a value if the current value is the same as the `old` value.
88     ///
89     /// The stabilized version of this intrinsic is available on the
90     /// [`atomic`] types via the `compare_exchange` method by passing
91     /// [`Ordering::Relaxed`] and [`Ordering::Acquire`] as the success and failure parameters.
92     /// For example, [`AtomicBool::compare_exchange`].
93     pub fn atomic_cxchg_relaxed_acquire<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
94     /// Stores a value if the current value is the same as the `old` value.
95     ///
96     /// The stabilized version of this intrinsic is available on the
97     /// [`atomic`] types via the `compare_exchange` method by passing
98     /// [`Ordering::Relaxed`] and [`Ordering::SeqCst`] as the success and failure parameters.
99     /// For example, [`AtomicBool::compare_exchange`].
100     pub fn atomic_cxchg_relaxed_seqcst<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
101     /// Stores a value if the current value is the same as the `old` value.
102     ///
103     /// The stabilized version of this intrinsic is available on the
104     /// [`atomic`] types via the `compare_exchange` method by passing
105     /// [`Ordering::Acquire`] and [`Ordering::Relaxed`] as the success and failure parameters.
106     /// For example, [`AtomicBool::compare_exchange`].
107     pub fn atomic_cxchg_acquire_relaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
108     /// Stores a value if the current value is the same as the `old` value.
109     ///
110     /// The stabilized version of this intrinsic is available on the
111     /// [`atomic`] types via the `compare_exchange` method by passing
112     /// [`Ordering::Acquire`] as both the success and failure parameters.
113     /// For example, [`AtomicBool::compare_exchange`].
114     pub fn atomic_cxchg_acquire_acquire<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
115     /// Stores a value if the current value is the same as the `old` value.
116     ///
117     /// The stabilized version of this intrinsic is available on the
118     /// [`atomic`] types via the `compare_exchange` method by passing
119     /// [`Ordering::Acquire`] and [`Ordering::SeqCst`] as the success and failure parameters.
120     /// For example, [`AtomicBool::compare_exchange`].
121     pub fn atomic_cxchg_acquire_seqcst<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
122     /// Stores a value if the current value is the same as the `old` value.
123     ///
124     /// The stabilized version of this intrinsic is available on the
125     /// [`atomic`] types via the `compare_exchange` method by passing
126     /// [`Ordering::Release`] and [`Ordering::Relaxed`] as the success and failure parameters.
127     /// For example, [`AtomicBool::compare_exchange`].
128     pub fn atomic_cxchg_release_relaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
129     /// Stores a value if the current value is the same as the `old` value.
130     ///
131     /// The stabilized version of this intrinsic is available on the
132     /// [`atomic`] types via the `compare_exchange` method by passing
133     /// [`Ordering::Release`] and [`Ordering::Acquire`] as the success and failure parameters.
134     /// For example, [`AtomicBool::compare_exchange`].
135     pub fn atomic_cxchg_release_acquire<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
136     /// Stores a value if the current value is the same as the `old` value.
137     ///
138     /// The stabilized version of this intrinsic is available on the
139     /// [`atomic`] types via the `compare_exchange` method by passing
140     /// [`Ordering::Release`] and [`Ordering::SeqCst`] as the success and failure parameters.
141     /// For example, [`AtomicBool::compare_exchange`].
142     pub fn atomic_cxchg_release_seqcst<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
143     /// Stores a value if the current value is the same as the `old` value.
144     ///
145     /// The stabilized version of this intrinsic is available on the
146     /// [`atomic`] types via the `compare_exchange` method by passing
147     /// [`Ordering::AcqRel`] and [`Ordering::Relaxed`] as the success and failure parameters.
148     /// For example, [`AtomicBool::compare_exchange`].
149     pub fn atomic_cxchg_acqrel_relaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
150     /// Stores a value if the current value is the same as the `old` value.
151     ///
152     /// The stabilized version of this intrinsic is available on the
153     /// [`atomic`] types via the `compare_exchange` method by passing
154     /// [`Ordering::AcqRel`] and [`Ordering::Acquire`] as the success and failure parameters.
155     /// For example, [`AtomicBool::compare_exchange`].
156     pub fn atomic_cxchg_acqrel_acquire<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
157     /// Stores a value if the current value is the same as the `old` value.
158     ///
159     /// The stabilized version of this intrinsic is available on the
160     /// [`atomic`] types via the `compare_exchange` method by passing
161     /// [`Ordering::AcqRel`] and [`Ordering::SeqCst`] as the success and failure parameters.
162     /// For example, [`AtomicBool::compare_exchange`].
163     pub fn atomic_cxchg_acqrel_seqcst<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
164     /// Stores a value if the current value is the same as the `old` value.
165     ///
166     /// The stabilized version of this intrinsic is available on the
167     /// [`atomic`] types via the `compare_exchange` method by passing
168     /// [`Ordering::SeqCst`] and [`Ordering::Relaxed`] as the success and failure parameters.
169     /// For example, [`AtomicBool::compare_exchange`].
170     pub fn atomic_cxchg_seqcst_relaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
171     /// Stores a value if the current value is the same as the `old` value.
172     ///
173     /// The stabilized version of this intrinsic is available on the
174     /// [`atomic`] types via the `compare_exchange` method by passing
175     /// [`Ordering::SeqCst`] and [`Ordering::Acquire`] as the success and failure parameters.
176     /// For example, [`AtomicBool::compare_exchange`].
177     pub fn atomic_cxchg_seqcst_acquire<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
178     /// Stores a value if the current value is the same as the `old` value.
179     ///
180     /// The stabilized version of this intrinsic is available on the
181     /// [`atomic`] types via the `compare_exchange` method by passing
182     /// [`Ordering::SeqCst`] as both the success and failure parameters.
183     /// For example, [`AtomicBool::compare_exchange`].
184     pub fn atomic_cxchg_seqcst_seqcst<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
185
186     /// Stores a value if the current value is the same as the `old` value.
187     ///
188     /// The stabilized version of this intrinsic is available on the
189     /// [`atomic`] types via the `compare_exchange_weak` method by passing
190     /// [`Ordering::Relaxed`] as both the success and failure parameters.
191     /// For example, [`AtomicBool::compare_exchange_weak`].
192     pub fn atomic_cxchgweak_relaxed_relaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
193     /// Stores a value if the current value is the same as the `old` value.
194     ///
195     /// The stabilized version of this intrinsic is available on the
196     /// [`atomic`] types via the `compare_exchange_weak` method by passing
197     /// [`Ordering::Relaxed`] and [`Ordering::Acquire`] as the success and failure parameters.
198     /// For example, [`AtomicBool::compare_exchange_weak`].
199     pub fn atomic_cxchgweak_relaxed_acquire<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
200     /// Stores a value if the current value is the same as the `old` value.
201     ///
202     /// The stabilized version of this intrinsic is available on the
203     /// [`atomic`] types via the `compare_exchange_weak` method by passing
204     /// [`Ordering::Relaxed`] and [`Ordering::SeqCst`] as the success and failure parameters.
205     /// For example, [`AtomicBool::compare_exchange_weak`].
206     pub fn atomic_cxchgweak_relaxed_seqcst<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
207     /// Stores a value if the current value is the same as the `old` value.
208     ///
209     /// The stabilized version of this intrinsic is available on the
210     /// [`atomic`] types via the `compare_exchange_weak` method by passing
211     /// [`Ordering::Acquire`] and [`Ordering::Relaxed`] as the success and failure parameters.
212     /// For example, [`AtomicBool::compare_exchange_weak`].
213     pub fn atomic_cxchgweak_acquire_relaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
214     /// Stores a value if the current value is the same as the `old` value.
215     ///
216     /// The stabilized version of this intrinsic is available on the
217     /// [`atomic`] types via the `compare_exchange_weak` method by passing
218     /// [`Ordering::Acquire`] as both the success and failure parameters.
219     /// For example, [`AtomicBool::compare_exchange_weak`].
220     pub fn atomic_cxchgweak_acquire_acquire<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
221     /// Stores a value if the current value is the same as the `old` value.
222     ///
223     /// The stabilized version of this intrinsic is available on the
224     /// [`atomic`] types via the `compare_exchange_weak` method by passing
225     /// [`Ordering::Acquire`] and [`Ordering::SeqCst`] as the success and failure parameters.
226     /// For example, [`AtomicBool::compare_exchange_weak`].
227     pub fn atomic_cxchgweak_acquire_seqcst<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
228     /// Stores a value if the current value is the same as the `old` value.
229     ///
230     /// The stabilized version of this intrinsic is available on the
231     /// [`atomic`] types via the `compare_exchange_weak` method by passing
232     /// [`Ordering::Release`] and [`Ordering::Relaxed`] as the success and failure parameters.
233     /// For example, [`AtomicBool::compare_exchange_weak`].
234     pub fn atomic_cxchgweak_release_relaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
235     /// Stores a value if the current value is the same as the `old` value.
236     ///
237     /// The stabilized version of this intrinsic is available on the
238     /// [`atomic`] types via the `compare_exchange_weak` method by passing
239     /// [`Ordering::Release`] and [`Ordering::Acquire`] as the success and failure parameters.
240     /// For example, [`AtomicBool::compare_exchange_weak`].
241     pub fn atomic_cxchgweak_release_acquire<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
242     /// Stores a value if the current value is the same as the `old` value.
243     ///
244     /// The stabilized version of this intrinsic is available on the
245     /// [`atomic`] types via the `compare_exchange_weak` method by passing
246     /// [`Ordering::Release`] and [`Ordering::SeqCst`] as the success and failure parameters.
247     /// For example, [`AtomicBool::compare_exchange_weak`].
248     pub fn atomic_cxchgweak_release_seqcst<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
249     /// Stores a value if the current value is the same as the `old` value.
250     ///
251     /// The stabilized version of this intrinsic is available on the
252     /// [`atomic`] types via the `compare_exchange_weak` method by passing
253     /// [`Ordering::AcqRel`] and [`Ordering::Relaxed`] as the success and failure parameters.
254     /// For example, [`AtomicBool::compare_exchange_weak`].
255     pub fn atomic_cxchgweak_acqrel_relaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
256     /// Stores a value if the current value is the same as the `old` value.
257     ///
258     /// The stabilized version of this intrinsic is available on the
259     /// [`atomic`] types via the `compare_exchange_weak` method by passing
260     /// [`Ordering::AcqRel`] and [`Ordering::Acquire`] as the success and failure parameters.
261     /// For example, [`AtomicBool::compare_exchange_weak`].
262     pub fn atomic_cxchgweak_acqrel_acquire<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
263     /// Stores a value if the current value is the same as the `old` value.
264     ///
265     /// The stabilized version of this intrinsic is available on the
266     /// [`atomic`] types via the `compare_exchange_weak` method by passing
267     /// [`Ordering::AcqRel`] and [`Ordering::SeqCst`] as the success and failure parameters.
268     /// For example, [`AtomicBool::compare_exchange_weak`].
269     pub fn atomic_cxchgweak_acqrel_seqcst<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
270     /// Stores a value if the current value is the same as the `old` value.
271     ///
272     /// The stabilized version of this intrinsic is available on the
273     /// [`atomic`] types via the `compare_exchange_weak` method by passing
274     /// [`Ordering::SeqCst`] and [`Ordering::Relaxed`] as the success and failure parameters.
275     /// For example, [`AtomicBool::compare_exchange_weak`].
276     pub fn atomic_cxchgweak_seqcst_relaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
277     /// Stores a value if the current value is the same as the `old` value.
278     ///
279     /// The stabilized version of this intrinsic is available on the
280     /// [`atomic`] types via the `compare_exchange_weak` method by passing
281     /// [`Ordering::SeqCst`] and [`Ordering::Acquire`] as the success and failure parameters.
282     /// For example, [`AtomicBool::compare_exchange_weak`].
283     pub fn atomic_cxchgweak_seqcst_acquire<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
284     /// Stores a value if the current value is the same as the `old` value.
285     ///
286     /// The stabilized version of this intrinsic is available on the
287     /// [`atomic`] types via the `compare_exchange_weak` method by passing
288     /// [`Ordering::SeqCst`] as both the success and failure parameters.
289     /// For example, [`AtomicBool::compare_exchange_weak`].
290     pub fn atomic_cxchgweak_seqcst_seqcst<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
291
292     /// Loads the current value of the pointer.
293     ///
294     /// The stabilized version of this intrinsic is available on the
295     /// [`atomic`] types via the `load` method by passing
296     /// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicBool::load`].
297     pub fn atomic_load_seqcst<T: Copy>(src: *const T) -> T;
298     /// Loads the current value of the pointer.
299     ///
300     /// The stabilized version of this intrinsic is available on the
301     /// [`atomic`] types via the `load` method by passing
302     /// [`Ordering::Acquire`] as the `order`. For example, [`AtomicBool::load`].
303     pub fn atomic_load_acquire<T: Copy>(src: *const T) -> T;
304     /// Loads the current value of the pointer.
305     ///
306     /// The stabilized version of this intrinsic is available on the
307     /// [`atomic`] types via the `load` method by passing
308     /// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicBool::load`].
309     pub fn atomic_load_relaxed<T: Copy>(src: *const T) -> T;
310     pub fn atomic_load_unordered<T: Copy>(src: *const T) -> T;
311
312     /// Stores the value at the specified memory location.
313     ///
314     /// The stabilized version of this intrinsic is available on the
315     /// [`atomic`] types via the `store` method by passing
316     /// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicBool::store`].
317     pub fn atomic_store_seqcst<T: Copy>(dst: *mut T, val: T);
318     /// Stores the value at the specified memory location.
319     ///
320     /// The stabilized version of this intrinsic is available on the
321     /// [`atomic`] types via the `store` method by passing
322     /// [`Ordering::Release`] as the `order`. For example, [`AtomicBool::store`].
323     pub fn atomic_store_release<T: Copy>(dst: *mut T, val: T);
324     /// Stores the value at the specified memory location.
325     ///
326     /// The stabilized version of this intrinsic is available on the
327     /// [`atomic`] types via the `store` method by passing
328     /// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicBool::store`].
329     pub fn atomic_store_relaxed<T: Copy>(dst: *mut T, val: T);
330     pub fn atomic_store_unordered<T: Copy>(dst: *mut T, val: T);
331
332     /// Stores the value at the specified memory location, returning the old value.
333     ///
334     /// The stabilized version of this intrinsic is available on the
335     /// [`atomic`] types via the `swap` method by passing
336     /// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicBool::swap`].
337     pub fn atomic_xchg_seqcst<T: Copy>(dst: *mut T, src: T) -> T;
338     /// Stores the value at the specified memory location, returning the old value.
339     ///
340     /// The stabilized version of this intrinsic is available on the
341     /// [`atomic`] types via the `swap` method by passing
342     /// [`Ordering::Acquire`] as the `order`. For example, [`AtomicBool::swap`].
343     pub fn atomic_xchg_acquire<T: Copy>(dst: *mut T, src: T) -> T;
344     /// Stores the value at the specified memory location, returning the old value.
345     ///
346     /// The stabilized version of this intrinsic is available on the
347     /// [`atomic`] types via the `swap` method by passing
348     /// [`Ordering::Release`] as the `order`. For example, [`AtomicBool::swap`].
349     pub fn atomic_xchg_release<T: Copy>(dst: *mut T, src: T) -> T;
350     /// Stores the value at the specified memory location, returning the old value.
351     ///
352     /// The stabilized version of this intrinsic is available on the
353     /// [`atomic`] types via the `swap` method by passing
354     /// [`Ordering::AcqRel`] as the `order`. For example, [`AtomicBool::swap`].
355     pub fn atomic_xchg_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
356     /// Stores the value at the specified memory location, returning the old value.
357     ///
358     /// The stabilized version of this intrinsic is available on the
359     /// [`atomic`] types via the `swap` method by passing
360     /// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicBool::swap`].
361     pub fn atomic_xchg_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
362
363     /// Adds to the current value, returning the previous value.
364     ///
365     /// The stabilized version of this intrinsic is available on the
366     /// [`atomic`] types via the `fetch_add` method by passing
367     /// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicIsize::fetch_add`].
368     pub fn atomic_xadd_seqcst<T: Copy>(dst: *mut T, src: T) -> T;
369     /// Adds to the current value, returning the previous value.
370     ///
371     /// The stabilized version of this intrinsic is available on the
372     /// [`atomic`] types via the `fetch_add` method by passing
373     /// [`Ordering::Acquire`] as the `order`. For example, [`AtomicIsize::fetch_add`].
374     pub fn atomic_xadd_acquire<T: Copy>(dst: *mut T, src: T) -> T;
375     /// Adds to the current value, returning the previous value.
376     ///
377     /// The stabilized version of this intrinsic is available on the
378     /// [`atomic`] types via the `fetch_add` method by passing
379     /// [`Ordering::Release`] as the `order`. For example, [`AtomicIsize::fetch_add`].
380     pub fn atomic_xadd_release<T: Copy>(dst: *mut T, src: T) -> T;
381     /// Adds to the current value, returning the previous value.
382     ///
383     /// The stabilized version of this intrinsic is available on the
384     /// [`atomic`] types via the `fetch_add` method by passing
385     /// [`Ordering::AcqRel`] as the `order`. For example, [`AtomicIsize::fetch_add`].
386     pub fn atomic_xadd_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
387     /// Adds to the current value, returning the previous value.
388     ///
389     /// The stabilized version of this intrinsic is available on the
390     /// [`atomic`] types via the `fetch_add` method by passing
391     /// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicIsize::fetch_add`].
392     pub fn atomic_xadd_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
393
394     /// Subtract from the current value, returning the previous value.
395     ///
396     /// The stabilized version of this intrinsic is available on the
397     /// [`atomic`] types via the `fetch_sub` method by passing
398     /// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicIsize::fetch_sub`].
399     pub fn atomic_xsub_seqcst<T: Copy>(dst: *mut T, src: T) -> T;
400     /// Subtract from the current value, returning the previous value.
401     ///
402     /// The stabilized version of this intrinsic is available on the
403     /// [`atomic`] types via the `fetch_sub` method by passing
404     /// [`Ordering::Acquire`] as the `order`. For example, [`AtomicIsize::fetch_sub`].
405     pub fn atomic_xsub_acquire<T: Copy>(dst: *mut T, src: T) -> T;
406     /// Subtract from the current value, returning the previous value.
407     ///
408     /// The stabilized version of this intrinsic is available on the
409     /// [`atomic`] types via the `fetch_sub` method by passing
410     /// [`Ordering::Release`] as the `order`. For example, [`AtomicIsize::fetch_sub`].
411     pub fn atomic_xsub_release<T: Copy>(dst: *mut T, src: T) -> T;
412     /// Subtract from the current value, returning the previous value.
413     ///
414     /// The stabilized version of this intrinsic is available on the
415     /// [`atomic`] types via the `fetch_sub` method by passing
416     /// [`Ordering::AcqRel`] as the `order`. For example, [`AtomicIsize::fetch_sub`].
417     pub fn atomic_xsub_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
418     /// Subtract from the current value, returning the previous value.
419     ///
420     /// The stabilized version of this intrinsic is available on the
421     /// [`atomic`] types via the `fetch_sub` method by passing
422     /// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicIsize::fetch_sub`].
423     pub fn atomic_xsub_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
424
425     /// Bitwise and with the current value, returning the previous value.
426     ///
427     /// The stabilized version of this intrinsic is available on the
428     /// [`atomic`] types via the `fetch_and` method by passing
429     /// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicBool::fetch_and`].
430     pub fn atomic_and_seqcst<T: Copy>(dst: *mut T, src: T) -> T;
431     /// Bitwise and with the current value, returning the previous value.
432     ///
433     /// The stabilized version of this intrinsic is available on the
434     /// [`atomic`] types via the `fetch_and` method by passing
435     /// [`Ordering::Acquire`] as the `order`. For example, [`AtomicBool::fetch_and`].
436     pub fn atomic_and_acquire<T: Copy>(dst: *mut T, src: T) -> T;
437     /// Bitwise and with the current value, returning the previous value.
438     ///
439     /// The stabilized version of this intrinsic is available on the
440     /// [`atomic`] types via the `fetch_and` method by passing
441     /// [`Ordering::Release`] as the `order`. For example, [`AtomicBool::fetch_and`].
442     pub fn atomic_and_release<T: Copy>(dst: *mut T, src: T) -> T;
443     /// Bitwise and with the current value, returning the previous value.
444     ///
445     /// The stabilized version of this intrinsic is available on the
446     /// [`atomic`] types via the `fetch_and` method by passing
447     /// [`Ordering::AcqRel`] as the `order`. For example, [`AtomicBool::fetch_and`].
448     pub fn atomic_and_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
449     /// Bitwise and with the current value, returning the previous value.
450     ///
451     /// The stabilized version of this intrinsic is available on the
452     /// [`atomic`] types via the `fetch_and` method by passing
453     /// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicBool::fetch_and`].
454     pub fn atomic_and_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
455
456     /// Bitwise nand with the current value, returning the previous value.
457     ///
458     /// The stabilized version of this intrinsic is available on the
459     /// [`AtomicBool`] type via the `fetch_nand` method by passing
460     /// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicBool::fetch_nand`].
461     pub fn atomic_nand_seqcst<T: Copy>(dst: *mut T, src: T) -> T;
462     /// Bitwise nand with the current value, returning the previous value.
463     ///
464     /// The stabilized version of this intrinsic is available on the
465     /// [`AtomicBool`] type via the `fetch_nand` method by passing
466     /// [`Ordering::Acquire`] as the `order`. For example, [`AtomicBool::fetch_nand`].
467     pub fn atomic_nand_acquire<T: Copy>(dst: *mut T, src: T) -> T;
468     /// Bitwise nand with the current value, returning the previous value.
469     ///
470     /// The stabilized version of this intrinsic is available on the
471     /// [`AtomicBool`] type via the `fetch_nand` method by passing
472     /// [`Ordering::Release`] as the `order`. For example, [`AtomicBool::fetch_nand`].
473     pub fn atomic_nand_release<T: Copy>(dst: *mut T, src: T) -> T;
474     /// Bitwise nand with the current value, returning the previous value.
475     ///
476     /// The stabilized version of this intrinsic is available on the
477     /// [`AtomicBool`] type via the `fetch_nand` method by passing
478     /// [`Ordering::AcqRel`] as the `order`. For example, [`AtomicBool::fetch_nand`].
479     pub fn atomic_nand_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
480     /// Bitwise nand with the current value, returning the previous value.
481     ///
482     /// The stabilized version of this intrinsic is available on the
483     /// [`AtomicBool`] type via the `fetch_nand` method by passing
484     /// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicBool::fetch_nand`].
485     pub fn atomic_nand_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
486
487     /// Bitwise or with the current value, returning the previous value.
488     ///
489     /// The stabilized version of this intrinsic is available on the
490     /// [`atomic`] types via the `fetch_or` method by passing
491     /// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicBool::fetch_or`].
492     pub fn atomic_or_seqcst<T: Copy>(dst: *mut T, src: T) -> T;
493     /// Bitwise or with the current value, returning the previous value.
494     ///
495     /// The stabilized version of this intrinsic is available on the
496     /// [`atomic`] types via the `fetch_or` method by passing
497     /// [`Ordering::Acquire`] as the `order`. For example, [`AtomicBool::fetch_or`].
498     pub fn atomic_or_acquire<T: Copy>(dst: *mut T, src: T) -> T;
499     /// Bitwise or with the current value, returning the previous value.
500     ///
501     /// The stabilized version of this intrinsic is available on the
502     /// [`atomic`] types via the `fetch_or` method by passing
503     /// [`Ordering::Release`] as the `order`. For example, [`AtomicBool::fetch_or`].
504     pub fn atomic_or_release<T: Copy>(dst: *mut T, src: T) -> T;
505     /// Bitwise or with the current value, returning the previous value.
506     ///
507     /// The stabilized version of this intrinsic is available on the
508     /// [`atomic`] types via the `fetch_or` method by passing
509     /// [`Ordering::AcqRel`] as the `order`. For example, [`AtomicBool::fetch_or`].
510     pub fn atomic_or_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
511     /// Bitwise or with the current value, returning the previous value.
512     ///
513     /// The stabilized version of this intrinsic is available on the
514     /// [`atomic`] types via the `fetch_or` method by passing
515     /// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicBool::fetch_or`].
516     pub fn atomic_or_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
517
518     /// Bitwise xor with the current value, returning the previous value.
519     ///
520     /// The stabilized version of this intrinsic is available on the
521     /// [`atomic`] types via the `fetch_xor` method by passing
522     /// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicBool::fetch_xor`].
523     pub fn atomic_xor_seqcst<T: Copy>(dst: *mut T, src: T) -> T;
524     /// Bitwise xor with the current value, returning the previous value.
525     ///
526     /// The stabilized version of this intrinsic is available on the
527     /// [`atomic`] types via the `fetch_xor` method by passing
528     /// [`Ordering::Acquire`] as the `order`. For example, [`AtomicBool::fetch_xor`].
529     pub fn atomic_xor_acquire<T: Copy>(dst: *mut T, src: T) -> T;
530     /// Bitwise xor with the current value, returning the previous value.
531     ///
532     /// The stabilized version of this intrinsic is available on the
533     /// [`atomic`] types via the `fetch_xor` method by passing
534     /// [`Ordering::Release`] as the `order`. For example, [`AtomicBool::fetch_xor`].
535     pub fn atomic_xor_release<T: Copy>(dst: *mut T, src: T) -> T;
536     /// Bitwise xor with the current value, returning the previous value.
537     ///
538     /// The stabilized version of this intrinsic is available on the
539     /// [`atomic`] types via the `fetch_xor` method by passing
540     /// [`Ordering::AcqRel`] as the `order`. For example, [`AtomicBool::fetch_xor`].
541     pub fn atomic_xor_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
542     /// Bitwise xor with the current value, returning the previous value.
543     ///
544     /// The stabilized version of this intrinsic is available on the
545     /// [`atomic`] types via the `fetch_xor` method by passing
546     /// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicBool::fetch_xor`].
547     pub fn atomic_xor_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
548
549     /// Maximum with the current value using a signed comparison.
550     ///
551     /// The stabilized version of this intrinsic is available on the
552     /// [`atomic`] signed integer types via the `fetch_max` method by passing
553     /// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicI32::fetch_max`].
554     pub fn atomic_max_seqcst<T: Copy>(dst: *mut T, src: T) -> T;
555     /// Maximum with the current value using a signed comparison.
556     ///
557     /// The stabilized version of this intrinsic is available on the
558     /// [`atomic`] signed integer types via the `fetch_max` method by passing
559     /// [`Ordering::Acquire`] as the `order`. For example, [`AtomicI32::fetch_max`].
560     pub fn atomic_max_acquire<T: Copy>(dst: *mut T, src: T) -> T;
561     /// Maximum with the current value using a signed comparison.
562     ///
563     /// The stabilized version of this intrinsic is available on the
564     /// [`atomic`] signed integer types via the `fetch_max` method by passing
565     /// [`Ordering::Release`] as the `order`. For example, [`AtomicI32::fetch_max`].
566     pub fn atomic_max_release<T: Copy>(dst: *mut T, src: T) -> T;
567     /// Maximum with the current value using a signed comparison.
568     ///
569     /// The stabilized version of this intrinsic is available on the
570     /// [`atomic`] signed integer types via the `fetch_max` method by passing
571     /// [`Ordering::AcqRel`] as the `order`. For example, [`AtomicI32::fetch_max`].
572     pub fn atomic_max_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
573     /// Maximum with the current value.
574     ///
575     /// The stabilized version of this intrinsic is available on the
576     /// [`atomic`] signed integer types via the `fetch_max` method by passing
577     /// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicI32::fetch_max`].
578     pub fn atomic_max_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
579
580     /// Minimum with the current value using a signed comparison.
581     ///
582     /// The stabilized version of this intrinsic is available on the
583     /// [`atomic`] signed integer types via the `fetch_min` method by passing
584     /// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicI32::fetch_min`].
585     pub fn atomic_min_seqcst<T: Copy>(dst: *mut T, src: T) -> T;
586     /// Minimum with the current value using a signed comparison.
587     ///
588     /// The stabilized version of this intrinsic is available on the
589     /// [`atomic`] signed integer types via the `fetch_min` method by passing
590     /// [`Ordering::Acquire`] as the `order`. For example, [`AtomicI32::fetch_min`].
591     pub fn atomic_min_acquire<T: Copy>(dst: *mut T, src: T) -> T;
592     /// Minimum with the current value using a signed comparison.
593     ///
594     /// The stabilized version of this intrinsic is available on the
595     /// [`atomic`] signed integer types via the `fetch_min` method by passing
596     /// [`Ordering::Release`] as the `order`. For example, [`AtomicI32::fetch_min`].
597     pub fn atomic_min_release<T: Copy>(dst: *mut T, src: T) -> T;
598     /// Minimum with the current value using a signed comparison.
599     ///
600     /// The stabilized version of this intrinsic is available on the
601     /// [`atomic`] signed integer types via the `fetch_min` method by passing
602     /// [`Ordering::AcqRel`] as the `order`. For example, [`AtomicI32::fetch_min`].
603     pub fn atomic_min_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
604     /// Minimum with the current value using a signed comparison.
605     ///
606     /// The stabilized version of this intrinsic is available on the
607     /// [`atomic`] signed integer types via the `fetch_min` method by passing
608     /// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicI32::fetch_min`].
609     pub fn atomic_min_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
610
611     /// Minimum with the current value using an unsigned comparison.
612     ///
613     /// The stabilized version of this intrinsic is available on the
614     /// [`atomic`] unsigned integer types via the `fetch_min` method by passing
615     /// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicU32::fetch_min`].
616     pub fn atomic_umin_seqcst<T: Copy>(dst: *mut T, src: T) -> T;
617     /// Minimum with the current value using an unsigned comparison.
618     ///
619     /// The stabilized version of this intrinsic is available on the
620     /// [`atomic`] unsigned integer types via the `fetch_min` method by passing
621     /// [`Ordering::Acquire`] as the `order`. For example, [`AtomicU32::fetch_min`].
622     pub fn atomic_umin_acquire<T: Copy>(dst: *mut T, src: T) -> T;
623     /// Minimum with the current value using an unsigned comparison.
624     ///
625     /// The stabilized version of this intrinsic is available on the
626     /// [`atomic`] unsigned integer types via the `fetch_min` method by passing
627     /// [`Ordering::Release`] as the `order`. For example, [`AtomicU32::fetch_min`].
628     pub fn atomic_umin_release<T: Copy>(dst: *mut T, src: T) -> T;
629     /// Minimum with the current value using an unsigned comparison.
630     ///
631     /// The stabilized version of this intrinsic is available on the
632     /// [`atomic`] unsigned integer types via the `fetch_min` method by passing
633     /// [`Ordering::AcqRel`] as the `order`. For example, [`AtomicU32::fetch_min`].
634     pub fn atomic_umin_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
635     /// Minimum with the current value using an unsigned comparison.
636     ///
637     /// The stabilized version of this intrinsic is available on the
638     /// [`atomic`] unsigned integer types via the `fetch_min` method by passing
639     /// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicU32::fetch_min`].
640     pub fn atomic_umin_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
641
642     /// Maximum with the current value using an unsigned comparison.
643     ///
644     /// The stabilized version of this intrinsic is available on the
645     /// [`atomic`] unsigned integer types via the `fetch_max` method by passing
646     /// [`Ordering::SeqCst`] as the `order`. For example, [`AtomicU32::fetch_max`].
647     pub fn atomic_umax_seqcst<T: Copy>(dst: *mut T, src: T) -> T;
648     /// Maximum with the current value using an unsigned comparison.
649     ///
650     /// The stabilized version of this intrinsic is available on the
651     /// [`atomic`] unsigned integer types via the `fetch_max` method by passing
652     /// [`Ordering::Acquire`] as the `order`. For example, [`AtomicU32::fetch_max`].
653     pub fn atomic_umax_acquire<T: Copy>(dst: *mut T, src: T) -> T;
654     /// Maximum with the current value using an unsigned comparison.
655     ///
656     /// The stabilized version of this intrinsic is available on the
657     /// [`atomic`] unsigned integer types via the `fetch_max` method by passing
658     /// [`Ordering::Release`] as the `order`. For example, [`AtomicU32::fetch_max`].
659     pub fn atomic_umax_release<T: Copy>(dst: *mut T, src: T) -> T;
660     /// Maximum with the current value using an unsigned comparison.
661     ///
662     /// The stabilized version of this intrinsic is available on the
663     /// [`atomic`] unsigned integer types via the `fetch_max` method by passing
664     /// [`Ordering::AcqRel`] as the `order`. For example, [`AtomicU32::fetch_max`].
665     pub fn atomic_umax_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
666     /// Maximum with the current value using an unsigned comparison.
667     ///
668     /// The stabilized version of this intrinsic is available on the
669     /// [`atomic`] unsigned integer types via the `fetch_max` method by passing
670     /// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicU32::fetch_max`].
671     pub fn atomic_umax_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
672
673     /// An atomic fence.
674     ///
675     /// The stabilized version of this intrinsic is available in
676     /// [`atomic::fence`] by passing [`Ordering::SeqCst`]
677     /// as the `order`.
678     pub fn atomic_fence_seqcst();
679     /// An atomic fence.
680     ///
681     /// The stabilized version of this intrinsic is available in
682     /// [`atomic::fence`] by passing [`Ordering::Acquire`]
683     /// as the `order`.
684     pub fn atomic_fence_acquire();
685     /// An atomic fence.
686     ///
687     /// The stabilized version of this intrinsic is available in
688     /// [`atomic::fence`] by passing [`Ordering::Release`]
689     /// as the `order`.
690     pub fn atomic_fence_release();
691     /// An atomic fence.
692     ///
693     /// The stabilized version of this intrinsic is available in
694     /// [`atomic::fence`] by passing [`Ordering::AcqRel`]
695     /// as the `order`.
696     pub fn atomic_fence_acqrel();
697
698     /// A compiler-only memory barrier.
699     ///
700     /// Memory accesses will never be reordered across this barrier by the
701     /// compiler, but no instructions will be emitted for it. This is
702     /// appropriate for operations on the same thread that may be preempted,
703     /// such as when interacting with signal handlers.
704     ///
705     /// The stabilized version of this intrinsic is available in
706     /// [`atomic::compiler_fence`] by passing [`Ordering::SeqCst`]
707     /// as the `order`.
708     pub fn atomic_singlethreadfence_seqcst();
709     /// A compiler-only memory barrier.
710     ///
711     /// Memory accesses will never be reordered across this barrier by the
712     /// compiler, but no instructions will be emitted for it. This is
713     /// appropriate for operations on the same thread that may be preempted,
714     /// such as when interacting with signal handlers.
715     ///
716     /// The stabilized version of this intrinsic is available in
717     /// [`atomic::compiler_fence`] by passing [`Ordering::Acquire`]
718     /// as the `order`.
719     pub fn atomic_singlethreadfence_acquire();
720     /// A compiler-only memory barrier.
721     ///
722     /// Memory accesses will never be reordered across this barrier by the
723     /// compiler, but no instructions will be emitted for it. This is
724     /// appropriate for operations on the same thread that may be preempted,
725     /// such as when interacting with signal handlers.
726     ///
727     /// The stabilized version of this intrinsic is available in
728     /// [`atomic::compiler_fence`] by passing [`Ordering::Release`]
729     /// as the `order`.
730     pub fn atomic_singlethreadfence_release();
731     /// A compiler-only memory barrier.
732     ///
733     /// Memory accesses will never be reordered across this barrier by the
734     /// compiler, but no instructions will be emitted for it. This is
735     /// appropriate for operations on the same thread that may be preempted,
736     /// such as when interacting with signal handlers.
737     ///
738     /// The stabilized version of this intrinsic is available in
739     /// [`atomic::compiler_fence`] by passing [`Ordering::AcqRel`]
740     /// as the `order`.
741     pub fn atomic_singlethreadfence_acqrel();
742
743     /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
744     /// if supported; otherwise, it is a no-op.
745     /// Prefetches have no effect on the behavior of the program but can change its performance
746     /// characteristics.
747     ///
748     /// The `locality` argument must be a constant integer and is a temporal locality specifier
749     /// ranging from (0) - no locality, to (3) - extremely local keep in cache.
750     ///
751     /// This intrinsic does not have a stable counterpart.
752     pub fn prefetch_read_data<T>(data: *const T, locality: i32);
753     /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
754     /// if supported; otherwise, it is a no-op.
755     /// Prefetches have no effect on the behavior of the program but can change its performance
756     /// characteristics.
757     ///
758     /// The `locality` argument must be a constant integer and is a temporal locality specifier
759     /// ranging from (0) - no locality, to (3) - extremely local keep in cache.
760     ///
761     /// This intrinsic does not have a stable counterpart.
762     pub fn prefetch_write_data<T>(data: *const T, locality: i32);
763     /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
764     /// if supported; otherwise, it is a no-op.
765     /// Prefetches have no effect on the behavior of the program but can change its performance
766     /// characteristics.
767     ///
768     /// The `locality` argument must be a constant integer and is a temporal locality specifier
769     /// ranging from (0) - no locality, to (3) - extremely local keep in cache.
770     ///
771     /// This intrinsic does not have a stable counterpart.
772     pub fn prefetch_read_instruction<T>(data: *const T, locality: i32);
773     /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
774     /// if supported; otherwise, it is a no-op.
775     /// Prefetches have no effect on the behavior of the program but can change its performance
776     /// characteristics.
777     ///
778     /// The `locality` argument must be a constant integer and is a temporal locality specifier
779     /// ranging from (0) - no locality, to (3) - extremely local keep in cache.
780     ///
781     /// This intrinsic does not have a stable counterpart.
782     pub fn prefetch_write_instruction<T>(data: *const T, locality: i32);
783
784     /// Magic intrinsic that derives its meaning from attributes
785     /// attached to the function.
786     ///
787     /// For example, dataflow uses this to inject static assertions so
788     /// that `rustc_peek(potentially_uninitialized)` would actually
789     /// double-check that dataflow did indeed compute that it is
790     /// uninitialized at that point in the control flow.
791     ///
792     /// This intrinsic should not be used outside of the compiler.
793     pub fn rustc_peek<T>(_: T) -> T;
794
795     /// Aborts the execution of the process.
796     ///
797     /// Note that, unlike most intrinsics, this is safe to call;
798     /// it does not require an `unsafe` block.
799     /// Therefore, implementations must not require the user to uphold
800     /// any safety invariants.
801     ///
802     /// [`std::process::abort`](../../std/process/fn.abort.html) is to be preferred if possible,
803     /// as its behavior is more user-friendly and more stable.
804     ///
805     /// The current implementation of `intrinsics::abort` is to invoke an invalid instruction,
806     /// on most platforms.
807     /// On Unix, the
808     /// process will probably terminate with a signal like `SIGABRT`, `SIGILL`, `SIGTRAP`, `SIGSEGV` or
809     /// `SIGBUS`.  The precise behaviour is not guaranteed and not stable.
810     pub fn abort() -> !;
811
812     /// Informs the optimizer that this point in the code is not reachable,
813     /// enabling further optimizations.
814     ///
815     /// N.B., this is very different from the `unreachable!()` macro: Unlike the
816     /// macro, which panics when it is executed, it is *undefined behavior* to
817     /// reach code marked with this function.
818     ///
819     /// The stabilized version of this intrinsic is [`core::hint::unreachable_unchecked`].
820     #[rustc_const_stable(feature = "const_unreachable_unchecked", since = "1.57.0")]
821     pub fn unreachable() -> !;
822
823     /// Informs the optimizer that a condition is always true.
824     /// If the condition is false, the behavior is undefined.
825     ///
826     /// No code is generated for this intrinsic, but the optimizer will try
827     /// to preserve it (and its condition) between passes, which may interfere
828     /// with optimization of surrounding code and reduce performance. It should
829     /// not be used if the invariant can be discovered by the optimizer on its
830     /// own, or if it does not enable any significant optimizations.
831     ///
832     /// This intrinsic does not have a stable counterpart.
833     #[rustc_const_unstable(feature = "const_assume", issue = "76972")]
834     pub fn assume(b: bool);
835
836     /// Hints to the compiler that branch condition is likely to be true.
837     /// Returns the value passed to it.
838     ///
839     /// Any use other than with `if` statements will probably not have an effect.
840     ///
841     /// Note that, unlike most intrinsics, this is safe to call;
842     /// it does not require an `unsafe` block.
843     /// Therefore, implementations must not require the user to uphold
844     /// any safety invariants.
845     ///
846     /// This intrinsic does not have a stable counterpart.
847     #[rustc_const_unstable(feature = "const_likely", issue = "none")]
848     pub fn likely(b: bool) -> bool;
849
850     /// Hints to the compiler that branch condition is likely to be false.
851     /// Returns the value passed to it.
852     ///
853     /// Any use other than with `if` statements will probably not have an effect.
854     ///
855     /// Note that, unlike most intrinsics, this is safe to call;
856     /// it does not require an `unsafe` block.
857     /// Therefore, implementations must not require the user to uphold
858     /// any safety invariants.
859     ///
860     /// This intrinsic does not have a stable counterpart.
861     #[rustc_const_unstable(feature = "const_likely", issue = "none")]
862     pub fn unlikely(b: bool) -> bool;
863
864     /// Executes a breakpoint trap, for inspection by a debugger.
865     ///
866     /// This intrinsic does not have a stable counterpart.
867     pub fn breakpoint();
868
869     /// The size of a type in bytes.
870     ///
871     /// Note that, unlike most intrinsics, this is safe to call;
872     /// it does not require an `unsafe` block.
873     /// Therefore, implementations must not require the user to uphold
874     /// any safety invariants.
875     ///
876     /// More specifically, this is the offset in bytes between successive
877     /// items of the same type, including alignment padding.
878     ///
879     /// The stabilized version of this intrinsic is [`core::mem::size_of`].
880     #[rustc_const_stable(feature = "const_size_of", since = "1.40.0")]
881     pub fn size_of<T>() -> usize;
882
883     /// The minimum alignment of a type.
884     ///
885     /// Note that, unlike most intrinsics, this is safe to call;
886     /// it does not require an `unsafe` block.
887     /// Therefore, implementations must not require the user to uphold
888     /// any safety invariants.
889     ///
890     /// The stabilized version of this intrinsic is [`core::mem::align_of`].
891     #[rustc_const_stable(feature = "const_min_align_of", since = "1.40.0")]
892     pub fn min_align_of<T>() -> usize;
893     /// The preferred alignment of a type.
894     ///
895     /// This intrinsic does not have a stable counterpart.
896     /// It's "tracking issue" is [#91971](https://github.com/rust-lang/rust/issues/91971).
897     #[rustc_const_unstable(feature = "const_pref_align_of", issue = "91971")]
898     pub fn pref_align_of<T>() -> usize;
899
900     /// The size of the referenced value in bytes.
901     ///
902     /// The stabilized version of this intrinsic is [`mem::size_of_val`].
903     #[rustc_const_unstable(feature = "const_size_of_val", issue = "46571")]
904     pub fn size_of_val<T: ?Sized>(_: *const T) -> usize;
905     /// The required alignment of the referenced value.
906     ///
907     /// The stabilized version of this intrinsic is [`core::mem::align_of_val`].
908     #[rustc_const_unstable(feature = "const_align_of_val", issue = "46571")]
909     pub fn min_align_of_val<T: ?Sized>(_: *const T) -> usize;
910
911     /// Gets a static string slice containing the name of a type.
912     ///
913     /// Note that, unlike most intrinsics, this is safe to call;
914     /// it does not require an `unsafe` block.
915     /// Therefore, implementations must not require the user to uphold
916     /// any safety invariants.
917     ///
918     /// The stabilized version of this intrinsic is [`core::any::type_name`].
919     #[rustc_const_unstable(feature = "const_type_name", issue = "63084")]
920     pub fn type_name<T: ?Sized>() -> &'static str;
921
922     /// Gets an identifier which is globally unique to the specified type. This
923     /// function will return the same value for a type regardless of whichever
924     /// crate it is invoked in.
925     ///
926     /// Note that, unlike most intrinsics, this is safe to call;
927     /// it does not require an `unsafe` block.
928     /// Therefore, implementations must not require the user to uphold
929     /// any safety invariants.
930     ///
931     /// The stabilized version of this intrinsic is [`core::any::TypeId::of`].
932     #[rustc_const_unstable(feature = "const_type_id", issue = "77125")]
933     pub fn type_id<T: ?Sized + 'static>() -> u64;
934
935     /// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited:
936     /// This will statically either panic, or do nothing.
937     ///
938     /// This intrinsic does not have a stable counterpart.
939     #[rustc_const_stable(feature = "const_assert_type", since = "1.59.0")]
940     pub fn assert_inhabited<T>();
941
942     /// A guard for unsafe functions that cannot ever be executed if `T` does not permit
943     /// zero-initialization: This will statically either panic, or do nothing.
944     ///
945     /// This intrinsic does not have a stable counterpart.
946     #[rustc_const_unstable(feature = "const_assert_type2", issue = "none")]
947     pub fn assert_zero_valid<T>();
948
949     /// A guard for unsafe functions that cannot ever be executed if `T` has invalid
950     /// bit patterns: This will statically either panic, or do nothing.
951     ///
952     /// This intrinsic does not have a stable counterpart.
953     #[rustc_const_unstable(feature = "const_assert_type2", issue = "none")]
954     pub fn assert_uninit_valid<T>();
955
956     /// Gets a reference to a static `Location` indicating where it was called.
957     ///
958     /// Note that, unlike most intrinsics, this is safe to call;
959     /// it does not require an `unsafe` block.
960     /// Therefore, implementations must not require the user to uphold
961     /// any safety invariants.
962     ///
963     /// Consider using [`core::panic::Location::caller`] instead.
964     #[rustc_const_unstable(feature = "const_caller_location", issue = "76156")]
965     pub fn caller_location() -> &'static crate::panic::Location<'static>;
966
967     /// Moves a value out of scope without running drop glue.
968     ///
969     /// This exists solely for [`mem::forget_unsized`]; normal `forget` uses
970     /// `ManuallyDrop` instead.
971     ///
972     /// Note that, unlike most intrinsics, this is safe to call;
973     /// it does not require an `unsafe` block.
974     /// Therefore, implementations must not require the user to uphold
975     /// any safety invariants.
976     #[rustc_const_unstable(feature = "const_intrinsic_forget", issue = "none")]
977     pub fn forget<T: ?Sized>(_: T);
978
979     /// Reinterprets the bits of a value of one type as another type.
980     ///
981     /// Both types must have the same size. Compilation will fail if this is not guaranteed.
982     ///
983     /// `transmute` is semantically equivalent to a bitwise move of one type
984     /// into another. It copies the bits from the source value into the
985     /// destination value, then forgets the original. Note that source and destination
986     /// are passed by-value, which means if `T` or `U` contain padding, that padding
987     /// is *not* guaranteed to be preserved by `transmute`.
988     ///
989     /// Both the argument and the result must be [valid](../../nomicon/what-unsafe-does.html) at
990     /// their given type. Violating this condition leads to [undefined behavior][ub]. The compiler
991     /// will generate code *assuming that you, the programmer, ensure that there will never be
992     /// undefined behavior*. It is therefore your responsibility to guarantee that every value
993     /// passed to `transmute` is valid at both types `T` and `U`. Failing to uphold this condition
994     /// may lead to unexpected and unstable compilation results. This makes `transmute` **incredibly
995     /// unsafe**. `transmute` should be the absolute last resort.
996     ///
997     /// Transmuting pointers to integers in a `const` context is [undefined behavior][ub].
998     /// Any attempt to use the resulting value for integer operations will abort const-evaluation.
999     /// (And even outside `const`, such transmutation is touching on many unspecified aspects of the
1000     /// Rust memory model and should be avoided. See below for alternatives.)
1001     ///
1002     /// Because `transmute` is a by-value operation, alignment of the *transmuted values
1003     /// themselves* is not a concern. As with any other function, the compiler already ensures
1004     /// both `T` and `U` are properly aligned. However, when transmuting values that *point
1005     /// elsewhere* (such as pointers, references, boxes…), the caller has to ensure proper
1006     /// alignment of the pointed-to values.
1007     ///
1008     /// The [nomicon](../../nomicon/transmutes.html) has additional documentation.
1009     ///
1010     /// [ub]: ../../reference/behavior-considered-undefined.html
1011     ///
1012     /// # Examples
1013     ///
1014     /// There are a few things that `transmute` is really useful for.
1015     ///
1016     /// Turning a pointer into a function pointer. This is *not* portable to
1017     /// machines where function pointers and data pointers have different sizes.
1018     ///
1019     /// ```
1020     /// fn foo() -> i32 {
1021     ///     0
1022     /// }
1023     /// // Crucially, we `as`-cast to a raw pointer before `transmute`ing to a function pointer.
1024     /// // This avoids an integer-to-pointer `transmute`, which can be problematic.
1025     /// // Transmuting between raw pointers and function pointers (i.e., two pointer types) is fine.
1026     /// let pointer = foo as *const ();
1027     /// let function = unsafe {
1028     ///     std::mem::transmute::<*const (), fn() -> i32>(pointer)
1029     /// };
1030     /// assert_eq!(function(), 0);
1031     /// ```
1032     ///
1033     /// Extending a lifetime, or shortening an invariant lifetime. This is
1034     /// advanced, very unsafe Rust!
1035     ///
1036     /// ```
1037     /// struct R<'a>(&'a i32);
1038     /// unsafe fn extend_lifetime<'b>(r: R<'b>) -> R<'static> {
1039     ///     std::mem::transmute::<R<'b>, R<'static>>(r)
1040     /// }
1041     ///
1042     /// unsafe fn shorten_invariant_lifetime<'b, 'c>(r: &'b mut R<'static>)
1043     ///                                              -> &'b mut R<'c> {
1044     ///     std::mem::transmute::<&'b mut R<'static>, &'b mut R<'c>>(r)
1045     /// }
1046     /// ```
1047     ///
1048     /// # Alternatives
1049     ///
1050     /// Don't despair: many uses of `transmute` can be achieved through other means.
1051     /// Below are common applications of `transmute` which can be replaced with safer
1052     /// constructs.
1053     ///
1054     /// Turning raw bytes (`&[u8]`) into `u32`, `f64`, etc.:
1055     ///
1056     /// ```
1057     /// let raw_bytes = [0x78, 0x56, 0x34, 0x12];
1058     ///
1059     /// let num = unsafe {
1060     ///     std::mem::transmute::<[u8; 4], u32>(raw_bytes)
1061     /// };
1062     ///
1063     /// // use `u32::from_ne_bytes` instead
1064     /// let num = u32::from_ne_bytes(raw_bytes);
1065     /// // or use `u32::from_le_bytes` or `u32::from_be_bytes` to specify the endianness
1066     /// let num = u32::from_le_bytes(raw_bytes);
1067     /// assert_eq!(num, 0x12345678);
1068     /// let num = u32::from_be_bytes(raw_bytes);
1069     /// assert_eq!(num, 0x78563412);
1070     /// ```
1071     ///
1072     /// Turning a pointer into a `usize`:
1073     ///
1074     /// ```no_run
1075     /// let ptr = &0;
1076     /// let ptr_num_transmute = unsafe {
1077     ///     std::mem::transmute::<&i32, usize>(ptr)
1078     /// };
1079     ///
1080     /// // Use an `as` cast instead
1081     /// let ptr_num_cast = ptr as *const i32 as usize;
1082     /// ```
1083     ///
1084     /// Note that using `transmute` to turn a pointer to a `usize` is (as noted above) [undefined
1085     /// behavior][ub] in `const` contexts. Also outside of consts, this operation might not behave
1086     /// as expected -- this is touching on many unspecified aspects of the Rust memory model.
1087     /// Depending on what the code is doing, the following alternatives are preferable to
1088     /// pointer-to-integer transmutation:
1089     /// - If the code just wants to store data of arbitrary type in some buffer and needs to pick a
1090     ///   type for that buffer, it can use [`MaybeUninit`][mem::MaybeUninit].
1091     /// - If the code actually wants to work on the address the pointer points to, it can use `as`
1092     ///   casts or [`ptr.addr()`][pointer::addr].
1093     ///
1094     /// Turning a `*mut T` into an `&mut T`:
1095     ///
1096     /// ```
1097     /// let ptr: *mut i32 = &mut 0;
1098     /// let ref_transmuted = unsafe {
1099     ///     std::mem::transmute::<*mut i32, &mut i32>(ptr)
1100     /// };
1101     ///
1102     /// // Use a reborrow instead
1103     /// let ref_casted = unsafe { &mut *ptr };
1104     /// ```
1105     ///
1106     /// Turning an `&mut T` into an `&mut U`:
1107     ///
1108     /// ```
1109     /// let ptr = &mut 0;
1110     /// let val_transmuted = unsafe {
1111     ///     std::mem::transmute::<&mut i32, &mut u32>(ptr)
1112     /// };
1113     ///
1114     /// // Now, put together `as` and reborrowing - note the chaining of `as`
1115     /// // `as` is not transitive
1116     /// let val_casts = unsafe { &mut *(ptr as *mut i32 as *mut u32) };
1117     /// ```
1118     ///
1119     /// Turning an `&str` into a `&[u8]`:
1120     ///
1121     /// ```
1122     /// // this is not a good way to do this.
1123     /// let slice = unsafe { std::mem::transmute::<&str, &[u8]>("Rust") };
1124     /// assert_eq!(slice, &[82, 117, 115, 116]);
1125     ///
1126     /// // You could use `str::as_bytes`
1127     /// let slice = "Rust".as_bytes();
1128     /// assert_eq!(slice, &[82, 117, 115, 116]);
1129     ///
1130     /// // Or, just use a byte string, if you have control over the string
1131     /// // literal
1132     /// assert_eq!(b"Rust", &[82, 117, 115, 116]);
1133     /// ```
1134     ///
1135     /// Turning a `Vec<&T>` into a `Vec<Option<&T>>`.
1136     ///
1137     /// To transmute the inner type of the contents of a container, you must make sure to not
1138     /// violate any of the container's invariants. For `Vec`, this means that both the size
1139     /// *and alignment* of the inner types have to match. Other containers might rely on the
1140     /// size of the type, alignment, or even the `TypeId`, in which case transmuting wouldn't
1141     /// be possible at all without violating the container invariants.
1142     ///
1143     /// ```
1144     /// let store = [0, 1, 2, 3];
1145     /// let v_orig = store.iter().collect::<Vec<&i32>>();
1146     ///
1147     /// // clone the vector as we will reuse them later
1148     /// let v_clone = v_orig.clone();
1149     ///
1150     /// // Using transmute: this relies on the unspecified data layout of `Vec`, which is a
1151     /// // bad idea and could cause Undefined Behavior.
1152     /// // However, it is no-copy.
1153     /// let v_transmuted = unsafe {
1154     ///     std::mem::transmute::<Vec<&i32>, Vec<Option<&i32>>>(v_clone)
1155     /// };
1156     ///
1157     /// let v_clone = v_orig.clone();
1158     ///
1159     /// // This is the suggested, safe way.
1160     /// // It does copy the entire vector, though, into a new array.
1161     /// let v_collected = v_clone.into_iter()
1162     ///                          .map(Some)
1163     ///                          .collect::<Vec<Option<&i32>>>();
1164     ///
1165     /// let v_clone = v_orig.clone();
1166     ///
1167     /// // This is the proper no-copy, unsafe way of "transmuting" a `Vec`, without relying on the
1168     /// // data layout. Instead of literally calling `transmute`, we perform a pointer cast, but
1169     /// // in terms of converting the original inner type (`&i32`) to the new one (`Option<&i32>`),
1170     /// // this has all the same caveats. Besides the information provided above, also consult the
1171     /// // [`from_raw_parts`] documentation.
1172     /// let v_from_raw = unsafe {
1173     // FIXME Update this when vec_into_raw_parts is stabilized
1174     ///     // Ensure the original vector is not dropped.
1175     ///     let mut v_clone = std::mem::ManuallyDrop::new(v_clone);
1176     ///     Vec::from_raw_parts(v_clone.as_mut_ptr() as *mut Option<&i32>,
1177     ///                         v_clone.len(),
1178     ///                         v_clone.capacity())
1179     /// };
1180     /// ```
1181     ///
1182     /// [`from_raw_parts`]: ../../std/vec/struct.Vec.html#method.from_raw_parts
1183     ///
1184     /// Implementing `split_at_mut`:
1185     ///
1186     /// ```
1187     /// use std::{slice, mem};
1188     ///
1189     /// // There are multiple ways to do this, and there are multiple problems
1190     /// // with the following (transmute) way.
1191     /// fn split_at_mut_transmute<T>(slice: &mut [T], mid: usize)
1192     ///                              -> (&mut [T], &mut [T]) {
1193     ///     let len = slice.len();
1194     ///     assert!(mid <= len);
1195     ///     unsafe {
1196     ///         let slice2 = mem::transmute::<&mut [T], &mut [T]>(slice);
1197     ///         // first: transmute is not type safe; all it checks is that T and
1198     ///         // U are of the same size. Second, right here, you have two
1199     ///         // mutable references pointing to the same memory.
1200     ///         (&mut slice[0..mid], &mut slice2[mid..len])
1201     ///     }
1202     /// }
1203     ///
1204     /// // This gets rid of the type safety problems; `&mut *` will *only* give
1205     /// // you an `&mut T` from an `&mut T` or `*mut T`.
1206     /// fn split_at_mut_casts<T>(slice: &mut [T], mid: usize)
1207     ///                          -> (&mut [T], &mut [T]) {
1208     ///     let len = slice.len();
1209     ///     assert!(mid <= len);
1210     ///     unsafe {
1211     ///         let slice2 = &mut *(slice as *mut [T]);
1212     ///         // however, you still have two mutable references pointing to
1213     ///         // the same memory.
1214     ///         (&mut slice[0..mid], &mut slice2[mid..len])
1215     ///     }
1216     /// }
1217     ///
1218     /// // This is how the standard library does it. This is the best method, if
1219     /// // you need to do something like this
1220     /// fn split_at_stdlib<T>(slice: &mut [T], mid: usize)
1221     ///                       -> (&mut [T], &mut [T]) {
1222     ///     let len = slice.len();
1223     ///     assert!(mid <= len);
1224     ///     unsafe {
1225     ///         let ptr = slice.as_mut_ptr();
1226     ///         // This now has three mutable references pointing at the same
1227     ///         // memory. `slice`, the rvalue ret.0, and the rvalue ret.1.
1228     ///         // `slice` is never used after `let ptr = ...`, and so one can
1229     ///         // treat it as "dead", and therefore, you only have two real
1230     ///         // mutable slices.
1231     ///         (slice::from_raw_parts_mut(ptr, mid),
1232     ///          slice::from_raw_parts_mut(ptr.add(mid), len - mid))
1233     ///     }
1234     /// }
1235     /// ```
1236     #[stable(feature = "rust1", since = "1.0.0")]
1237     #[rustc_allowed_through_unstable_modules]
1238     #[rustc_const_stable(feature = "const_transmute", since = "1.56.0")]
1239     #[rustc_diagnostic_item = "transmute"]
1240     pub fn transmute<T, U>(e: T) -> U;
1241
1242     /// Returns `true` if the actual type given as `T` requires drop
1243     /// glue; returns `false` if the actual type provided for `T`
1244     /// implements `Copy`.
1245     ///
1246     /// If the actual type neither requires drop glue nor implements
1247     /// `Copy`, then the return value of this function is unspecified.
1248     ///
1249     /// Note that, unlike most intrinsics, this is safe to call;
1250     /// it does not require an `unsafe` block.
1251     /// Therefore, implementations must not require the user to uphold
1252     /// any safety invariants.
1253     ///
1254     /// The stabilized version of this intrinsic is [`mem::needs_drop`](crate::mem::needs_drop).
1255     #[rustc_const_stable(feature = "const_needs_drop", since = "1.40.0")]
1256     pub fn needs_drop<T: ?Sized>() -> bool;
1257
1258     /// Calculates the offset from a pointer.
1259     ///
1260     /// This is implemented as an intrinsic to avoid converting to and from an
1261     /// integer, since the conversion would throw away aliasing information.
1262     ///
1263     /// # Safety
1264     ///
1265     /// Both the starting and resulting pointer must be either in bounds or one
1266     /// byte past the end of an allocated object. If either pointer is out of
1267     /// bounds or arithmetic overflow occurs then any further use of the
1268     /// returned value will result in undefined behavior.
1269     ///
1270     /// The stabilized version of this intrinsic is [`pointer::offset`].
1271     #[must_use = "returns a new pointer rather than modifying its argument"]
1272     #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
1273     pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
1274
1275     /// Calculates the offset from a pointer, potentially wrapping.
1276     ///
1277     /// This is implemented as an intrinsic to avoid converting to and from an
1278     /// integer, since the conversion inhibits certain optimizations.
1279     ///
1280     /// # Safety
1281     ///
1282     /// Unlike the `offset` intrinsic, this intrinsic does not restrict the
1283     /// resulting pointer to point into or one byte past the end of an allocated
1284     /// object, and it wraps with two's complement arithmetic. The resulting
1285     /// value is not necessarily valid to be used to actually access memory.
1286     ///
1287     /// The stabilized version of this intrinsic is [`pointer::wrapping_offset`].
1288     #[must_use = "returns a new pointer rather than modifying its argument"]
1289     #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
1290     pub fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
1291
1292     /// Masks out bits of the pointer according to a mask.
1293     ///
1294     /// Note that, unlike most intrinsics, this is safe to call;
1295     /// it does not require an `unsafe` block.
1296     /// Therefore, implementations must not require the user to uphold
1297     /// any safety invariants.
1298     ///
1299     /// Consider using [`pointer::mask`] instead.
1300     #[cfg(not(bootstrap))]
1301     pub fn ptr_mask<T>(ptr: *const T, mask: usize) -> *const T;
1302
1303     /// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with
1304     /// a size of `count` * `size_of::<T>()` and an alignment of
1305     /// `min_align_of::<T>()`
1306     ///
1307     /// The volatile parameter is set to `true`, so it will not be optimized out
1308     /// unless size is equal to zero.
1309     ///
1310     /// This intrinsic does not have a stable counterpart.
1311     pub fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: usize);
1312     /// Equivalent to the appropriate `llvm.memmove.p0i8.0i8.*` intrinsic, with
1313     /// a size of `count * size_of::<T>()` and an alignment of
1314     /// `min_align_of::<T>()`
1315     ///
1316     /// The volatile parameter is set to `true`, so it will not be optimized out
1317     /// unless size is equal to zero.
1318     ///
1319     /// This intrinsic does not have a stable counterpart.
1320     pub fn volatile_copy_memory<T>(dst: *mut T, src: *const T, count: usize);
1321     /// Equivalent to the appropriate `llvm.memset.p0i8.*` intrinsic, with a
1322     /// size of `count * size_of::<T>()` and an alignment of
1323     /// `min_align_of::<T>()`.
1324     ///
1325     /// The volatile parameter is set to `true`, so it will not be optimized out
1326     /// unless size is equal to zero.
1327     ///
1328     /// This intrinsic does not have a stable counterpart.
1329     pub fn volatile_set_memory<T>(dst: *mut T, val: u8, count: usize);
1330
1331     /// Performs a volatile load from the `src` pointer.
1332     ///
1333     /// The stabilized version of this intrinsic is [`core::ptr::read_volatile`].
1334     pub fn volatile_load<T>(src: *const T) -> T;
1335     /// Performs a volatile store to the `dst` pointer.
1336     ///
1337     /// The stabilized version of this intrinsic is [`core::ptr::write_volatile`].
1338     pub fn volatile_store<T>(dst: *mut T, val: T);
1339
1340     /// Performs a volatile load from the `src` pointer
1341     /// The pointer is not required to be aligned.
1342     ///
1343     /// This intrinsic does not have a stable counterpart.
1344     pub fn unaligned_volatile_load<T>(src: *const T) -> T;
1345     /// Performs a volatile store to the `dst` pointer.
1346     /// The pointer is not required to be aligned.
1347     ///
1348     /// This intrinsic does not have a stable counterpart.
1349     pub fn unaligned_volatile_store<T>(dst: *mut T, val: T);
1350
1351     /// Returns the square root of an `f32`
1352     ///
1353     /// The stabilized version of this intrinsic is
1354     /// [`f32::sqrt`](../../std/primitive.f32.html#method.sqrt)
1355     pub fn sqrtf32(x: f32) -> f32;
1356     /// Returns the square root of an `f64`
1357     ///
1358     /// The stabilized version of this intrinsic is
1359     /// [`f64::sqrt`](../../std/primitive.f64.html#method.sqrt)
1360     pub fn sqrtf64(x: f64) -> f64;
1361
1362     /// Raises an `f32` to an integer power.
1363     ///
1364     /// The stabilized version of this intrinsic is
1365     /// [`f32::powi`](../../std/primitive.f32.html#method.powi)
1366     pub fn powif32(a: f32, x: i32) -> f32;
1367     /// Raises an `f64` to an integer power.
1368     ///
1369     /// The stabilized version of this intrinsic is
1370     /// [`f64::powi`](../../std/primitive.f64.html#method.powi)
1371     pub fn powif64(a: f64, x: i32) -> f64;
1372
1373     /// Returns the sine of an `f32`.
1374     ///
1375     /// The stabilized version of this intrinsic is
1376     /// [`f32::sin`](../../std/primitive.f32.html#method.sin)
1377     pub fn sinf32(x: f32) -> f32;
1378     /// Returns the sine of an `f64`.
1379     ///
1380     /// The stabilized version of this intrinsic is
1381     /// [`f64::sin`](../../std/primitive.f64.html#method.sin)
1382     pub fn sinf64(x: f64) -> f64;
1383
1384     /// Returns the cosine of an `f32`.
1385     ///
1386     /// The stabilized version of this intrinsic is
1387     /// [`f32::cos`](../../std/primitive.f32.html#method.cos)
1388     pub fn cosf32(x: f32) -> f32;
1389     /// Returns the cosine of an `f64`.
1390     ///
1391     /// The stabilized version of this intrinsic is
1392     /// [`f64::cos`](../../std/primitive.f64.html#method.cos)
1393     pub fn cosf64(x: f64) -> f64;
1394
1395     /// Raises an `f32` to an `f32` power.
1396     ///
1397     /// The stabilized version of this intrinsic is
1398     /// [`f32::powf`](../../std/primitive.f32.html#method.powf)
1399     pub fn powf32(a: f32, x: f32) -> f32;
1400     /// Raises an `f64` to an `f64` power.
1401     ///
1402     /// The stabilized version of this intrinsic is
1403     /// [`f64::powf`](../../std/primitive.f64.html#method.powf)
1404     pub fn powf64(a: f64, x: f64) -> f64;
1405
1406     /// Returns the exponential of an `f32`.
1407     ///
1408     /// The stabilized version of this intrinsic is
1409     /// [`f32::exp`](../../std/primitive.f32.html#method.exp)
1410     pub fn expf32(x: f32) -> f32;
1411     /// Returns the exponential of an `f64`.
1412     ///
1413     /// The stabilized version of this intrinsic is
1414     /// [`f64::exp`](../../std/primitive.f64.html#method.exp)
1415     pub fn expf64(x: f64) -> f64;
1416
1417     /// Returns 2 raised to the power of an `f32`.
1418     ///
1419     /// The stabilized version of this intrinsic is
1420     /// [`f32::exp2`](../../std/primitive.f32.html#method.exp2)
1421     pub fn exp2f32(x: f32) -> f32;
1422     /// Returns 2 raised to the power of an `f64`.
1423     ///
1424     /// The stabilized version of this intrinsic is
1425     /// [`f64::exp2`](../../std/primitive.f64.html#method.exp2)
1426     pub fn exp2f64(x: f64) -> f64;
1427
1428     /// Returns the natural logarithm of an `f32`.
1429     ///
1430     /// The stabilized version of this intrinsic is
1431     /// [`f32::ln`](../../std/primitive.f32.html#method.ln)
1432     pub fn logf32(x: f32) -> f32;
1433     /// Returns the natural logarithm of an `f64`.
1434     ///
1435     /// The stabilized version of this intrinsic is
1436     /// [`f64::ln`](../../std/primitive.f64.html#method.ln)
1437     pub fn logf64(x: f64) -> f64;
1438
1439     /// Returns the base 10 logarithm of an `f32`.
1440     ///
1441     /// The stabilized version of this intrinsic is
1442     /// [`f32::log10`](../../std/primitive.f32.html#method.log10)
1443     pub fn log10f32(x: f32) -> f32;
1444     /// Returns the base 10 logarithm of an `f64`.
1445     ///
1446     /// The stabilized version of this intrinsic is
1447     /// [`f64::log10`](../../std/primitive.f64.html#method.log10)
1448     pub fn log10f64(x: f64) -> f64;
1449
1450     /// Returns the base 2 logarithm of an `f32`.
1451     ///
1452     /// The stabilized version of this intrinsic is
1453     /// [`f32::log2`](../../std/primitive.f32.html#method.log2)
1454     pub fn log2f32(x: f32) -> f32;
1455     /// Returns the base 2 logarithm of an `f64`.
1456     ///
1457     /// The stabilized version of this intrinsic is
1458     /// [`f64::log2`](../../std/primitive.f64.html#method.log2)
1459     pub fn log2f64(x: f64) -> f64;
1460
1461     /// Returns `a * b + c` for `f32` values.
1462     ///
1463     /// The stabilized version of this intrinsic is
1464     /// [`f32::mul_add`](../../std/primitive.f32.html#method.mul_add)
1465     pub fn fmaf32(a: f32, b: f32, c: f32) -> f32;
1466     /// Returns `a * b + c` for `f64` values.
1467     ///
1468     /// The stabilized version of this intrinsic is
1469     /// [`f64::mul_add`](../../std/primitive.f64.html#method.mul_add)
1470     pub fn fmaf64(a: f64, b: f64, c: f64) -> f64;
1471
1472     /// Returns the absolute value of an `f32`.
1473     ///
1474     /// The stabilized version of this intrinsic is
1475     /// [`f32::abs`](../../std/primitive.f32.html#method.abs)
1476     pub fn fabsf32(x: f32) -> f32;
1477     /// Returns the absolute value of an `f64`.
1478     ///
1479     /// The stabilized version of this intrinsic is
1480     /// [`f64::abs`](../../std/primitive.f64.html#method.abs)
1481     pub fn fabsf64(x: f64) -> f64;
1482
1483     /// Returns the minimum of two `f32` values.
1484     ///
1485     /// Note that, unlike most intrinsics, this is safe to call;
1486     /// it does not require an `unsafe` block.
1487     /// Therefore, implementations must not require the user to uphold
1488     /// any safety invariants.
1489     ///
1490     /// The stabilized version of this intrinsic is
1491     /// [`f32::min`]
1492     pub fn minnumf32(x: f32, y: f32) -> f32;
1493     /// Returns the minimum of two `f64` values.
1494     ///
1495     /// Note that, unlike most intrinsics, this is safe to call;
1496     /// it does not require an `unsafe` block.
1497     /// Therefore, implementations must not require the user to uphold
1498     /// any safety invariants.
1499     ///
1500     /// The stabilized version of this intrinsic is
1501     /// [`f64::min`]
1502     pub fn minnumf64(x: f64, y: f64) -> f64;
1503     /// Returns the maximum of two `f32` values.
1504     ///
1505     /// Note that, unlike most intrinsics, this is safe to call;
1506     /// it does not require an `unsafe` block.
1507     /// Therefore, implementations must not require the user to uphold
1508     /// any safety invariants.
1509     ///
1510     /// The stabilized version of this intrinsic is
1511     /// [`f32::max`]
1512     pub fn maxnumf32(x: f32, y: f32) -> f32;
1513     /// Returns the maximum of two `f64` values.
1514     ///
1515     /// Note that, unlike most intrinsics, this is safe to call;
1516     /// it does not require an `unsafe` block.
1517     /// Therefore, implementations must not require the user to uphold
1518     /// any safety invariants.
1519     ///
1520     /// The stabilized version of this intrinsic is
1521     /// [`f64::max`]
1522     pub fn maxnumf64(x: f64, y: f64) -> f64;
1523
1524     /// Copies the sign from `y` to `x` for `f32` values.
1525     ///
1526     /// The stabilized version of this intrinsic is
1527     /// [`f32::copysign`](../../std/primitive.f32.html#method.copysign)
1528     pub fn copysignf32(x: f32, y: f32) -> f32;
1529     /// Copies the sign from `y` to `x` for `f64` values.
1530     ///
1531     /// The stabilized version of this intrinsic is
1532     /// [`f64::copysign`](../../std/primitive.f64.html#method.copysign)
1533     pub fn copysignf64(x: f64, y: f64) -> f64;
1534
1535     /// Returns the largest integer less than or equal to an `f32`.
1536     ///
1537     /// The stabilized version of this intrinsic is
1538     /// [`f32::floor`](../../std/primitive.f32.html#method.floor)
1539     pub fn floorf32(x: f32) -> f32;
1540     /// Returns the largest integer less than or equal to an `f64`.
1541     ///
1542     /// The stabilized version of this intrinsic is
1543     /// [`f64::floor`](../../std/primitive.f64.html#method.floor)
1544     pub fn floorf64(x: f64) -> f64;
1545
1546     /// Returns the smallest integer greater than or equal to an `f32`.
1547     ///
1548     /// The stabilized version of this intrinsic is
1549     /// [`f32::ceil`](../../std/primitive.f32.html#method.ceil)
1550     pub fn ceilf32(x: f32) -> f32;
1551     /// Returns the smallest integer greater than or equal to an `f64`.
1552     ///
1553     /// The stabilized version of this intrinsic is
1554     /// [`f64::ceil`](../../std/primitive.f64.html#method.ceil)
1555     pub fn ceilf64(x: f64) -> f64;
1556
1557     /// Returns the integer part of an `f32`.
1558     ///
1559     /// The stabilized version of this intrinsic is
1560     /// [`f32::trunc`](../../std/primitive.f32.html#method.trunc)
1561     pub fn truncf32(x: f32) -> f32;
1562     /// Returns the integer part of an `f64`.
1563     ///
1564     /// The stabilized version of this intrinsic is
1565     /// [`f64::trunc`](../../std/primitive.f64.html#method.trunc)
1566     pub fn truncf64(x: f64) -> f64;
1567
1568     /// Returns the nearest integer to an `f32`. May raise an inexact floating-point exception
1569     /// if the argument is not an integer.
1570     pub fn rintf32(x: f32) -> f32;
1571     /// Returns the nearest integer to an `f64`. May raise an inexact floating-point exception
1572     /// if the argument is not an integer.
1573     pub fn rintf64(x: f64) -> f64;
1574
1575     /// Returns the nearest integer to an `f32`.
1576     ///
1577     /// This intrinsic does not have a stable counterpart.
1578     pub fn nearbyintf32(x: f32) -> f32;
1579     /// Returns the nearest integer to an `f64`.
1580     ///
1581     /// This intrinsic does not have a stable counterpart.
1582     pub fn nearbyintf64(x: f64) -> f64;
1583
1584     /// Returns the nearest integer to an `f32`. Rounds half-way cases away from zero.
1585     ///
1586     /// The stabilized version of this intrinsic is
1587     /// [`f32::round`](../../std/primitive.f32.html#method.round)
1588     pub fn roundf32(x: f32) -> f32;
1589     /// Returns the nearest integer to an `f64`. Rounds half-way cases away from zero.
1590     ///
1591     /// The stabilized version of this intrinsic is
1592     /// [`f64::round`](../../std/primitive.f64.html#method.round)
1593     pub fn roundf64(x: f64) -> f64;
1594
1595     /// Float addition that allows optimizations based on algebraic rules.
1596     /// May assume inputs are finite.
1597     ///
1598     /// This intrinsic does not have a stable counterpart.
1599     pub fn fadd_fast<T: Copy>(a: T, b: T) -> T;
1600
1601     /// Float subtraction that allows optimizations based on algebraic rules.
1602     /// May assume inputs are finite.
1603     ///
1604     /// This intrinsic does not have a stable counterpart.
1605     pub fn fsub_fast<T: Copy>(a: T, b: T) -> T;
1606
1607     /// Float multiplication that allows optimizations based on algebraic rules.
1608     /// May assume inputs are finite.
1609     ///
1610     /// This intrinsic does not have a stable counterpart.
1611     pub fn fmul_fast<T: Copy>(a: T, b: T) -> T;
1612
1613     /// Float division that allows optimizations based on algebraic rules.
1614     /// May assume inputs are finite.
1615     ///
1616     /// This intrinsic does not have a stable counterpart.
1617     pub fn fdiv_fast<T: Copy>(a: T, b: T) -> T;
1618
1619     /// Float remainder that allows optimizations based on algebraic rules.
1620     /// May assume inputs are finite.
1621     ///
1622     /// This intrinsic does not have a stable counterpart.
1623     pub fn frem_fast<T: Copy>(a: T, b: T) -> T;
1624
1625     /// Convert with LLVM’s fptoui/fptosi, which may return undef for values out of range
1626     /// (<https://github.com/rust-lang/rust/issues/10184>)
1627     ///
1628     /// Stabilized as [`f32::to_int_unchecked`] and [`f64::to_int_unchecked`].
1629     pub fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
1630
1631     /// Returns the number of bits set in an integer type `T`
1632     ///
1633     /// Note that, unlike most intrinsics, this is safe to call;
1634     /// it does not require an `unsafe` block.
1635     /// Therefore, implementations must not require the user to uphold
1636     /// any safety invariants.
1637     ///
1638     /// The stabilized versions of this intrinsic are available on the integer
1639     /// primitives via the `count_ones` method. For example,
1640     /// [`u32::count_ones`]
1641     #[rustc_const_stable(feature = "const_ctpop", since = "1.40.0")]
1642     pub fn ctpop<T: Copy>(x: T) -> T;
1643
1644     /// Returns the number of leading unset bits (zeroes) in an integer type `T`.
1645     ///
1646     /// Note that, unlike most intrinsics, this is safe to call;
1647     /// it does not require an `unsafe` block.
1648     /// Therefore, implementations must not require the user to uphold
1649     /// any safety invariants.
1650     ///
1651     /// The stabilized versions of this intrinsic are available on the integer
1652     /// primitives via the `leading_zeros` method. For example,
1653     /// [`u32::leading_zeros`]
1654     ///
1655     /// # Examples
1656     ///
1657     /// ```
1658     /// #![feature(core_intrinsics)]
1659     ///
1660     /// use std::intrinsics::ctlz;
1661     ///
1662     /// let x = 0b0001_1100_u8;
1663     /// let num_leading = ctlz(x);
1664     /// assert_eq!(num_leading, 3);
1665     /// ```
1666     ///
1667     /// An `x` with value `0` will return the bit width of `T`.
1668     ///
1669     /// ```
1670     /// #![feature(core_intrinsics)]
1671     ///
1672     /// use std::intrinsics::ctlz;
1673     ///
1674     /// let x = 0u16;
1675     /// let num_leading = ctlz(x);
1676     /// assert_eq!(num_leading, 16);
1677     /// ```
1678     #[rustc_const_stable(feature = "const_ctlz", since = "1.40.0")]
1679     pub fn ctlz<T: Copy>(x: T) -> T;
1680
1681     /// Like `ctlz`, but extra-unsafe as it returns `undef` when
1682     /// given an `x` with value `0`.
1683     ///
1684     /// This intrinsic does not have a stable counterpart.
1685     ///
1686     /// # Examples
1687     ///
1688     /// ```
1689     /// #![feature(core_intrinsics)]
1690     ///
1691     /// use std::intrinsics::ctlz_nonzero;
1692     ///
1693     /// let x = 0b0001_1100_u8;
1694     /// let num_leading = unsafe { ctlz_nonzero(x) };
1695     /// assert_eq!(num_leading, 3);
1696     /// ```
1697     #[rustc_const_stable(feature = "constctlz", since = "1.50.0")]
1698     pub fn ctlz_nonzero<T: Copy>(x: T) -> T;
1699
1700     /// Returns the number of trailing unset bits (zeroes) in an integer type `T`.
1701     ///
1702     /// Note that, unlike most intrinsics, this is safe to call;
1703     /// it does not require an `unsafe` block.
1704     /// Therefore, implementations must not require the user to uphold
1705     /// any safety invariants.
1706     ///
1707     /// The stabilized versions of this intrinsic are available on the integer
1708     /// primitives via the `trailing_zeros` method. For example,
1709     /// [`u32::trailing_zeros`]
1710     ///
1711     /// # Examples
1712     ///
1713     /// ```
1714     /// #![feature(core_intrinsics)]
1715     ///
1716     /// use std::intrinsics::cttz;
1717     ///
1718     /// let x = 0b0011_1000_u8;
1719     /// let num_trailing = cttz(x);
1720     /// assert_eq!(num_trailing, 3);
1721     /// ```
1722     ///
1723     /// An `x` with value `0` will return the bit width of `T`:
1724     ///
1725     /// ```
1726     /// #![feature(core_intrinsics)]
1727     ///
1728     /// use std::intrinsics::cttz;
1729     ///
1730     /// let x = 0u16;
1731     /// let num_trailing = cttz(x);
1732     /// assert_eq!(num_trailing, 16);
1733     /// ```
1734     #[rustc_const_stable(feature = "const_cttz", since = "1.40.0")]
1735     pub fn cttz<T: Copy>(x: T) -> T;
1736
1737     /// Like `cttz`, but extra-unsafe as it returns `undef` when
1738     /// given an `x` with value `0`.
1739     ///
1740     /// This intrinsic does not have a stable counterpart.
1741     ///
1742     /// # Examples
1743     ///
1744     /// ```
1745     /// #![feature(core_intrinsics)]
1746     ///
1747     /// use std::intrinsics::cttz_nonzero;
1748     ///
1749     /// let x = 0b0011_1000_u8;
1750     /// let num_trailing = unsafe { cttz_nonzero(x) };
1751     /// assert_eq!(num_trailing, 3);
1752     /// ```
1753     #[rustc_const_stable(feature = "const_cttz_nonzero", since = "1.53.0")]
1754     pub fn cttz_nonzero<T: Copy>(x: T) -> T;
1755
1756     /// Reverses the bytes in an integer type `T`.
1757     ///
1758     /// Note that, unlike most intrinsics, this is safe to call;
1759     /// it does not require an `unsafe` block.
1760     /// Therefore, implementations must not require the user to uphold
1761     /// any safety invariants.
1762     ///
1763     /// The stabilized versions of this intrinsic are available on the integer
1764     /// primitives via the `swap_bytes` method. For example,
1765     /// [`u32::swap_bytes`]
1766     #[rustc_const_stable(feature = "const_bswap", since = "1.40.0")]
1767     pub fn bswap<T: Copy>(x: T) -> T;
1768
1769     /// Reverses the bits in an integer type `T`.
1770     ///
1771     /// Note that, unlike most intrinsics, this is safe to call;
1772     /// it does not require an `unsafe` block.
1773     /// Therefore, implementations must not require the user to uphold
1774     /// any safety invariants.
1775     ///
1776     /// The stabilized versions of this intrinsic are available on the integer
1777     /// primitives via the `reverse_bits` method. For example,
1778     /// [`u32::reverse_bits`]
1779     #[rustc_const_stable(feature = "const_bitreverse", since = "1.40.0")]
1780     pub fn bitreverse<T: Copy>(x: T) -> T;
1781
1782     /// Performs checked integer addition.
1783     ///
1784     /// Note that, unlike most intrinsics, this is safe to call;
1785     /// it does not require an `unsafe` block.
1786     /// Therefore, implementations must not require the user to uphold
1787     /// any safety invariants.
1788     ///
1789     /// The stabilized versions of this intrinsic are available on the integer
1790     /// primitives via the `overflowing_add` method. For example,
1791     /// [`u32::overflowing_add`]
1792     #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1793     pub fn add_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
1794
1795     /// Performs checked integer subtraction
1796     ///
1797     /// Note that, unlike most intrinsics, this is safe to call;
1798     /// it does not require an `unsafe` block.
1799     /// Therefore, implementations must not require the user to uphold
1800     /// any safety invariants.
1801     ///
1802     /// The stabilized versions of this intrinsic are available on the integer
1803     /// primitives via the `overflowing_sub` method. For example,
1804     /// [`u32::overflowing_sub`]
1805     #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1806     pub fn sub_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
1807
1808     /// Performs checked integer multiplication
1809     ///
1810     /// Note that, unlike most intrinsics, this is safe to call;
1811     /// it does not require an `unsafe` block.
1812     /// Therefore, implementations must not require the user to uphold
1813     /// any safety invariants.
1814     ///
1815     /// The stabilized versions of this intrinsic are available on the integer
1816     /// primitives via the `overflowing_mul` method. For example,
1817     /// [`u32::overflowing_mul`]
1818     #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1819     pub fn mul_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
1820
1821     /// Performs an exact division, resulting in undefined behavior where
1822     /// `x % y != 0` or `y == 0` or `x == T::MIN && y == -1`
1823     ///
1824     /// This intrinsic does not have a stable counterpart.
1825     pub fn exact_div<T: Copy>(x: T, y: T) -> T;
1826
1827     /// Performs an unchecked division, resulting in undefined behavior
1828     /// where `y == 0` or `x == T::MIN && y == -1`
1829     ///
1830     /// Safe wrappers for this intrinsic are available on the integer
1831     /// primitives via the `checked_div` method. For example,
1832     /// [`u32::checked_div`]
1833     #[rustc_const_stable(feature = "const_int_unchecked_div", since = "1.52.0")]
1834     pub fn unchecked_div<T: Copy>(x: T, y: T) -> T;
1835     /// Returns the remainder of an unchecked division, resulting in
1836     /// undefined behavior when `y == 0` or `x == T::MIN && y == -1`
1837     ///
1838     /// Safe wrappers for this intrinsic are available on the integer
1839     /// primitives via the `checked_rem` method. For example,
1840     /// [`u32::checked_rem`]
1841     #[rustc_const_stable(feature = "const_int_unchecked_rem", since = "1.52.0")]
1842     pub fn unchecked_rem<T: Copy>(x: T, y: T) -> T;
1843
1844     /// Performs an unchecked left shift, resulting in undefined behavior when
1845     /// `y < 0` or `y >= N`, where N is the width of T in bits.
1846     ///
1847     /// Safe wrappers for this intrinsic are available on the integer
1848     /// primitives via the `checked_shl` method. For example,
1849     /// [`u32::checked_shl`]
1850     #[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
1851     pub fn unchecked_shl<T: Copy>(x: T, y: T) -> T;
1852     /// Performs an unchecked right shift, resulting in undefined behavior when
1853     /// `y < 0` or `y >= N`, where N is the width of T in bits.
1854     ///
1855     /// Safe wrappers for this intrinsic are available on the integer
1856     /// primitives via the `checked_shr` method. For example,
1857     /// [`u32::checked_shr`]
1858     #[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
1859     pub fn unchecked_shr<T: Copy>(x: T, y: T) -> T;
1860
1861     /// Returns the result of an unchecked addition, resulting in
1862     /// undefined behavior when `x + y > T::MAX` or `x + y < T::MIN`.
1863     ///
1864     /// This intrinsic does not have a stable counterpart.
1865     #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1866     pub fn unchecked_add<T: Copy>(x: T, y: T) -> T;
1867
1868     /// Returns the result of an unchecked subtraction, resulting in
1869     /// undefined behavior when `x - y > T::MAX` or `x - y < T::MIN`.
1870     ///
1871     /// This intrinsic does not have a stable counterpart.
1872     #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1873     pub fn unchecked_sub<T: Copy>(x: T, y: T) -> T;
1874
1875     /// Returns the result of an unchecked multiplication, resulting in
1876     /// undefined behavior when `x * y > T::MAX` or `x * y < T::MIN`.
1877     ///
1878     /// This intrinsic does not have a stable counterpart.
1879     #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1880     pub fn unchecked_mul<T: Copy>(x: T, y: T) -> T;
1881
1882     /// Performs rotate left.
1883     ///
1884     /// Note that, unlike most intrinsics, this is safe to call;
1885     /// it does not require an `unsafe` block.
1886     /// Therefore, implementations must not require the user to uphold
1887     /// any safety invariants.
1888     ///
1889     /// The stabilized versions of this intrinsic are available on the integer
1890     /// primitives via the `rotate_left` method. For example,
1891     /// [`u32::rotate_left`]
1892     #[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
1893     pub fn rotate_left<T: Copy>(x: T, y: T) -> T;
1894
1895     /// Performs rotate right.
1896     ///
1897     /// Note that, unlike most intrinsics, this is safe to call;
1898     /// it does not require an `unsafe` block.
1899     /// Therefore, implementations must not require the user to uphold
1900     /// any safety invariants.
1901     ///
1902     /// The stabilized versions of this intrinsic are available on the integer
1903     /// primitives via the `rotate_right` method. For example,
1904     /// [`u32::rotate_right`]
1905     #[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
1906     pub fn rotate_right<T: Copy>(x: T, y: T) -> T;
1907
1908     /// Returns (a + b) mod 2<sup>N</sup>, where N is the width of T in bits.
1909     ///
1910     /// Note that, unlike most intrinsics, this is safe to call;
1911     /// it does not require an `unsafe` block.
1912     /// Therefore, implementations must not require the user to uphold
1913     /// any safety invariants.
1914     ///
1915     /// The stabilized versions of this intrinsic are available on the integer
1916     /// primitives via the `wrapping_add` method. For example,
1917     /// [`u32::wrapping_add`]
1918     #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1919     pub fn wrapping_add<T: Copy>(a: T, b: T) -> T;
1920     /// Returns (a - b) mod 2<sup>N</sup>, where N is the width of T in bits.
1921     ///
1922     /// Note that, unlike most intrinsics, this is safe to call;
1923     /// it does not require an `unsafe` block.
1924     /// Therefore, implementations must not require the user to uphold
1925     /// any safety invariants.
1926     ///
1927     /// The stabilized versions of this intrinsic are available on the integer
1928     /// primitives via the `wrapping_sub` method. For example,
1929     /// [`u32::wrapping_sub`]
1930     #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1931     pub fn wrapping_sub<T: Copy>(a: T, b: T) -> T;
1932     /// Returns (a * b) mod 2<sup>N</sup>, where N is the width of T in bits.
1933     ///
1934     /// Note that, unlike most intrinsics, this is safe to call;
1935     /// it does not require an `unsafe` block.
1936     /// Therefore, implementations must not require the user to uphold
1937     /// any safety invariants.
1938     ///
1939     /// The stabilized versions of this intrinsic are available on the integer
1940     /// primitives via the `wrapping_mul` method. For example,
1941     /// [`u32::wrapping_mul`]
1942     #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1943     pub fn wrapping_mul<T: Copy>(a: T, b: T) -> T;
1944
1945     /// Computes `a + b`, saturating at numeric bounds.
1946     ///
1947     /// Note that, unlike most intrinsics, this is safe to call;
1948     /// it does not require an `unsafe` block.
1949     /// Therefore, implementations must not require the user to uphold
1950     /// any safety invariants.
1951     ///
1952     /// The stabilized versions of this intrinsic are available on the integer
1953     /// primitives via the `saturating_add` method. For example,
1954     /// [`u32::saturating_add`]
1955     #[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")]
1956     pub fn saturating_add<T: Copy>(a: T, b: T) -> T;
1957     /// Computes `a - b`, saturating at numeric bounds.
1958     ///
1959     /// Note that, unlike most intrinsics, this is safe to call;
1960     /// it does not require an `unsafe` block.
1961     /// Therefore, implementations must not require the user to uphold
1962     /// any safety invariants.
1963     ///
1964     /// The stabilized versions of this intrinsic are available on the integer
1965     /// primitives via the `saturating_sub` method. For example,
1966     /// [`u32::saturating_sub`]
1967     #[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")]
1968     pub fn saturating_sub<T: Copy>(a: T, b: T) -> T;
1969
1970     /// Returns the value of the discriminant for the variant in 'v';
1971     /// if `T` has no discriminant, returns `0`.
1972     ///
1973     /// Note that, unlike most intrinsics, this is safe to call;
1974     /// it does not require an `unsafe` block.
1975     /// Therefore, implementations must not require the user to uphold
1976     /// any safety invariants.
1977     ///
1978     /// The stabilized version of this intrinsic is [`core::mem::discriminant`].
1979     #[rustc_const_unstable(feature = "const_discriminant", issue = "69821")]
1980     pub fn discriminant_value<T>(v: &T) -> <T as DiscriminantKind>::Discriminant;
1981
1982     /// Returns the number of variants of the type `T` cast to a `usize`;
1983     /// if `T` has no variants, returns `0`. Uninhabited variants will be counted.
1984     ///
1985     /// Note that, unlike most intrinsics, this is safe to call;
1986     /// it does not require an `unsafe` block.
1987     /// Therefore, implementations must not require the user to uphold
1988     /// any safety invariants.
1989     ///
1990     /// The to-be-stabilized version of this intrinsic is [`mem::variant_count`].
1991     #[rustc_const_unstable(feature = "variant_count", issue = "73662")]
1992     pub fn variant_count<T>() -> usize;
1993
1994     /// Rust's "try catch" construct which invokes the function pointer `try_fn`
1995     /// with the data pointer `data`.
1996     ///
1997     /// The third argument is a function called if a panic occurs. This function
1998     /// takes the data pointer and a pointer to the target-specific exception
1999     /// object that was caught. For more information see the compiler's
2000     /// source as well as std's catch implementation.
2001     pub fn r#try(try_fn: fn(*mut u8), data: *mut u8, catch_fn: fn(*mut u8, *mut u8)) -> i32;
2002
2003     /// Emits a `!nontemporal` store according to LLVM (see their docs).
2004     /// Probably will never become stable.
2005     pub fn nontemporal_store<T>(ptr: *mut T, val: T);
2006
2007     /// See documentation of `<*const T>::offset_from` for details.
2008     #[rustc_const_stable(feature = "const_ptr_offset_from", since = "1.65.0")]
2009     pub fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
2010
2011     /// See documentation of `<*const T>::sub_ptr` for details.
2012     #[rustc_const_unstable(feature = "const_ptr_sub_ptr", issue = "95892")]
2013     pub fn ptr_offset_from_unsigned<T>(ptr: *const T, base: *const T) -> usize;
2014
2015     /// See documentation of `<*const T>::guaranteed_eq` for details.
2016     ///
2017     /// Note that, unlike most intrinsics, this is safe to call;
2018     /// it does not require an `unsafe` block.
2019     /// Therefore, implementations must not require the user to uphold
2020     /// any safety invariants.
2021     #[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
2022     pub fn ptr_guaranteed_eq<T>(ptr: *const T, other: *const T) -> bool;
2023
2024     /// See documentation of `<*const T>::guaranteed_ne` for details.
2025     ///
2026     /// Note that, unlike most intrinsics, this is safe to call;
2027     /// it does not require an `unsafe` block.
2028     /// Therefore, implementations must not require the user to uphold
2029     /// any safety invariants.
2030     #[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
2031     pub fn ptr_guaranteed_ne<T>(ptr: *const T, other: *const T) -> bool;
2032
2033     /// Allocates a block of memory at compile time.
2034     /// At runtime, just returns a null pointer.
2035     ///
2036     /// # Safety
2037     ///
2038     /// - The `align` argument must be a power of two.
2039     ///    - At compile time, a compile error occurs if this constraint is violated.
2040     ///    - At runtime, it is not checked.
2041     #[rustc_const_unstable(feature = "const_heap", issue = "79597")]
2042     pub fn const_allocate(size: usize, align: usize) -> *mut u8;
2043
2044     /// Deallocates a memory which allocated by `intrinsics::const_allocate` at compile time.
2045     /// At runtime, does nothing.
2046     ///
2047     /// # Safety
2048     ///
2049     /// - The `align` argument must be a power of two.
2050     ///    - At compile time, a compile error occurs if this constraint is violated.
2051     ///    - At runtime, it is not checked.
2052     /// - If the `ptr` is created in an another const, this intrinsic doesn't deallocate it.
2053     /// - If the `ptr` is pointing to a local variable, this intrinsic doesn't deallocate it.
2054     #[rustc_const_unstable(feature = "const_heap", issue = "79597")]
2055     pub fn const_deallocate(ptr: *mut u8, size: usize, align: usize);
2056
2057     /// Determines whether the raw bytes of the two values are equal.
2058     ///
2059     /// This is particularly handy for arrays, since it allows things like just
2060     /// comparing `i96`s instead of forcing `alloca`s for `[6 x i16]`.
2061     ///
2062     /// Above some backend-decided threshold this will emit calls to `memcmp`,
2063     /// like slice equality does, instead of causing massive code size.
2064     ///
2065     /// # Safety
2066     ///
2067     /// It's UB to call this if any of the *bytes* in `*a` or `*b` are uninitialized or carry a
2068     /// pointer value.
2069     /// Note that this is a stricter criterion than just the *values* being
2070     /// fully-initialized: if `T` has padding, it's UB to call this intrinsic.
2071     ///
2072     /// (The implementation is allowed to branch on the results of comparisons,
2073     /// which is UB if any of their inputs are `undef`.)
2074     #[rustc_const_unstable(feature = "const_intrinsic_raw_eq", issue = "none")]
2075     pub fn raw_eq<T>(a: &T, b: &T) -> bool;
2076
2077     /// See documentation of [`std::hint::black_box`] for details.
2078     ///
2079     /// [`std::hint::black_box`]: crate::hint::black_box
2080     #[rustc_const_unstable(feature = "const_black_box", issue = "none")]
2081     pub fn black_box<T>(dummy: T) -> T;
2082
2083     /// `ptr` must point to a vtable.
2084     /// The intrinsic will return the size stored in that vtable.
2085     pub fn vtable_size(ptr: *const ()) -> usize;
2086
2087     /// `ptr` must point to a vtable.
2088     /// The intrinsic will return the alignment stored in that vtable.
2089     pub fn vtable_align(ptr: *const ()) -> usize;
2090
2091     /// Selects which function to call depending on the context.
2092     ///
2093     /// If this function is evaluated at compile-time, then a call to this
2094     /// intrinsic will be replaced with a call to `called_in_const`. It gets
2095     /// replaced with a call to `called_at_rt` otherwise.
2096     ///
2097     /// # Type Requirements
2098     ///
2099     /// The two functions must be both function items. They cannot be function
2100     /// pointers or closures. The first function must be a `const fn`.
2101     ///
2102     /// `arg` will be the tupled arguments that will be passed to either one of
2103     /// the two functions, therefore, both functions must accept the same type of
2104     /// arguments. Both functions must return RET.
2105     ///
2106     /// # Safety
2107     ///
2108     /// The two functions must behave observably equivalent. Safe code in other
2109     /// crates may assume that calling a `const fn` at compile-time and at run-time
2110     /// produces the same result. A function that produces a different result when
2111     /// evaluated at run-time, or has any other observable side-effects, is
2112     /// *unsound*.
2113     ///
2114     /// Here is an example of how this could cause a problem:
2115     /// ```no_run
2116     /// #![feature(const_eval_select)]
2117     /// #![feature(core_intrinsics)]
2118     /// use std::hint::unreachable_unchecked;
2119     /// use std::intrinsics::const_eval_select;
2120     ///
2121     /// // Crate A
2122     /// pub const fn inconsistent() -> i32 {
2123     ///     fn runtime() -> i32 { 1 }
2124     ///     const fn compiletime() -> i32 { 2 }
2125     ///
2126     ///     unsafe {
2127     //          // ⚠ This code violates the required equivalence of `compiletime`
2128     ///         // and `runtime`.
2129     ///         const_eval_select((), compiletime, runtime)
2130     ///     }
2131     /// }
2132     ///
2133     /// // Crate B
2134     /// const X: i32 = inconsistent();
2135     /// let x = inconsistent();
2136     /// if x != X { unsafe { unreachable_unchecked(); }}
2137     /// ```
2138     ///
2139     /// This code causes Undefined Behavior when being run, since the
2140     /// `unreachable_unchecked` is actually being reached. The bug is in *crate A*,
2141     /// which violates the principle that a `const fn` must behave the same at
2142     /// compile-time and at run-time. The unsafe code in crate B is fine.
2143     #[cfg(not(bootstrap))]
2144     #[rustc_const_unstable(feature = "const_eval_select", issue = "none")]
2145     pub fn const_eval_select<ARG, F, G, RET>(arg: ARG, called_in_const: F, called_at_rt: G) -> RET
2146     where
2147         G: FnOnce<ARG, Output = RET>,
2148         F: FnOnce<ARG, Output = RET>;
2149 }
2150
2151 // Some functions are defined here because they accidentally got made
2152 // available in this module on stable. See <https://github.com/rust-lang/rust/issues/15702>.
2153 // (`transmute` also falls into this category, but it cannot be wrapped due to the
2154 // check that `T` and `U` have the same size.)
2155
2156 /// Check that the preconditions of an unsafe function are followed, if debug_assertions are on,
2157 /// and only at runtime.
2158 ///
2159 /// This macro should be called as `assert_unsafe_precondition!([Generics](name: Type) => Expression)`
2160 /// where the names specified will be moved into the macro as captured variables, and defines an item
2161 /// to call `const_eval_select` on. The tokens inside the square brackets are used to denote generics
2162 /// for the function declaractions and can be omitted if there is no generics.
2163 ///
2164 /// # Safety
2165 ///
2166 /// Invoking this macro is only sound if the following code is already UB when the passed
2167 /// expression evaluates to false.
2168 ///
2169 /// This macro expands to a check at runtime if debug_assertions is set. It has no effect at
2170 /// compile time, but the semantics of the contained `const_eval_select` must be the same at
2171 /// runtime and at compile time. Thus if the expression evaluates to false, this macro produces
2172 /// different behavior at compile time and at runtime, and invoking it is incorrect.
2173 ///
2174 /// So in a sense it is UB if this macro is useful, but we expect callers of `unsafe fn` to make
2175 /// the occasional mistake, and this check should help them figure things out.
2176 #[allow_internal_unstable(const_eval_select)] // permit this to be called in stably-const fn
2177 macro_rules! assert_unsafe_precondition {
2178     ($([$($tt:tt)*])?($($i:ident:$ty:ty),*$(,)?) => $e:expr) => {
2179         if cfg!(debug_assertions) {
2180             // allow non_snake_case to allow capturing const generics
2181             #[allow(non_snake_case)]
2182             #[inline(always)]
2183             fn runtime$(<$($tt)*>)?($($i:$ty),*) {
2184                 if !$e {
2185                     // abort instead of panicking to reduce impact on code size
2186                     ::core::intrinsics::abort();
2187                 }
2188             }
2189             #[allow(non_snake_case)]
2190             const fn comptime$(<$($tt)*>)?($(_:$ty),*) {}
2191
2192             ::core::intrinsics::const_eval_select(($($i,)*), comptime, runtime);
2193         }
2194     };
2195 }
2196 pub(crate) use assert_unsafe_precondition;
2197
2198 /// Checks whether `ptr` is properly aligned with respect to
2199 /// `align_of::<T>()`.
2200 pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
2201     !ptr.is_null() && ptr.is_aligned()
2202 }
2203
2204 /// Checks whether the regions of memory starting at `src` and `dst` of size
2205 /// `count * size_of::<T>()` do *not* overlap.
2206 pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) -> bool {
2207     let src_usize = src.addr();
2208     let dst_usize = dst.addr();
2209     let size = mem::size_of::<T>().checked_mul(count).unwrap();
2210     let diff = if src_usize > dst_usize { src_usize - dst_usize } else { dst_usize - src_usize };
2211     // If the absolute distance between the ptrs is at least as big as the size of the buffer,
2212     // they do not overlap.
2213     diff >= size
2214 }
2215
2216 /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
2217 /// and destination must *not* overlap.
2218 ///
2219 /// For regions of memory which might overlap, use [`copy`] instead.
2220 ///
2221 /// `copy_nonoverlapping` is semantically equivalent to C's [`memcpy`], but
2222 /// with the argument order swapped.
2223 ///
2224 /// The copy is "untyped" in the sense that data may be uninitialized or otherwise violate the
2225 /// requirements of `T`. The initialization state is preserved exactly.
2226 ///
2227 /// [`memcpy`]: https://en.cppreference.com/w/c/string/byte/memcpy
2228 ///
2229 /// # Safety
2230 ///
2231 /// Behavior is undefined if any of the following conditions are violated:
2232 ///
2233 /// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
2234 ///
2235 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
2236 ///
2237 /// * Both `src` and `dst` must be properly aligned.
2238 ///
2239 /// * The region of memory beginning at `src` with a size of `count *
2240 ///   size_of::<T>()` bytes must *not* overlap with the region of memory
2241 ///   beginning at `dst` with the same size.
2242 ///
2243 /// Like [`read`], `copy_nonoverlapping` creates a bitwise copy of `T`, regardless of
2244 /// whether `T` is [`Copy`]. If `T` is not [`Copy`], using *both* the values
2245 /// in the region beginning at `*src` and the region beginning at `*dst` can
2246 /// [violate memory safety][read-ownership].
2247 ///
2248 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
2249 /// `0`, the pointers must be non-null and properly aligned.
2250 ///
2251 /// [`read`]: crate::ptr::read
2252 /// [read-ownership]: crate::ptr::read#ownership-of-the-returned-value
2253 /// [valid]: crate::ptr#safety
2254 ///
2255 /// # Examples
2256 ///
2257 /// Manually implement [`Vec::append`]:
2258 ///
2259 /// ```
2260 /// use std::ptr;
2261 ///
2262 /// /// Moves all the elements of `src` into `dst`, leaving `src` empty.
2263 /// fn append<T>(dst: &mut Vec<T>, src: &mut Vec<T>) {
2264 ///     let src_len = src.len();
2265 ///     let dst_len = dst.len();
2266 ///
2267 ///     // Ensure that `dst` has enough capacity to hold all of `src`.
2268 ///     dst.reserve(src_len);
2269 ///
2270 ///     unsafe {
2271 ///         // The call to add is always safe because `Vec` will never
2272 ///         // allocate more than `isize::MAX` bytes.
2273 ///         let dst_ptr = dst.as_mut_ptr().add(dst_len);
2274 ///         let src_ptr = src.as_ptr();
2275 ///
2276 ///         // Truncate `src` without dropping its contents. We do this first,
2277 ///         // to avoid problems in case something further down panics.
2278 ///         src.set_len(0);
2279 ///
2280 ///         // The two regions cannot overlap because mutable references do
2281 ///         // not alias, and two different vectors cannot own the same
2282 ///         // memory.
2283 ///         ptr::copy_nonoverlapping(src_ptr, dst_ptr, src_len);
2284 ///
2285 ///         // Notify `dst` that it now holds the contents of `src`.
2286 ///         dst.set_len(dst_len + src_len);
2287 ///     }
2288 /// }
2289 ///
2290 /// let mut a = vec!['r'];
2291 /// let mut b = vec!['u', 's', 't'];
2292 ///
2293 /// append(&mut a, &mut b);
2294 ///
2295 /// assert_eq!(a, &['r', 'u', 's', 't']);
2296 /// assert!(b.is_empty());
2297 /// ```
2298 ///
2299 /// [`Vec::append`]: ../../std/vec/struct.Vec.html#method.append
2300 #[doc(alias = "memcpy")]
2301 #[stable(feature = "rust1", since = "1.0.0")]
2302 #[rustc_allowed_through_unstable_modules]
2303 #[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
2304 #[inline]
2305 #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
2306 pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
2307     extern "rust-intrinsic" {
2308         #[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
2309         pub fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
2310     }
2311
2312     // SAFETY: the safety contract for `copy_nonoverlapping` must be
2313     // upheld by the caller.
2314     unsafe {
2315         assert_unsafe_precondition!([T](src: *const T, dst: *mut T, count: usize) =>
2316             is_aligned_and_not_null(src)
2317                 && is_aligned_and_not_null(dst)
2318                 && is_nonoverlapping(src, dst, count)
2319         );
2320         copy_nonoverlapping(src, dst, count)
2321     }
2322 }
2323
2324 /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
2325 /// and destination may overlap.
2326 ///
2327 /// If the source and destination will *never* overlap,
2328 /// [`copy_nonoverlapping`] can be used instead.
2329 ///
2330 /// `copy` is semantically equivalent to C's [`memmove`], but with the argument
2331 /// order swapped. Copying takes place as if the bytes were copied from `src`
2332 /// to a temporary array and then copied from the array to `dst`.
2333 ///
2334 /// The copy is "untyped" in the sense that data may be uninitialized or otherwise violate the
2335 /// requirements of `T`. The initialization state is preserved exactly.
2336 ///
2337 /// [`memmove`]: https://en.cppreference.com/w/c/string/byte/memmove
2338 ///
2339 /// # Safety
2340 ///
2341 /// Behavior is undefined if any of the following conditions are violated:
2342 ///
2343 /// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
2344 ///
2345 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
2346 ///
2347 /// * Both `src` and `dst` must be properly aligned.
2348 ///
2349 /// Like [`read`], `copy` creates a bitwise copy of `T`, regardless of
2350 /// whether `T` is [`Copy`]. If `T` is not [`Copy`], using both the values
2351 /// in the region beginning at `*src` and the region beginning at `*dst` can
2352 /// [violate memory safety][read-ownership].
2353 ///
2354 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
2355 /// `0`, the pointers must be non-null and properly aligned.
2356 ///
2357 /// [`read`]: crate::ptr::read
2358 /// [read-ownership]: crate::ptr::read#ownership-of-the-returned-value
2359 /// [valid]: crate::ptr#safety
2360 ///
2361 /// # Examples
2362 ///
2363 /// Efficiently create a Rust vector from an unsafe buffer:
2364 ///
2365 /// ```
2366 /// use std::ptr;
2367 ///
2368 /// /// # Safety
2369 /// ///
2370 /// /// * `ptr` must be correctly aligned for its type and non-zero.
2371 /// /// * `ptr` must be valid for reads of `elts` contiguous elements of type `T`.
2372 /// /// * Those elements must not be used after calling this function unless `T: Copy`.
2373 /// # #[allow(dead_code)]
2374 /// unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> {
2375 ///     let mut dst = Vec::with_capacity(elts);
2376 ///
2377 ///     // SAFETY: Our precondition ensures the source is aligned and valid,
2378 ///     // and `Vec::with_capacity` ensures that we have usable space to write them.
2379 ///     ptr::copy(ptr, dst.as_mut_ptr(), elts);
2380 ///
2381 ///     // SAFETY: We created it with this much capacity earlier,
2382 ///     // and the previous `copy` has initialized these elements.
2383 ///     dst.set_len(elts);
2384 ///     dst
2385 /// }
2386 /// ```
2387 #[doc(alias = "memmove")]
2388 #[stable(feature = "rust1", since = "1.0.0")]
2389 #[rustc_allowed_through_unstable_modules]
2390 #[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
2391 #[inline]
2392 #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
2393 pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
2394     extern "rust-intrinsic" {
2395         #[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
2396         fn copy<T>(src: *const T, dst: *mut T, count: usize);
2397     }
2398
2399     // SAFETY: the safety contract for `copy` must be upheld by the caller.
2400     unsafe {
2401         assert_unsafe_precondition!([T](src: *const T, dst: *mut T) =>
2402             is_aligned_and_not_null(src) && is_aligned_and_not_null(dst));
2403         copy(src, dst, count)
2404     }
2405 }
2406
2407 /// Sets `count * size_of::<T>()` bytes of memory starting at `dst` to
2408 /// `val`.
2409 ///
2410 /// `write_bytes` is similar to C's [`memset`], but sets `count *
2411 /// size_of::<T>()` bytes to `val`.
2412 ///
2413 /// [`memset`]: https://en.cppreference.com/w/c/string/byte/memset
2414 ///
2415 /// # Safety
2416 ///
2417 /// Behavior is undefined if any of the following conditions are violated:
2418 ///
2419 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
2420 ///
2421 /// * `dst` must be properly aligned.
2422 ///
2423 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
2424 /// `0`, the pointer must be non-null and properly aligned.
2425 ///
2426 /// Additionally, note that changing `*dst` in this way can easily lead to undefined behavior (UB)
2427 /// later if the written bytes are not a valid representation of some `T`. For instance, the
2428 /// following is an **incorrect** use of this function:
2429 ///
2430 /// ```rust,no_run
2431 /// unsafe {
2432 ///     let mut value: u8 = 0;
2433 ///     let ptr: *mut bool = &mut value as *mut u8 as *mut bool;
2434 ///     let _bool = ptr.read(); // This is fine, `ptr` points to a valid `bool`.
2435 ///     ptr.write_bytes(42u8, 1); // This function itself does not cause UB...
2436 ///     let _bool = ptr.read(); // ...but it makes this operation UB! ⚠️
2437 /// }
2438 /// ```
2439 ///
2440 /// [valid]: crate::ptr#safety
2441 ///
2442 /// # Examples
2443 ///
2444 /// Basic usage:
2445 ///
2446 /// ```
2447 /// use std::ptr;
2448 ///
2449 /// let mut vec = vec![0u32; 4];
2450 /// unsafe {
2451 ///     let vec_ptr = vec.as_mut_ptr();
2452 ///     ptr::write_bytes(vec_ptr, 0xfe, 2);
2453 /// }
2454 /// assert_eq!(vec, [0xfefefefe, 0xfefefefe, 0, 0]);
2455 /// ```
2456 #[doc(alias = "memset")]
2457 #[stable(feature = "rust1", since = "1.0.0")]
2458 #[rustc_allowed_through_unstable_modules]
2459 #[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
2460 #[inline]
2461 #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
2462 pub const unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
2463     extern "rust-intrinsic" {
2464         #[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
2465         fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
2466     }
2467
2468     // SAFETY: the safety contract for `write_bytes` must be upheld by the caller.
2469     unsafe {
2470         assert_unsafe_precondition!([T](dst: *mut T) => is_aligned_and_not_null(dst));
2471         write_bytes(dst, val, count)
2472     }
2473 }
2474
2475 #[cfg(bootstrap)]
2476 #[unstable(
2477     feature = "const_eval_select",
2478     issue = "none",
2479     reason = "const_eval_select will never be stable"
2480 )]
2481 #[rustc_const_unstable(feature = "const_eval_select", issue = "none")]
2482 #[lang = "const_eval_select"]
2483 #[rustc_do_not_const_check]
2484 #[inline]
2485 pub const unsafe fn const_eval_select<ARG, F, G, RET>(
2486     arg: ARG,
2487     _called_in_const: F,
2488     called_at_rt: G,
2489 ) -> RET
2490 where
2491     F: ~const FnOnce<ARG, Output = RET>,
2492     G: FnOnce<ARG, Output = RET> + ~const Destruct,
2493 {
2494     called_at_rt.call_once(arg)
2495 }
2496
2497 #[cfg(bootstrap)]
2498 #[unstable(
2499     feature = "const_eval_select",
2500     issue = "none",
2501     reason = "const_eval_select will never be stable"
2502 )]
2503 #[rustc_const_unstable(feature = "const_eval_select", issue = "none")]
2504 #[lang = "const_eval_select_ct"]
2505 pub const unsafe fn const_eval_select_ct<ARG, F, G, RET>(
2506     arg: ARG,
2507     called_in_const: F,
2508     _called_at_rt: G,
2509 ) -> RET
2510 where
2511     F: ~const FnOnce<ARG, Output = RET>,
2512     G: FnOnce<ARG, Output = RET> + ~const Destruct,
2513 {
2514     called_in_const.call_once(arg)
2515 }