Skip to content

Commit 5d445d1

Browse files
committed
Fix doctest
1 parent e0d98ae commit 5d445d1

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/doc/unstable-book/src/language-features/intrinsics.md

+26-4
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,35 @@ some features that only exist on some backends. Backends can simply not implemen
1616
intrinsics without causing any code miscompilations or failures to compile.
1717

1818
```rust
19-
#![feature(core_intrinsics)]
19+
#![feature(rustc_attrs, effects)]
20+
#![allow(internal_features)]
2021

2122
#[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+
}
2440
}
41+
2542
```
2643

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+
2748
## Intrinsics lowered to MIR instructions
2849

2950
Various intrinsics have native MIR operations that they correspond to. Instead of requiring
@@ -53,4 +74,5 @@ extern "rust-intrinsic" {
5374
}
5475
```
5576

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

Comments
 (0)