@@ -16,14 +16,35 @@ some features that only exist on some backends. Backends can simply not implemen
16
16
intrinsics without causing any code miscompilations or failures to compile.
17
17
18
18
``` rust
19
- #![feature(core_intrinsics)]
19
+ #![feature(rustc_attrs, effects)]
20
+ #![allow(internal_features)]
20
21
21
22
#[rustc_intrinsic]
22
- fn some_intrinsic_name () -> u32 {
23
- 42
23
+ const unsafe fn const_deallocate (_ptr : * mut u8 , _size : usize , _align : usize ) {}
24
+ ```
25
+
26
+ Since these are just regular functions, it is perfectly ok to create the intrinsic twice:
27
+
28
+ ``` rust
29
+ #![feature(rustc_attrs, effects)]
30
+ #![allow(internal_features)]
31
+
32
+ #[rustc_intrinsic]
33
+ const unsafe fn const_deallocate (_ptr : * mut u8 , _size : usize , _align : usize ) {}
34
+
35
+ mod foo {
36
+ #[rustc_intrinsic]
37
+ const unsafe fn const_deallocate (ptr : * mut u8 , size : usize , align : usize ) {
38
+ eprintln! (" noisy const dealloc: {ptr:p}, {size}, {align}" )
39
+ }
24
40
}
41
+
25
42
```
26
43
44
+ The behaviour on backends that override the intrinsic is exactly the same. On other
45
+ backends, the intrinsic behaviour depends on which implementation is called, just like
46
+ with any regular function.
47
+
27
48
## Intrinsics lowered to MIR instructions
28
49
29
50
Various intrinsics have native MIR operations that they correspond to. Instead of requiring
@@ -53,4 +74,5 @@ extern "rust-intrinsic" {
53
74
}
54
75
```
55
76
56
- As with any other FFI functions, these are always ` unsafe ` to call.
77
+ As with any other FFI functions, these are by default always ` unsafe ` to call.
78
+ You can add ` #[rustc_safe_intrinsic] ` to the intrinsic to make it safe to call.
0 commit comments