Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change unsafe_op_in_unsafe_fn to be warn-by-default from edition 2024 #112038

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the old syntax wasn't used at all? Strange...

) => (
$(#[$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

Loading