compiler/rustc_error_codes/src/error_codes/E0133.md MARKDOWN 52 lines View on github.com → Search inside
1Unsafe code was used outside of an unsafe block.23Erroneous code example:45```compile_fail,E01336unsafe fn f() { return; } // This is the unsafe code78fn main() {9    f(); // error: call to unsafe function requires unsafe function or block10}11```1213Using unsafe functionality is potentially dangerous and disallowed by safety14checks. Examples:1516* Dereferencing raw pointers17* Calling functions via FFI18* Calling functions marked unsafe1920These safety checks can be relaxed for a section of the code by wrapping the21unsafe instructions with an `unsafe` block. For instance:2223```24unsafe fn f() { return; }2526fn main() {27    unsafe { f(); } // ok!28}29```3031See the [unsafe section][unsafe-section] of the Book for more details.3233#### Unsafe code in functions3435Unsafe code is currently accepted in unsafe functions, but that is being phased36out in favor of requiring unsafe blocks here too.3738```39unsafe fn f() { return; }4041unsafe fn g() {42    f(); // Is accepted, but no longer recommended43    unsafe { f(); } // Recommended way to write this44}45```4647Linting against this is controlled via the `unsafe_op_in_unsafe_fn` lint, which48is `warn` by default in the 2024 edition and `allow` by default in earlier49editions.5051[unsafe-section]: https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html

Findings

✓ No findings reported for this file.

Get this view in your editor

Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.