Skip to content

Commit df63c5f

Browse files
committed
Auto merge of rust-lang#112038 - Nemo157:edition-2024-unsafe_op_in_unsafe_fn, r=RalfJung
Change `unsafe_op_in_unsafe_fn` to be `warn`-by-default from edition 2024 This was previously FCPed: rust-lang#71668 (comment) There were two blocking requirements: * Fix the `unused_unsafe` lint, done in rust-lang#100081 * Have `cargo fix` able to fix the lint, done in rust-lang#112017
2 parents d97e04f + 119e0ff commit df63c5f

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed

compiler/rustc_lint_defs/src/builtin.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2554,8 +2554,8 @@ declare_lint! {
25542554
///
25552555
/// The fix to this is to wrap the unsafe code in an `unsafe` block.
25562556
///
2557-
/// This lint is "allow" by default since this will affect a large amount
2558-
/// of existing code, and the exact plan for increasing the severity is
2557+
/// This lint is "allow" by default on editions up to 2021, from 2024 it is
2558+
/// "warn" by default; the plan for increasing severity further is
25592559
/// still being considered. See [RFC #2585] and [issue #71668] for more
25602560
/// details.
25612561
///
@@ -2567,6 +2567,7 @@ declare_lint! {
25672567
pub UNSAFE_OP_IN_UNSAFE_FN,
25682568
Allow,
25692569
"unsafe operations in unsafe functions without an explicit unsafe block are deprecated",
2570+
@edition Edition2024 => Warn;
25702571
}
25712572

25722573
declare_lint! {

compiler/rustc_lint_defs/src/lib.rs

+4-16
Original file line numberDiff line numberDiff line change
@@ -719,36 +719,24 @@ macro_rules! declare_lint {
719719
($(#[$attr:meta])* $vis: vis $NAME: ident, $Level: ident, $desc: expr,
720720
$(@feature_gate = $gate:expr;)?
721721
$(@future_incompatible = FutureIncompatibleInfo { $($field:ident : $val:expr),* $(,)* }; )?
722+
$(@edition $lint_edition:ident => $edition_level:ident;)?
722723
$($v:ident),*) => (
723724
$(#[$attr])*
724725
$vis static $NAME: &$crate::Lint = &$crate::Lint {
725726
name: stringify!($NAME),
726727
default_level: $crate::$Level,
727728
desc: $desc,
728-
edition_lint_opts: None,
729729
is_plugin: false,
730730
$($v: true,)*
731-
$(feature_gate: Some($gate),)*
731+
$(feature_gate: Some($gate),)?
732732
$(future_incompatible: Some($crate::FutureIncompatibleInfo {
733733
$($field: $val,)*
734734
..$crate::FutureIncompatibleInfo::default_fields_for_macro()
735-
}),)*
735+
}),)?
736+
$(edition_lint_opts: Some(($crate::Edition::$lint_edition, $crate::$edition_level)),)?
736737
..$crate::Lint::default_fields_for_macro()
737738
};
738739
);
739-
($(#[$attr:meta])* $vis: vis $NAME: ident, $Level: ident, $desc: expr,
740-
$lint_edition: expr => $edition_level: ident
741-
) => (
742-
$(#[$attr])*
743-
$vis static $NAME: &$crate::Lint = &$crate::Lint {
744-
name: stringify!($NAME),
745-
default_level: $crate::$Level,
746-
desc: $desc,
747-
edition_lint_opts: Some(($lint_edition, $crate::Level::$edition_level)),
748-
report_in_external_macro: false,
749-
is_plugin: false,
750-
};
751-
);
752740
}
753741

754742
#[macro_export]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// edition: 2024
2+
// compile-flags: -Zunstable-options
3+
// check-pass
4+
5+
#![crate_type = "lib"]
6+
7+
#![deny(unused_unsafe)]
8+
9+
unsafe fn unsf() {}
10+
11+
unsafe fn foo() {
12+
unsf();
13+
//~^ WARN call to unsafe function is unsafe and requires unsafe block
14+
15+
// no unused_unsafe
16+
unsafe { unsf(); }
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
warning: call to unsafe function is unsafe and requires unsafe block (error E0133)
2+
--> $DIR/edition-2024-unsafe_op_in_unsafe_fn.rs:12:5
3+
|
4+
LL | unsf();
5+
| ^^^^^^ call to unsafe function
6+
|
7+
= note: consult the function's documentation for information on how to avoid undefined behavior
8+
note: an unsafe function restricts its caller, but its body is safe by default
9+
--> $DIR/edition-2024-unsafe_op_in_unsafe_fn.rs:11:1
10+
|
11+
LL | unsafe fn foo() {
12+
| ^^^^^^^^^^^^^^^
13+
= note: `#[warn(unsafe_op_in_unsafe_fn)]` on by default
14+
15+
warning: 1 warning emitted
16+

0 commit comments

Comments
 (0)