rust-lang / rust-lang/rust-clippy

move expect from `allow_attributes_without_reason` to it's own lint

Open
#17,409 5 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

Currently allow_attributes works only on allow, but doesn't trigger on expect.
The allow_attributes_without_reason works differently, it applies to both allow and expect.

It would be nice if these could be set separately, so that allow_attributes_without_reason only applied to
#[allow()] and expect_attributes_without_reason could apply the same logic to expect.

Advantage

The allow_attributes lint is too much for many cases, such as when you conditionally need an allow in a #[cfg()] where #[expect(...)] is too strong.

We would like to be able to use:

#[allow(...) reason = "...."]
#[expect(something_else)]

but erroring on

#[allow(some_other_thing)]

Moving expect_attributes_without_reason to it's own lint would allow this kind of flexibility.

Drawbacks

People relying on the current behavior of allow_attributes_without_reason need to enable another lint to keep that behavior.

Example
<code>

Could be written as:

<code>
Comparison with existing lints

No response

Additional Context

No response

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 tracing the existing allow_attributes_without_reason lint and its tests to understand how it handles both allow and expect attributes. Separate the expect behavior into expect_attributes_without_reason, preserve the existing behavior for allow, and verify both lints cover the requested examples and configuration cases.

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
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.