Skip to content

FP for allow_attributes_without_reason with ? operator #10377

Closed
@base0x10

Description

@base0x10

Summary

Use of ? on results and options triggers allow_attributes_without_reason.

The specific type of the options and results in the reproduction aren't important. I first observed the FP using ? on fmt::Results.

I suspect, similar to #9630 we need to filter out findings that originate in builtins or std. That said, I don't see a specific macro or allow that is triggering this.

Lint Name

allow_attributes_without_reason

Reproducer

I tried this code:
(each line that triggers the lint will also individually trigger the lint)

#![warn(clippy::allow_attributes_without_reason)]
#![feature(lint_reasons)]

pub fn trigger_fp_option() -> Option<()>{
    Some(())?;      // Triggers lint
    None?;          // Triggers lint
    Some(())
}

pub fn trigger_fp_result() -> Result<(), &'static str> {
    Ok(())?;        // Triggers lint
    Err("asdf")?;   // Triggers lint
    Ok(())
}

I saw this happen:

warning: `allow` attribute without specifying a reason
 --> src/lib.rs:5:5
  |
5 |     Some(())?;      // Triggers lint
  |     ^^^^^^^^^
  |
  = help: try adding a reason at the end with `, reason = ".."`
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#allow_attributes_without_reason
note: the lint level is defined here
 --> src/lib.rs:1:9
  |
1 | #![warn(clippy::allow_attributes_without_reason)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: `allow` attribute without specifying a reason
 --> src/lib.rs:6:5
  |
6 |     None?;          // Triggers lint
  |     ^^^^^
  |
  = help: try adding a reason at the end with `, reason = ".."`
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#allow_attributes_without_reason

warning: `allow` attribute without specifying a reason
  --> src/lib.rs:11:5
   |
11 |     Ok(())?;        // Triggers lint
   |     ^^^^^^^
   |
   = help: try adding a reason at the end with `, reason = ".."`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#allow_attributes_without_reason

warning: `allow` attribute without specifying a reason
  --> src/lib.rs:12:5
   |
12 |     Err("asdf")?;   // Triggers lint
   |     ^^^^^^^^^^^^
   |
   = help: try adding a reason at the end with `, reason = ".."`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#allow_attributes_without_reason

I expected to see this happen:
No lints trigger

Version

rustc 1.69.0-nightly (4507fdaaa 2023-02-18)
binary: rustc
commit-hash: 4507fdaaa27ea2fb59a41df2ce7d1f290da53dae
commit-date: 2023-02-18
host: x86_64-unknown-linux-gnu
release: 1.69.0-nightly
LLVM version: 15.0.7

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions