Skip to content

clippy::for_loop_over_option triggers on quote! macro expansion #3696

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

Closed
elinorbgr opened this issue Jan 25, 2019 · 2 comments
Closed

clippy::for_loop_over_option triggers on quote! macro expansion #3696

elinorbgr opened this issue Jan 25, 2019 · 2 comments
Labels
C-bug Category: Clippy is not doing the correct thing T-macros Type: Issues with macros and macro expansion

Comments

@elinorbgr
Copy link

Using cargo clippy from stable: clippy 0.0.212 (b2601be 2018-11-27)

The lint apparently triggers on the result of expansion of quote!(..):

error: for loop over `$ single`, which is an `Option`. This is more readably written as an `if let` statement.
   --> wayland-scanner/src/common_gen.rs:794:21
    |
794 |       let prototype = quote! {
    |  _____________________^
795 | |         pub fn #fn_name#(<#generics>)*(&self, #(#args),*) -> #return_type #where_bounds
796 | |     };
    | |_____^
    |
    = note: #[deny(clippy::for_loop_over_option)] on by default
    = help: consider replacing `for $ first in $ single` with `if let Some($ first) = $ single`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#for_loop_over_option
    = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

The relevant code invoking quote!() is here: https://github.com/Smithay/wayland-rs/blob/5600194a6b614413194bfda09fc438fc5c45a792/wayland-scanner/src/common_gen.rs#L794-L796

I suppose this is a bug, given I don't expect clippy to trigger on the expansion of macros from my dependencies.

@phansch phansch added C-bug Category: Clippy is not doing the correct thing T-macros Type: Issues with macros and macro expansion labels Jan 25, 2019
@phansch
Copy link
Member

phansch commented Jan 25, 2019

That's a bug, yup! Thanks for the report

@phansch phansch self-assigned this Jan 26, 2019
@phansch
Copy link
Member

phansch commented Jan 26, 2019

This has already been fixed by #3577. The fix should be included in the next Rust stable release (1.33)

@phansch phansch closed this as completed Jan 26, 2019
@phansch phansch removed their assignment Jan 26, 2019
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 T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

No branches or pull requests

2 participants