Skip to content

Commit

Permalink
Auto merge of #112038 - Nemo157:edition-2024-unsafe_op_in_unsafe_fn, …
Browse files Browse the repository at this point in the history
…r=RalfJung

Change `unsafe_op_in_unsafe_fn` to be `warn`-by-default from edition 2024

This was previously FCPed: #71668 (comment)

There were two blocking requirements:
* Fix the `unused_unsafe` lint, done in #100081
* Have `cargo fix` able to fix the lint, done in #112017
  • Loading branch information
bors committed Sep 14, 2023
2 parents d97e04f + 119e0ff commit df63c5f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 18 deletions.
5 changes: 3 additions & 2 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2554,8 +2554,8 @@ declare_lint! {
///
/// The fix to this is to wrap the unsafe code in an `unsafe` block.
///
/// This lint is "allow" by default since this will affect a large amount
/// of existing code, and the exact plan for increasing the severity is
/// This lint is "allow" by default on editions up to 2021, from 2024 it is
/// "warn" by default; the plan for increasing severity further is
/// still being considered. See [RFC #2585] and [issue #71668] for more
/// details.
///
Expand All @@ -2567,6 +2567,7 @@ declare_lint! {
pub UNSAFE_OP_IN_UNSAFE_FN,
Allow,
"unsafe operations in unsafe functions without an explicit unsafe block are deprecated",
@edition Edition2024 => Warn;
}

declare_lint! {
Expand Down
20 changes: 4 additions & 16 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,36 +719,24 @@ macro_rules! declare_lint {
($(#[$attr:meta])* $vis: vis $NAME: ident, $Level: ident, $desc: expr,
$(@feature_gate = $gate:expr;)?
$(@future_incompatible = FutureIncompatibleInfo { $($field:ident : $val:expr),* $(,)* }; )?
$(@edition $lint_edition:ident => $edition_level:ident;)?
$($v:ident),*) => (
$(#[$attr])*
$vis static $NAME: &$crate::Lint = &$crate::Lint {
name: stringify!($NAME),
default_level: $crate::$Level,
desc: $desc,
edition_lint_opts: None,
is_plugin: false,
$($v: true,)*
$(feature_gate: Some($gate),)*
$(feature_gate: Some($gate),)?
$(future_incompatible: Some($crate::FutureIncompatibleInfo {
$($field: $val,)*
..$crate::FutureIncompatibleInfo::default_fields_for_macro()
}),)*
}),)?
$(edition_lint_opts: Some(($crate::Edition::$lint_edition, $crate::$edition_level)),)?
..$crate::Lint::default_fields_for_macro()
};
);
($(#[$attr:meta])* $vis: vis $NAME: ident, $Level: ident, $desc: expr,
$lint_edition: expr => $edition_level: ident
) => (
$(#[$attr])*
$vis static $NAME: &$crate::Lint = &$crate::Lint {
name: stringify!($NAME),
default_level: $crate::$Level,
desc: $desc,
edition_lint_opts: Some(($lint_edition, $crate::Level::$edition_level)),
report_in_external_macro: false,
is_plugin: false,
};
);
}

#[macro_export]
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/unsafe/edition-2024-unsafe_op_in_unsafe_fn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// edition: 2024
// compile-flags: -Zunstable-options
// check-pass

#![crate_type = "lib"]

#![deny(unused_unsafe)]

unsafe fn unsf() {}

unsafe fn foo() {
unsf();
//~^ WARN call to unsafe function is unsafe and requires unsafe block

// no unused_unsafe
unsafe { unsf(); }
}
16 changes: 16 additions & 0 deletions tests/ui/unsafe/edition-2024-unsafe_op_in_unsafe_fn.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
warning: call to unsafe function is unsafe and requires unsafe block (error E0133)
--> $DIR/edition-2024-unsafe_op_in_unsafe_fn.rs:12:5
|
LL | unsf();
| ^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior
note: an unsafe function restricts its caller, but its body is safe by default
--> $DIR/edition-2024-unsafe_op_in_unsafe_fn.rs:11:1
|
LL | unsafe fn foo() {
| ^^^^^^^^^^^^^^^
= note: `#[warn(unsafe_op_in_unsafe_fn)]` on by default

warning: 1 warning emitted

0 comments on commit df63c5f

Please sign in to comment.