File tree 1 file changed +18
-1
lines changed
compiler/rustc_error_codes/src/error_codes
1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 1
- Unsafe code was used outside of an unsafe function or block.
1
+ Unsafe code was used outside of an unsafe block.
2
2
3
3
Erroneous code example:
4
4
@@ -30,4 +30,21 @@ fn main() {
30
30
31
31
See the [ unsafe section] [ unsafe-section ] of the Book for more details.
32
32
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
+
33
50
[ unsafe-section ] : https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html
You can’t perform that action at this time.
0 commit comments