diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-05-29 04:03:02 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-29 04:03:02 +0200 |
| commit | c5a93ba9fe32916ddf1f13e6f21c21cecd8568f0 (patch) | |
| tree | 136023424b70f98511ccddc01c9a1bbbe82cd62e | |
| parent | 45ca2f732e18e42d3a95c79ace21b484205acdb1 (diff) | |
| parent | 8f942532541f571733c38d8c3145845948e4cd44 (diff) | |
Rollup merge of #112037 - Nemo157:e0133-unsafe_op_in_unsafe_fn, r=petrochenkov
Add details about `unsafe_op_in_unsafe_fn` to E0133 This was mentioned in https://github.com/rust-lang/rust/pull/99827#discussion_r933899901
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0133.md | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0133.md b/compiler/rustc_error_codes/src/error_codes/E0133.md index 1adbcc31356..8ca3f03ce15 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0133.md +++ b/compiler/rustc_error_codes/src/error_codes/E0133.md @@ -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: @@ -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 |
