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

match_like_matches_macro ignores #[cfg()] attribute in suggestion #6289

Closed
matthiaskrgr opened this issue Nov 4, 2020 · 0 comments · Fixed by #6290
Closed

match_like_matches_macro ignores #[cfg()] attribute in suggestion #6289

matthiaskrgr opened this issue Nov 4, 2020 · 0 comments · Fixed by #6290
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@matthiaskrgr
Copy link
Member

Code from cargo

 pub(super) fn error_unsupported(err: &Error) -> bool {
        match err.raw_os_error() {
            Some(libc::ENOTSUP) => true,
            #[cfg(target_os = "linux")]
            Some(libc::ENOSYS) => true,
            _ => false,
        }
    }

clippy will suggest

warning: match expression looks like `matches!` macro
   --> src/cargo/util/flock.rs:376:9
    |
376 | /         match err.raw_os_error() {
377 | |             Some(libc::ENOTSUP) => true,
378 | |             #[cfg(target_os = "linux")]
379 | |             Some(libc::ENOSYS) => true,
380 | |             _ => false,
381 | |         }
    | |_________^ help: try this: `matches!(err.raw_os_error(), Some(libc::ENOTSUP) | Some(libc::ENOSYS))`
    |
    = note: `#[warn(clippy::match_like_matches_macro)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro

Note that it does not take the #[cfg] attributes into account, blindly applying the suggestion would alter semantics.

clippy 0.0.212 (601c13c 2020-11-04)

@matthiaskrgr matthiaskrgr added C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied labels Nov 4, 2020
bors added a commit that referenced this issue Nov 6, 2020
do not trigger MATCH_LIKE_MATCHES_MACRO lint with attrs

fixed #6289
changelog: do not trigger MATCH_LIKE_MATCHES_MACRO lint for arms with attrs
@bors bors closed this as completed in b627731 Nov 28, 2020
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-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant