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

iter_without_into_iter fires on code generated by macros from other crates #12037

Closed
jyn514 opened this issue Dec 28, 2023 · 4 comments · Fixed by #12054
Closed

iter_without_into_iter fires on code generated by macros from other crates #12037

jyn514 opened this issue Dec 28, 2023 · 4 comments · Fixed by #12054
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have T-macros Type: Issues with macros and macro expansion

Comments

@jyn514
Copy link
Member

jyn514 commented Dec 28, 2023

Summary

iter_without_into_iter fires on external macros.

Lint Name

iter_without_into_iter

Reproducer

I tried this code with bitflags version 2.3.2 (note that later versions may not reproduce the lint):

#![warn(clippy::pedantic)]

bitflags::bitflags! {
    pub struct HttpComponents: u16 {
        const REQUEST_RESPONSE = 1 << 0;
    }
}

I saw this happen:

warning: `iter` method without an `IntoIterator` impl for `&$BitFlags`
  --> src/main.rs:4:1
   |
4  | / bitflags! {
5  | |     ///  Configuration for HTTP metadata fields.
6  | |     #[derive(Copy, Clone)]
7  | |     pub struct HttpComponents: u16 {
...  |
18 | |     }
19 | | }
   | |_^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#iter_without_into_iter
   = note: this warning originates in the macro `__impl_public_bitflags_iter` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info)

I expected to see this happen: No warning, because this is not code I can change.

Version

clippy 0.1.75 (82e1608d 2023-12-21)
rustc 1.75.0 (82e1608df 2023-12-21)

Additional Labels

No response

@jyn514 jyn514 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 Dec 28, 2023
@jyn514
Copy link
Member Author

jyn514 commented Dec 28, 2023

there's a further issue here that there's nowhere to put the #[allow()] attribute. putting it on the macro invocation does nothing (and warns that it's ignored), putting it on the struct means it's expanded the macro and shows up on the struct itself but not the impl block that defines fn iter.

going to put it at the module level for now - i think this makes a good case for never firing lints in foreign macros tbh, since you can't apply attributes to them.

@jyn514
Copy link
Member Author

jyn514 commented Dec 28, 2023

i wonder if rustc in general (not just clippy) could - instead of ignoring the attribute - for lints specifically, apply the lint level to all code generated by the macro.

@blyxyas blyxyas added the good-first-issue These issues are a good way to get started with Clippy label Dec 28, 2023
@Xuanwo
Copy link

Xuanwo commented Dec 29, 2023

#12039 seems also related to this: Lint that emitted against an external type.

@m-rph
Copy link
Contributor

m-rph commented Dec 29, 2023

@rustbot label +T-macros

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 good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants