-
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
missing_unsafe_doc
, explain why an unsafe
block is safe/sound
#7464
Comments
I would like to have this as it also improves overall crate quality as people who are less familiar with the code inside of unsafe (as it can be a C binding for example) would get a better understanding of this code which I think is overall leading to better documentation quality for contributors of crates. |
This also works really well with the |
I'll try to take a stab at this. @rustbot claim |
The PR has been closed due to inactivity. My understanding is that @LeSeulArtichaut will not continue to work on this for now. I'll therefore unassign him. The PR still looks like a good starting point if someone else wants to take over 🙃 |
I'll try. @rustbot claim |
Should this check all unsafe blocks or just those in safe functions? |
It would make sense to have it on every unsafe block IMO. 🙃 |
I've got it working, but I can't figure out how to do the suggestion. format!("// Safety: ...\n{}", snippet(cx, block.span, "..")) The newline breaks the snippet line.
Should I not be using |
Every one, yes, unconditionally. Unless it's explicitly opted out ( |
For this lint you can just use |
One thing i'm not sure about is if the suggestion will clash with all-uppercase |
Thanks, that had me confused for awhile.
What I have now doesn't care about case since I saw your examples used "Safety" and #7557 uses "SAFETY" |
Nevermind, I finally figured it out :) QuestionI assume you'd also want to accept// Safety: ...
let _ = unsafe {}; over let _ =
// Safety: ...
unsafe {} but since I'm using |
Yup, would make sense. Though i think it'd get complicated once it gets nested enough (think |
What it does
Kinda like
missing_safety_doc
, but this lint would warn about a missing comment on eachunsafe {}
block, for which a comment must exist explaining why theunsafe
block is safe/sound.Categories (optional)
style
What is the advantage of the recommended code over the original code
There'd be no recommended code, but the lint would suggest adding
// Safety: [...]
To the new code as a start. The lint would also raise a warning if that comment is copied verbatim.
Drawbacks
This would be rather bothersome to those who know what they're doing, or only make small
unsafe
blocks all around.Example
Could be written as:
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.);The text was updated successfully, but these errors were encountered: