]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0133.md
Rollup merge of #92310 - ehuss:rustdoc-ice, r=estebank
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0133.md
1 Unsafe code was used outside of an unsafe function or block.
2
3 Erroneous code example:
4
5 ```compile_fail,E0133
6 unsafe fn f() { return; } // This is the unsafe code
7
8 fn main() {
9     f(); // error: call to unsafe function requires unsafe function or block
10 }
11 ```
12
13 Using unsafe functionality is potentially dangerous and disallowed by safety
14 checks. Examples:
15
16 * Dereferencing raw pointers
17 * Calling functions via FFI
18 * Calling functions marked unsafe
19
20 These safety checks can be relaxed for a section of the code by wrapping the
21 unsafe instructions with an `unsafe` block. For instance:
22
23 ```
24 unsafe fn f() { return; }
25
26 fn main() {
27     unsafe { f(); } // ok!
28 }
29 ```
30
31 See the [unsafe section][unsafe-section] of the Book for more details.
32
33 [unsafe-section]: https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html