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

Bug in handling unsafe_op_in_unsafe_fn #18462

Closed
schreter opened this issue Nov 2, 2024 · 1 comment · Fixed by #18466
Closed

Bug in handling unsafe_op_in_unsafe_fn #18462

schreter opened this issue Nov 2, 2024 · 1 comment · Fixed by #18466
Assignees
Labels
C-bug Category: bug

Comments

@schreter
Copy link

schreter commented Nov 2, 2024

Handling of unsafe_op_in_unsafe_fn warning introduced by #18135 is unfortunately a bit broken (@ChayimFriedman2).

In our project, we deny warnings, which only has an effect on enabled warnings. In edition 2021 (which is the current default) the warning unsafe_op_in_unsafe_fn is not enabled (allow-by-default).

When compiling regularly with #[deny(warnings)], the compiler doesn't complain. However, rust-analyzer produces a lot of warnings/errors for all unsafe-in-unsafe calls in our code (one library in our project being an async executor implementation naturally has a lot of unsafe code).

rust-analyzer version: 0.3.2162-standalone (3b3a87f 2024-10-27)

rustc version: rustc 1.81.0 (eeb90cda1 2024-09-04)

editor or extension: VSCode

relevant settings: (nothing specific, trivial project shows it)

code snippet to reproduce:

The minimal example I came up with is this one:

Contents of main.rs:

#![warn(warnings)] // <- or `deny` - it activates the warning in Edition 2021!
unsafe fn dangerous() {}
unsafe fn call_dangerous() { dangerous(); }
fn main() { unsafe { call_dangerous(); } }

For completeness, here the Cargo.toml:

[package]
name = "test_unsafe"
version = "0.1.0"
edition = "2021"

It seems like the warning is improperly enabled when #[warn(warnings)] or #[deny(warnings)] is in place. It should be only enabled if either edition is set to 2024 or if it's explicitly enabled by #[warn(unsafe_op_in_unsafe_fn)] or #[deny(unsafe_op_in_unsafe_fn)].

Please fix the warning activation and ideally name a workaround for the time being. Thanks in advance.

@schreter schreter added the C-bug Category: bug label Nov 2, 2024
@ChayimFriedman2
Copy link
Contributor

Note that #![deny(warnings)] isn't a good practice anyway (we still need to fix this issue though).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants