Skip to content

Commit ec20993

Browse files
Stabilize unsafe_op_in_unsafe_fn lint
1 parent cb2effd commit ec20993

File tree

13 files changed

+26
-74
lines changed

13 files changed

+26
-74
lines changed

compiler/rustc_feature/src/accepted.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ declare_features! (
275275
(accepted, move_ref_pattern, "1.48.0", Some(68354), None),
276276
/// The smallest useful subset of `const_generics`.
277277
(accepted, min_const_generics, "1.51.0", Some(74878), None),
278+
/// The `unsafe_op_in_unsafe_fn` lint (allowed by default): no longer treat an unsafe function as an unsafe block.
279+
(accepted, unsafe_block_in_unsafe_fn, "1.51.0", Some(71668), None),
278280

279281
// -------------------------------------------------------------------------
280282
// feature-group-end: accepted features

compiler/rustc_feature/src/active.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,6 @@ declare_features! (
557557
/// Allows the use of `#[ffi_const]` on foreign functions.
558558
(active, ffi_const, "1.45.0", Some(58328), None),
559559

560-
/// No longer treat an unsafe function as an unsafe block.
561-
(active, unsafe_block_in_unsafe_fn, "1.45.0", Some(71668), None),
562-
563560
/// Allows `extern "avr-interrupt" fn()` and `extern "avr-non-blocking-interrupt" fn()`.
564561
(active, abi_avr_interrupt, "1.45.0", Some(69664), None),
565562

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
99
use crate::{declare_lint, declare_lint_pass};
1010
use rustc_span::edition::Edition;
11-
use rustc_span::symbol::sym;
1211

1312
declare_lint! {
1413
/// The `forbidden_lint_groups` lint detects violations of
@@ -2577,16 +2576,11 @@ declare_lint! {
25772576

25782577
declare_lint! {
25792578
/// The `unsafe_op_in_unsafe_fn` lint detects unsafe operations in unsafe
2580-
/// functions without an explicit unsafe block. This lint only works on
2581-
/// the [**nightly channel**] with the
2582-
/// `#![feature(unsafe_block_in_unsafe_fn)]` feature.
2583-
///
2584-
/// [**nightly channel**]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
2579+
/// functions without an explicit unsafe block.
25852580
///
25862581
/// ### Example
25872582
///
25882583
/// ```rust,compile_fail
2589-
/// #![feature(unsafe_block_in_unsafe_fn)]
25902584
/// #![deny(unsafe_op_in_unsafe_fn)]
25912585
///
25922586
/// unsafe fn foo() {}
@@ -2624,7 +2618,6 @@ declare_lint! {
26242618
pub UNSAFE_OP_IN_UNSAFE_FN,
26252619
Allow,
26262620
"unsafe operations in unsafe functions without an explicit unsafe block are deprecated",
2627-
@feature_gate = sym::unsafe_block_in_unsafe_fn;
26282621
}
26292622

26302623
declare_lint! {

compiler/rustc_middle/src/mir/query.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ pub enum UnsafetyViolationKind {
2828
BorrowPacked,
2929
/// Unsafe operation in an `unsafe fn` but outside an `unsafe` block.
3030
/// Has to be handled as a lint for backwards compatibility.
31-
/// Should stay gated under `#![feature(unsafe_block_in_unsafe_fn)]`.
3231
UnsafeFn,
3332
/// Borrow of packed field in an `unsafe fn` but outside an `unsafe` block.
3433
/// Has to be handled as a lint for backwards compatibility.
35-
/// Should stay gated under `#![feature(unsafe_block_in_unsafe_fn)]`.
3634
UnsafeFnBorrowPacked,
3735
}
3836

compiler/rustc_mir/src/transform/check_unsafety.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
340340
false
341341
}
342342
// With the RFC 2585, no longer allow `unsafe` operations in `unsafe fn`s
343-
Safety::FnUnsafe if self.tcx.features().unsafe_block_in_unsafe_fn => {
343+
Safety::FnUnsafe => {
344344
for violation in violations {
345345
let mut violation = *violation;
346346

@@ -355,8 +355,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
355355
}
356356
false
357357
}
358-
// `unsafe` function bodies allow unsafe without additional unsafe blocks (before RFC 2585)
359-
Safety::BuiltinUnsafe | Safety::FnUnsafe => true,
358+
Safety::BuiltinUnsafe => true,
360359
Safety::ExplicitUnsafe(hir_id) => {
361360
// mark unsafe block as used if there are any unsafe operations inside
362361
if !violations.is_empty() {

library/alloc/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
#![feature(trusted_len)]
129129
#![feature(unboxed_closures)]
130130
#![feature(unicode_internals)]
131-
#![feature(unsafe_block_in_unsafe_fn)]
131+
#![cfg_attr(bootstrap, feature(unsafe_block_in_unsafe_fn))]
132132
#![feature(unsize)]
133133
#![feature(unsized_fn_params)]
134134
#![feature(allocator_internals)]

library/core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@
162162
#![feature(const_caller_location)]
163163
#![feature(slice_ptr_get)]
164164
#![feature(no_niche)] // rust-lang/rust#68303
165-
#![feature(unsafe_block_in_unsafe_fn)]
166165
#![feature(int_error_matching)]
166+
#![cfg_attr(bootstrap, feature(unsafe_block_in_unsafe_fn))]
167167
#![deny(unsafe_op_in_unsafe_fn)]
168168

169169
#[prelude_import]

library/core/tests/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@
7171
#![feature(peekable_peek_mut)]
7272
#![cfg_attr(not(bootstrap), feature(ptr_metadata))]
7373
#![feature(once_cell)]
74-
#![feature(unsafe_block_in_unsafe_fn)]
7574
#![feature(unsized_tuple_coercion)]
7675
#![feature(int_bits_const)]
7776
#![feature(nonzero_leading_trailing_zeros)]
7877
#![feature(const_option)]
7978
#![feature(integer_atomics)]
8079
#![feature(slice_group_by)]
8180
#![feature(trusted_random_access)]
82-
#![deny(unsafe_op_in_unsafe_fn)]
81+
#![cfg_attr(bootstrap, feature(unsafe_block_in_unsafe_fn))]
8382
#![cfg_attr(not(bootstrap), feature(unsize))]
83+
#![deny(unsafe_op_in_unsafe_fn)]
8484

8585
extern crate test;
8686

library/std/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@
324324
#![feature(try_blocks)]
325325
#![feature(try_reserve)]
326326
#![feature(unboxed_closures)]
327-
#![feature(unsafe_block_in_unsafe_fn)]
327+
#![cfg_attr(bootstrap, feature(unsafe_block_in_unsafe_fn))]
328328
#![feature(unsafe_cell_raw_get)]
329329
#![feature(unwind_attributes)]
330330
#![feature(vec_into_raw_parts)]

src/test/ui/feature-gates/feature-gate-unsafe_block_in_unsafe_fn.rs

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)