Skip to content

Conversation

teofr
Copy link
Contributor

@teofr teofr commented Sep 15, 2025

The way clippy checked for SAFETY comments above attributes was wrong:

  • It wasn't considered for items
  • It cause an ICE with some attributes
  • When considering comments above attributes, it didn't considered comments below them, causing some unlintable situations.

This PR tries to fix this by delegating the skipping of attributes to the function analyzing the source code itself.

changelog: [unnecessary_safety_comment]: Taking into account comments above attributes for items

Fixes #14555
Fixes #15684
Fixes #15754

Copy link

github-actions bot commented Sep 24, 2025

Lintcheck changes for c7b79d8

Lint Added Removed Changed
clippy::undocumented_unsafe_blocks 0 18 1
clippy::unnecessary_safety_comment 16 0 2

This comment will be updated if you push new changes

@teofr
Copy link
Contributor Author

teofr commented Sep 24, 2025

I checked all the removed/added lints and they all make sense to me

  • All of the removed undocumented_unsafe_block are correct, and shouldn'te have been there in the first place
  • Most of the added unnecesary_safety_comment are because a // SAFETY: comment is used in an unsafe fn. Maybe we should improve the lint message in these cases to suggest a // # Safety comment instead
  • One is a SAFETY comment on a struct, which I think is correctly linted
  • One is a bug that's been uncovered by this PR but was present already (unnecessary_safety_comment and undocumented_unsafe_blocks visit the same comment twice #15755)
  • The changes are a bit strange, basically some notes regarding why the lint is enabled are deleted or added, does anyone know what could cause this?

@teofr teofr marked this pull request as ready for review September 24, 2025 15:14
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 24, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 24, 2025

r? @samueltardieu

rustbot has assigned @samueltardieu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@teofr teofr changed the title [unnecessary_safety_comment] Considering comments above attributes for items [unnecessary_safety_comment] Some fixes regarding comments above attributes Sep 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
3 participants