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

Contents of expanded derive macro are being checked and errors generated #14063

Open
lukidoescode opened this issue Jan 22, 2025 · 1 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

Comments

@lukidoescode
Copy link

Summary

I believe this might be related to

A user has already commented on that ticket that the fix did not solve the issue for them.

Here's what this looks like:
Image
This screenshot is from an IDE, so you can see the code and the resulting lint error at the same time.

Here's what that looks like in the terminal:

error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
  --> <redacted>/src/cli/config.rs:15:38
   |
15 | #[derive(Debug, Clone, clap::Parser, derive_getters::Getters)]
   |                                      ^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ref_option
note: the lint level is defined here
  --> <redacted>/src/main.rs:1:22
   |
1  | #![deny(clippy::all, clippy::pedantic)]
   |                      ^^^^^^^^^^^^^^^^
   = note: `#[deny(clippy::ref_option)]` implied by `#[deny(clippy::pedantic)]`
   = note: this error originates in the derive macro `derive_getters::Getters` (in Nightly builds, run with -Z macro-backtrace for more info)

Lint Name

#[deny(clippy::ref_option)]

Reproducer

I tried this code:

#[derive(Debug, Clone, clap::Parser, derive_getters::Getters)]
pub struct Config {
    ...
}

I saw this happen:

error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>`
  --> worker-runner/src/cli/config.rs:15:38
   |
15 | #[derive(Debug, Clone, clap::Parser, derive_getters::Getters)]
   |                                      ^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ref_option
note: the lint level is defined here
  --> worker-runner/src/main.rs:1:22
   |
1  | #![deny(clippy::all, clippy::pedantic)]
   |                      ^^^^^^^^^^^^^^^^
   = note: `#[deny(clippy::ref_option)]` implied by `#[deny(clippy::pedantic)]`
   = note: this error originates in the derive macro `derive_getters::Getters` (in Nightly builds, run with -Z macro-backtrace for more info)

I expected to see this happen:

No error, since the lint is being violated within the code generated by a derive macro. I'd expect there to be a flag to enable checking in an expanded macro (useful for macro authoring). But I'd not expect macro expanded code to be checked by default, as those errors can only be fixed during the development of the macro and only by someone with rights to publish the macro.

Version

rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: aarch64-apple-darwin
release: 1.83.0
LLVM version: 19.1.1

Additional Labels

No response

@lukidoescode lukidoescode 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 22, 2025
@pac-work
Copy link

pac-work commented Jan 30, 2025

The same here for clippy::too_many_arguments. Any clues how to disable this for a specific expansion in the code? Now I bypassed this by changing settings for the whole module using #![allow(clippy::too_many_arguments)], but I do not find that to be a very good solution.

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