File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
compiler/rustc_error_codes/src/error_codes Expand file tree Collapse file tree 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.
22
33Erroneous code example:
44
@@ -30,4 +30,21 @@ fn main() {
3030
3131See 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
You can’t perform that action at this time.
0 commit comments