Skip to content

Commit b0360e9

Browse files
authored
Rollup merge of rust-lang#79208 - LeSeulArtichaut:stable-unsafe_op_in_unsafe_fn, r=nikomatsakis
Stabilize `unsafe_op_in_unsafe_fn` lint This makes it possible to override the level of the `unsafe_op_in_unsafe_fn`, as proposed in rust-lang#71668 (comment). Tracking issue: rust-lang#71668 r? ```@nikomatsakis``` cc ```@SimonSapin``` ```@RalfJung``` # Stabilization report This is a stabilization report for `#![feature(unsafe_block_in_unsafe_fn)]`. ## Summary Currently, the body of unsafe functions is an unsafe block, i.e. you can perform unsafe operations inside. The `unsafe_op_in_unsafe_fn` lint, stabilized here, can be used to change this behavior, so performing unsafe operations in unsafe functions requires an unsafe block. For now, the lint is allow-by-default, which means that this PR does not change anything without overriding the lint level. For more information, see [RFC 2585](https://github.com/rust-lang/rfcs/blob/master/text/2585-unsafe-block-in-unsafe-fn.md) ### Example ```rust // An `unsafe fn` for demonstration purposes. // Calling this is an unsafe operation. unsafe fn unsf() {} // #[allow(unsafe_op_in_unsafe_fn)] by default, // the behavior of `unsafe fn` is unchanged unsafe fn allowed() { // Here, no `unsafe` block is needed to // perform unsafe operations... unsf(); // ...and any `unsafe` block is considered // unused and is warned on by the compiler. unsafe { unsf(); } } #[warn(unsafe_op_in_unsafe_fn)] unsafe fn warned() { // Removing this `unsafe` block will // cause the compiler to emit a warning. // (Also, no "unused unsafe" warning will be emitted here.) unsafe { unsf(); } } #[deny(unsafe_op_in_unsafe_fn)] unsafe fn denied() { // Removing this `unsafe` block will // cause a compilation error. // (Also, no "unused unsafe" warning will be emitted here.) unsafe { unsf(); } } ```
2 parents f13f458 + 8a84bf4 commit b0360e9

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

alloc/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
#![feature(trusted_len)]
134134
#![feature(unboxed_closures)]
135135
#![feature(unicode_internals)]
136-
#![feature(unsafe_block_in_unsafe_fn)]
136+
#![cfg_attr(bootstrap, feature(unsafe_block_in_unsafe_fn))]
137137
#![feature(unsize)]
138138
#![feature(unsized_fn_params)]
139139
#![feature(allocator_internals)]

core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@
164164
#![feature(const_caller_location)]
165165
#![feature(slice_ptr_get)]
166166
#![feature(no_niche)] // rust-lang/rust#68303
167-
#![feature(unsafe_block_in_unsafe_fn)]
168167
#![feature(int_error_matching)]
168+
#![cfg_attr(bootstrap, feature(unsafe_block_in_unsafe_fn))]
169169
#![deny(unsafe_op_in_unsafe_fn)]
170170

171171
#[prelude_import]

core/tests/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,16 @@
7272
#![feature(peekable_peek_mut)]
7373
#![cfg_attr(not(bootstrap), feature(ptr_metadata))]
7474
#![feature(once_cell)]
75-
#![feature(unsafe_block_in_unsafe_fn)]
7675
#![feature(unsized_tuple_coercion)]
7776
#![feature(int_bits_const)]
7877
#![feature(nonzero_leading_trailing_zeros)]
7978
#![feature(const_option)]
8079
#![feature(integer_atomics)]
8180
#![feature(slice_group_by)]
8281
#![feature(trusted_random_access)]
83-
#![deny(unsafe_op_in_unsafe_fn)]
82+
#![cfg_attr(bootstrap, feature(unsafe_block_in_unsafe_fn))]
8483
#![cfg_attr(not(bootstrap), feature(unsize))]
84+
#![deny(unsafe_op_in_unsafe_fn)]
8585

8686
extern crate test;
8787

std/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@
327327
#![feature(try_blocks)]
328328
#![feature(try_reserve)]
329329
#![feature(unboxed_closures)]
330-
#![feature(unsafe_block_in_unsafe_fn)]
330+
#![cfg_attr(bootstrap, feature(unsafe_block_in_unsafe_fn))]
331331
#![feature(unsafe_cell_raw_get)]
332332
#![feature(unwind_attributes)]
333333
#![feature(vec_into_raw_parts)]

0 commit comments

Comments
 (0)