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