-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 undocumented_unsafe_blocks lint #7748
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @xFrednet (or someone else) soon. Please see the contribution instructions for more information. |
Yes, sure. I have time this afternoon. r? @flip1995 |
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 latest upstream changes (presumably #7709) made this pull request unmergeable. Please resolve the merge conflicts. |
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.
Thanks! Just missing one feature from the original suggestion in #7464;
The lint would also raise a warning if that comment is copied verbatim.
...
The following code would still raise a warning (not because of what transmute is doing here, but because the safety comment still has "...", as suggested. The developer would need to update it with an actual sentence.);
// Safety: ... let totally_a_usize = unsafe { std::mem::transmute::<String, usize>(string) };
070833f
to
f3934ed
Compare
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.
Impl LGTM overall now. A few minor improvements could be made.
670e2a1
to
59d93c5
Compare
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 PR should be almost done. I have some suggestions on how to simplify the code a bit.
The tests look awesome! The only test that is missing is a macro test. Two important tests here would be
unsafe
block in the macro call:m!(unsafe{ ... }
unsafe
block in the macro definition
Just for posterity; the behaviour that makes sure that "..." is also checked and errored on is removed, I think that's fine for now to get this PR through, but I'd still like to see it somewhere in the future |
abe480f
to
760115c
Compare
☔ The latest upstream changes (presumably #7773) made this pull request unmergeable. Please resolve the merge conflicts. |
One more thing that came to mind: What if the unsafe block has multi-line code in it? How does the suggestion look in that case? I expect that the full unsafe block is shown. We may want to avoid this, by using the |
760115c
to
b450d0d
Compare
Looks great now! Could you address the multi-line unsafe block case? After that this should be good to go. 🚀 |
Did I not take care of that? The |
Oh I missed that. In that case all good 👍 ( |
Please squash some commits, so that we can merge this. |
☔ The latest upstream changes (presumably #7705) made this pull request unmergeable. Please resolve the merge conflicts. |
b450d0d
to
412b862
Compare
@bors r+ Thanks for sticking around through all the review iterations. Great work! |
📌 Commit 412b862 has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fix `SAFETY` comment tag casing in undocumented_unsafe_blocks This changes the lint introduced in #7748 to suggest adding a `SAFETY` comment instead of a `Safety` comment. Searching for `// Safety:` in rust-lang/rust yields 67 results while `// SAFETY:` yields 1072. I think it's safe to say that this comment tag is written in upper case, just like `TODO`, `FIXME` and so on are. As such I would expect this lint to follow the official convention as well. Note that I intentionally introduced some casing diversity in `tests/ui/undocumented_unsafe_blocks.rs` to test more cases than just `Safety:`. changelog: Capitalize `SAFETY` comment in [`undocumented_unsafe_blocks`]
changelog: Added a new lint [
undocumented_unsafe_blocks
]Fixes #7464, #7238 (?)