-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add MVP suggestion for unsafe_op_in_unsafe_fn
#99827
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// run-rustfix | ||
|
||
#![deny(unsafe_op_in_unsafe_fn)] | ||
|
||
unsafe fn unsf() {} | ||
|
||
pub unsafe fn foo() { unsafe { | ||
unsf(); //~ ERROR call to unsafe function is unsafe | ||
unsf(); //~ ERROR call to unsafe function is unsafe | ||
}} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// run-rustfix | ||
|
||
#![deny(unsafe_op_in_unsafe_fn)] | ||
|
||
unsafe fn unsf() {} | ||
|
||
pub unsafe fn foo() { | ||
unsf(); //~ ERROR call to unsafe function is unsafe | ||
unsf(); //~ ERROR call to unsafe function is unsafe | ||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
error: call to unsafe function is unsafe and requires unsafe block (error E0133) | ||
--> $DIR/wrapping-unsafe-block-sugg.rs:8:5 | ||
| | ||
LL | unsf(); | ||
| ^^^^^^ call to unsafe function | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/wrapping-unsafe-block-sugg.rs:3:9 | ||
| | ||
LL | #![deny(unsafe_op_in_unsafe_fn)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: consult the function's documentation for information on how to avoid undefined behavior | ||
help: consider wrapping the function in an unsafe block | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure that this help text is useful -- I assume it's not necessary for the suggestion to be emitted for us to show it to humans too? I feel like something more human-applicable here would be better, along the lines of "help: an unsafe function restricts callers, but it's body is safe by default". But I'm struggling with something succinct here. It's probably a good idea to update the text in E0133 with some more expansive commentary on the effects of unsafe_op_in_unsafe_fn in any case, since it currently says nothing about that case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We could show only the message without the code, or hide the suggestion entirely. |
||
| | ||
LL ~ pub unsafe fn foo() { unsafe { | ||
LL | unsf(); | ||
LL | unsf(); | ||
LL ~ }} | ||
| | ||
|
||
error: call to unsafe function is unsafe and requires unsafe block (error E0133) | ||
--> $DIR/wrapping-unsafe-block-sugg.rs:9:5 | ||
| | ||
LL | unsf(); | ||
| ^^^^^^ call to unsafe function | ||
| | ||
= note: consult the function's documentation for information on how to avoid undefined behavior | ||
|
||
error: aborting due to 2 previous errors | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps HasPlaceholders?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs for
Applicability
stateBut I think the goal is to be able to apply a "quick fix" to make the code compile. Can
HasPlaceholders
suggestion still be applied "auto-manually"? I have never used rustfix (:sweat_smile:) and I'm not sure how the differentApplicability
settings behave for the end user.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not, good point.