Skip to content

Commit 8f94253

Browse files
committed
Add details about unsafe_op_in_unsafe_fn to E0133
1 parent a525c7d commit 8f94253

File tree

1 file changed

+18
-1
lines changed
  • compiler/rustc_error_codes/src/error_codes

1 file changed

+18
-1
lines changed

Diff for: compiler/rustc_error_codes/src/error_codes/E0133.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Unsafe code was used outside of an unsafe function or block.
1+
Unsafe code was used outside of an unsafe block.
22

33
Erroneous code example:
44

@@ -30,4 +30,21 @@ fn main() {
3030

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

33+
#### Unsafe code in functions
34+
35+
Unsafe code is currently accepted in unsafe functions, but that is being phased
36+
out in favor of requiring unsafe blocks here too.
37+
38+
```
39+
unsafe fn f() { return; }
40+
41+
unsafe fn g() {
42+
f(); // Is accepted, but no longer recommended
43+
unsafe { f(); } // Recommended way to write this
44+
}
45+
```
46+
47+
Linting against this is controlled via the `unsafe_op_in_unsafe_fn` lint, which
48+
is `allow` by default but will be upgraded to `warn` in a future edition.
49+
3350
[unsafe-section]: https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html

0 commit comments

Comments
 (0)