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