-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Fix unused_unsafe
label with unsafe_block_in_unsafe_fn
#81110
Fix unused_unsafe
label with unsafe_block_in_unsafe_fn
#81110
Conversation
r? @lcnr (rust-highfive has picked a reviewer for you, use r? to override) |
I don't see the problem here? What you describe in the OP is intended behavior!
|
IOW, the feature gate itself should not change anything (as is common for feature gates). The feature gate merely unlocks the ability to use some other syntax to change something; in this case, that other syntax is |
Oh, wait, I misunderstood... I thought you wanted to not show the warning, but instead you want to show more information with the warning? I have no idea why that has anything to do with the feature flag though... |
@@ -74,12 +74,18 @@ LL | #![deny(unused_unsafe)] | |||
error: unnecessary `unsafe` block | |||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:51:5 | |||
| | |||
LL | unsafe fn allow_level() { | |||
| ----------------------- because it's nested under this `unsafe` fn | |||
... | |||
LL | unsafe { unsf() } | |||
| ^^^^^^ unnecessary `unsafe` block |
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.
FWIW, this error is kind of confusing because the "because" comes before the thing it is justifying. I guess there's also the error 'title' thing "unnecessary unsafe
block", so it's probably okay, but just reading the spans things are in the wrong order... not sure how we usually handle situations where code order and "justification order" disagree.
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.
This is how the warning is emitted today (without unsafe_block_in_unsafe_fn
). I guess any improvement here should be made in another PR
Right, sorry, I was probably not clear enough in the OP. This PR "restores" the "because it's nested under this unsafe fn" label in the warning when the lint is allowed, to match the behavior when the feature gate is not present. |
And as a drive-by fix it replaces a |
@RalfJung do you intend to fully review this PR? |
I guess at this point I just as well might.^^ |
5421029
to
2136a5c
Compare
@RalfJung This should be ready for another review |
Looking good, thanks! |
📌 Commit 2136a5c has been approved by |
…abel, r=RalfJung Fix `unused_unsafe` label with `unsafe_block_in_unsafe_fn Previously, the following code: ```rust #![feature(unsafe_block_in_unsafe_fn)] unsafe fn foo() { unsafe { unsf() } } unsafe fn unsf() {} ``` Would give the following warning: ``` warning: unnecessary `unsafe` block --> src/lib.rs:4:5 | 4 | unsafe { unsf() } | ^^^^^^ unnecessary `unsafe` block | = note: `#[warn(unused_unsafe)]` on by default ``` which doesn't point out that the block is in an `unsafe fn`. Tracking issue: rust-lang#71668 cc rust-lang#79208
unused_unsafe
label with `unsafe_block_in_unsafe_fnunused_unsafe
label with unsafe_block_in_unsafe_fn
☀️ Test successful - checks-actions |
Previously, the following code:
Would give the following warning:
which doesn't point out that the block is in an
unsafe fn
.Tracking issue: #71668
cc #79208