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

unfulfilled_lint_expectations in combination with proc macro [wasm_bingen] #14008

Open
threema-theo opened this issue Jan 16, 2025 · 1 comment
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@threema-theo
Copy link

threema-theo commented Jan 16, 2025

Summary

clippy throws false positives when using a proc macro (I only tested with [wasm_bindgen].

I further observed the following:

  • Removing #[wasm_bindgen] removes the false positive
  • Removing #[expect(...)] correctly throws warnings
  • Replacing #[expect(...)] with #[allow(...)] correctly removes the warnings.

I'm not 100% sure whether it is a problem of clippy or wasm-bindgen. Please tell me if the latter should be the case.

Lint Name

unfulfilled_lint_expectations

Reproducer

I tried this code:

#![warn(clippy::missing_panics_doc)]
#![warn(clippy::missing_errors_doc)]


use wasm_bindgen::prelude::wasm_bindgen;

#[expect(clippy::missing_panics_doc, reason = "mock example")]
#[wasm_bindgen]
pub fn panic() {
    panic!("Here we go");
}

#[expect(clippy::missing_errors_doc, reason = "mock example")]
#[wasm_bindgen]
pub fn error() -> Result<usize, usize> {
    Err(1)
}

I saw this happen:

    Checking playground v0.0.1 (/playground)
warning: this lint expectation is unfulfilled
 --> src/main.rs:7:10
  |
7 | #[expect(clippy::missing_panics_doc, reason = "mock example")]
  |          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: mock example
  = note: `#[warn(unfulfilled_lint_expectations)]` on by default

warning: this lint expectation is unfulfilled
  --> src/main.rs:13:10
   |
13 | #[expect(clippy::missing_errors_doc, reason = "mock example")]
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: mock example

warning: `playground` (bin "playground") generated 2 warnings
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.05s

I expected to see this happen: Clippy throws no warnings.

When I remove the expect macros, Clippy correctly throws the warnings.

Version

1.86.0-nightly
2025-01-15 419b3e2d3e350822550e

(see playground)

Additional Labels

No response

@threema-theo threema-theo added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jan 16, 2025
samueltardieu added a commit to samueltardieu/wasm-bindgen that referenced this issue Jan 16, 2025
An `#[expect]` outer attribute must not be kept in the
`#[automatically_derived]` code, as the expanded code will probably not
meet the expectations. Transforming it into the equivalent `#[allow]`
attribute is the safest way to ensure that expected attributes will not
trigger a warning.

Noticed through a bug report entered at the Clippy reposityory at
<rust-lang/rust-clippy#14008>.
samueltardieu added a commit to samueltardieu/wasm-bindgen that referenced this issue Jan 16, 2025
An `#[expect]` outer attribute must not be kept in the
`#[automatically_derived]` code, as the expanded code will probably not
meet the expectations. Transforming it into the equivalent `#[allow]`
attribute is the safest way to ensure that expected attributes will not
trigger a warning.

Noticed through a bug report entered at the Clippy repository at
<rust-lang/rust-clippy#14008>.
@samueltardieu
Copy link
Contributor

wasm_bindgen applies identical outer attributes to the autogenerated code, which will not fullfill the expectations. I have proposed a patch to wasm_bindgen which transforms those attribute into equivalent #[allow] attributes in rustwasm/wasm-bindgen#4409.

samueltardieu added a commit to samueltardieu/wasm-bindgen that referenced this issue Jan 16, 2025
An `#[expect]` outer attribute must not be kept in the
`#[automatically_derived]` code, as the expanded code will probably not
meet the expectations. Transforming it into the equivalent `#[allow]`
attribute is the safest way to ensure that expected attributes will not
trigger a warning.

Noticed through a bug report entered at the Clippy repository at
<rust-lang/rust-clippy#14008>.
@samueltardieu samueltardieu self-assigned this Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

2 participants