Skip to content
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

Merged
merged 1 commit into from
Oct 8, 2021

Conversation

Serial-ATA
Copy link
Contributor

@Serial-ATA Serial-ATA commented Oct 2, 2021

changelog: Added a new lint [undocumented_unsafe_blocks]

Fixes #7464, #7238 (?)

@rust-highfive
Copy link

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.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Oct 2, 2021
@xFrednet
Copy link
Member

xFrednet commented Oct 2, 2021

Welcome to the project, it's nice to see that you got a working implementation 🙃.

@flip1995 would you maybe like to review this, as you've also reviewed #7557? Otherwise, I'll have a look at it during the next week 🙃

@flip1995
Copy link
Member

flip1995 commented Oct 2, 2021

Yes, sure. I have time this afternoon.

r? @flip1995

@rust-highfive rust-highfive assigned flip1995 and unassigned xFrednet Oct 2, 2021
Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I had to guess, I assume, that you didn't look at #7557 before implementing this?

I think your approach and the approach taken in #7557 combined would be ideal. I left comments about that below. IMO the work done in #7557 is really valuable. The PR was only closed, because it was inactive.

clippy_lints/src/undocumented_unsafe_block_safety.rs Outdated Show resolved Hide resolved
clippy_lints/src/undocumented_unsafe_block_safety.rs Outdated Show resolved Hide resolved
clippy_lints/src/undocumented_unsafe_block_safety.rs Outdated Show resolved Hide resolved
tests/ui/undocumented_unsafe_block_safety.stderr Outdated Show resolved Hide resolved
clippy_lints/src/undocumented_unsafe_block_safety.rs Outdated Show resolved Hide resolved
clippy_lints/src/undocumented_unsafe_block_safety.rs Outdated Show resolved Hide resolved
clippy_lints/src/undocumented_unsafe_block_safety.rs Outdated Show resolved Hide resolved
clippy_lints/src/undocumented_unsafe_block_safety.rs Outdated Show resolved Hide resolved
@bors
Copy link
Contributor

bors commented Oct 3, 2021

☔ The latest upstream changes (presumably #7709) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link

@ShadowJonathan ShadowJonathan left a 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)
};

clippy_lints/src/undocumented_unsafe_blocks.rs Outdated Show resolved Hide resolved
@Serial-ATA Serial-ATA force-pushed the lint-undocumented-unsafe branch from 070833f to f3934ed Compare October 3, 2021 19:23
@Serial-ATA Serial-ATA requested a review from flip1995 October 3, 2021 19:24
Copy link
Member

@flip1995 flip1995 left a 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.

clippy_lints/src/undocumented_unsafe_blocks.rs Outdated Show resolved Hide resolved
tests/ui/undocumented_unsafe_blocks.rs Show resolved Hide resolved
clippy_lints/src/undocumented_unsafe_blocks.rs Outdated Show resolved Hide resolved
tests/ui/undocumented_unsafe_blocks.rs Outdated Show resolved Hide resolved
tests/ui/undocumented_unsafe_blocks.rs Show resolved Hide resolved
tests/ui/undocumented_unsafe_blocks.rs Show resolved Hide resolved
clippy_lints/src/undocumented_unsafe_blocks.rs Outdated Show resolved Hide resolved
clippy_lints/src/undocumented_unsafe_blocks.rs Outdated Show resolved Hide resolved
@Serial-ATA Serial-ATA changed the title Add undocumented_unsafe_block_safety lint Add undocumented_unsafe_blocks lint Oct 4, 2021
@Serial-ATA Serial-ATA force-pushed the lint-undocumented-unsafe branch from 670e2a1 to 59d93c5 Compare October 4, 2021 23:24
Copy link
Member

@flip1995 flip1995 left a 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

clippy_lints/src/undocumented_unsafe_blocks.rs Outdated Show resolved Hide resolved
clippy_lints/src/undocumented_unsafe_blocks.rs Outdated Show resolved Hide resolved
clippy_lints/src/undocumented_unsafe_blocks.rs Outdated Show resolved Hide resolved
clippy_lints/src/undocumented_unsafe_blocks.rs Outdated Show resolved Hide resolved
@flip1995 flip1995 added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Oct 5, 2021
@ShadowJonathan
Copy link

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

@Serial-ATA Serial-ATA force-pushed the lint-undocumented-unsafe branch from abe480f to 760115c Compare October 5, 2021 22:24
@bors
Copy link
Contributor

bors commented Oct 6, 2021

☔ The latest upstream changes (presumably #7773) made this pull request unmergeable. Please resolve the merge conflicts.

@flip1995
Copy link
Member

flip1995 commented Oct 6, 2021

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 span_until_char function ( or similar functions)

@Serial-ATA Serial-ATA force-pushed the lint-undocumented-unsafe branch from 760115c to b450d0d Compare October 6, 2021 22:22
@flip1995
Copy link
Member

flip1995 commented Oct 7, 2021

Looks great now! Could you address the multi-line unsafe block case? After that this should be good to go. 🚀

@Serial-ATA
Copy link
Contributor Author

Did I not take care of that? The no_comment_match and internal_comment tests only show the first line now.

@flip1995
Copy link
Member

flip1995 commented Oct 7, 2021

Did I not take care of that? The no_comment_match and internal_comment tests only show the first line now.

Oh I missed that. In that case all good 👍

(no_comment_match doesn't test that, because the unsafe block is still empty and all on one line in this test case, but the other test case does)

@flip1995
Copy link
Member

flip1995 commented Oct 7, 2021

Please squash some commits, so that we can merge this.

@bors
Copy link
Contributor

bors commented Oct 7, 2021

☔ The latest upstream changes (presumably #7705) made this pull request unmergeable. Please resolve the merge conflicts.

@Serial-ATA Serial-ATA force-pushed the lint-undocumented-unsafe branch from b450d0d to 412b862 Compare October 7, 2021 21:06
@flip1995
Copy link
Member

flip1995 commented Oct 8, 2021

@bors r+

Thanks for sticking around through all the review iterations. Great work!

@bors
Copy link
Contributor

bors commented Oct 8, 2021

📌 Commit 412b862 has been approved by flip1995

@bors
Copy link
Contributor

bors commented Oct 8, 2021

⌛ Testing commit 412b862 with merge 78e7312...

@bors
Copy link
Contributor

bors commented Oct 8, 2021

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: flip1995
Pushing 78e7312 to master...

@bors bors merged commit 78e7312 into rust-lang:master Oct 8, 2021
@Serial-ATA Serial-ATA deleted the lint-undocumented-unsafe branch October 8, 2021 13:48
bors added a commit that referenced this pull request Dec 20, 2021
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`]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

missing_unsafe_doc, explain why an unsafe block is safe/sound
6 participants