-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7d4fd2e742e8d92ddc1032a8328f95b2
unsafe fn foo() -> u32 {
unsafe {
std::mem::transmute::<i32, u32>(5)
}
}
The current output is:
warning: unnecessary `unsafe` block
--> src/lib.rs:2:5
|
1 | unsafe fn foo() -> u32 {
| ---------------------- because it's nested under this `unsafe` fn
2 | unsafe {
| ^^^^^^ unnecessary `unsafe` block
|
= note: `#[warn(unused_unsafe)]` on by default
Ideally the output should look like (very roughly):
warning: unnecessary `unsafe` block
--> src/lib.rs:2:5
|
1 | unsafe fn foo() -> u32 {
| ---------------------- because it's nested under this `unsafe` fn
2 | unsafe {
| ^^^^^^ unnecessary `unsafe` block
|
= note: `#[warn(unused_unsafe)]` on by default
= note: use `#[warn(unsafe_op_in_unsafe_fn)]` to allow unsafe blocks in unsafe functions in places where they would be needed in a safe function
The note should only appear when it's an appropriate usage of an unsafe
block, i.e. the block's contents aren't safe.
This would hint at unsafe_op_in_unsafe_fn
even being a thing right from the output :)
PatchMixolydic, mk12, RustyYato and shepmaster
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
unused_unsafe
lint #93678steffahn commentedon Feb 6, 2022
I’ve created a PR that would generate the following output:
(The
note: `#[allow(unsafe_op_in_unsafe_fn)]` on by default
part – technically – just explains where the lint-level for the first unsafe operation inside the block for whichunsafe_op_in_unsafe_fn
is allowed comes from, in the same style as it’s done e.g. for theunused_unsafe
warning itself in the other, earlier,note
.)Feel free to give feedback on this output, or ask questions. I do suppose it fulfills the main property to “hint at
unsafe_op_in_unsafe_fn
even being a thing”.