Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add details about unsafe_op_in_unsafe_fn to E0133 #112037

Merged
merged 1 commit into from
May 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion compiler/rustc_error_codes/src/error_codes/E0133.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Unsafe code was used outside of an unsafe function or block.
Unsafe code was used outside of an unsafe block.

Erroneous code example:

Expand Down Expand Up @@ -30,4 +30,21 @@ fn main() {

See the [unsafe section][unsafe-section] of the Book for more details.

#### Unsafe code in functions

Unsafe code is currently accepted in unsafe functions, but that is being phased
out in favor of requiring unsafe blocks here too.

```
unsafe fn f() { return; }

unsafe fn g() {
f(); // Is accepted, but no longer recommended
unsafe { f(); } // Recommended way to write this
}
```

Linting against this is controlled via the `unsafe_op_in_unsafe_fn` lint, which
is `allow` by default but will be upgraded to `warn` in a future edition.

[unsafe-section]: https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html