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

New lint (unnecessary_safety_comment): reverse of undocumented_unsafe_blocks #7954

Closed
Tracked by #79
ojeda opened this issue Nov 9, 2021 · 1 comment
Closed
Tracked by #79
Assignees
Labels
A-lint Area: New lints

Comments

@ojeda
Copy link
Contributor

ojeda commented Nov 9, 2021

What it does

Warns about unexpected // SAFETY: comments (i.e. the reverse of the undocumented_unsafe_blocks lint).

This lint is similar to #6880, which is requesting the reverse of missing_safety_docs.

Drawbacks

  • A project might also be using // SAFETY: comments to explain why safe code makes other unsafe code sound, e.g. within the module.

  • Potential false positives in general (depending on how it is implemented).

Example

// SAFETY: `x` is `Some`.
x.unwrap()

Could be written as:

x.unwrap()
@Veykril
Copy link
Member

Veykril commented Nov 14, 2022

@rustbot claim

bors added a commit that referenced this issue Nov 25, 2022
Lint unnecessary safety comments

changelog: [`unnecessary_safety_comment`]: Add unnecessary safety comment lint

Addresses #7954

This does not necessarily catch all occurences, as doing so would require checking all expressions in the entire source which seems rather expensive. Instead what the lint does is it checks items, statements and the tail expression of blocks for safety comments, then checks if those comments are necessary or not, then linting for the unnecessary ones.

I kept the tests in one file to check that the lints do not clash with each other.
@ojeda ojeda changed the title New lint: reverse of undocumented_unsafe_blocks New lint (unnecessary_safety_comment): reverse of undocumented_unsafe_blocks Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

No branches or pull requests

3 participants