rust-lang / rust-lang/rust-clippy

Unsafe attributes support (`unnecessary_safety_comment`)

Open
#13,317 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

What it does

Unsafe attributes have been stabilized (https://github.com/rust-lang/rust/pull/128771, https://github.com/rust-lang/rust/issues/123757), thus it would be nice to have a lint that ensures // SAFETY comments are not written for safe attributes.

Since unnecessary_safety_comment covers impls too, perhaps it should also cover this too, although it may be best to possibly split them (but that is a different issue).

See https://github.com/rust-lang/rust-clippy/issues/13316 as well.

Advantage

No response

Drawbacks

No response

Example
// SAFETY: ...
#[derive(Debug)]
struct S;

Should be written as:

#[derive(Debug)]
struct S;

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the existing unnecessary_safety_comment lint and its tests in rust-clippy, then inspect how it handles impls and unsafe attributes. Add coverage for a safe attribute such as #[derive(Debug)] preceded by a // SAFETY comment, and verify that the lint accepts the version without the comment.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.