Skip to content

False positive for collapsible_match with cfg feature usage #16916

@catenacyber

Description

@catenacyber

Summary

Same as #15158

Running cargo clippy on suricata rust subdirectory now prints

error: expected one of `=>`, `@`, `if`, or `|`, found `SCLogDebug`
   --> src/smb/smb1.rs:722:13
    |
721 |         SMB1_COMMAND_NT_CREATE_ANDX
    |                                    - expected one of `=>`, `@`, `if`, or `|`
722 |             SCLogDebug!("SMB1_COMMAND_NT_CREATE_ANDX response {:08x}", r.nt_status);
    |             ^^^^^^^^^^ unexpected token

error: expected one of `=>`, `if`, or `|`, found `SCLogDebug`
   --> src/ike/ikev2.rs:139:25
    |
138 |                     IkeV2PayloadContent::KE(ref kex)
    |                                                     - expected one of `=>`, `if`, or `|`
139 |                         SCLogDebug!("KEX {:?}", kex.dh_group);
    |                         ^^^^^^^^^^ unexpected token

error: aborting due to 2 previous errors

Original diagnostics will follow.

warning: this `if` can be collapsed into the outer `match`
   --> src/smb/smb1.rs:723:13
    |
723 | /             if r.nt_status == SMB_NTSTATUS_SUCCESS {
724 | |                 match parse_smb_create_andx_response_record(&r.data[*andx_offset-SMB1_HEADER_SIZE..]) {
725 | |                     Ok((_, cr)) => {
726 | |                         SCLogDebug!("Create AndX {:?}", cr);
...   |
765 | |                 false
766 | |             }
    | |_____________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#collapsible_match
    = note: `#[warn(clippy::collapsible_match)]` on by default
help: collapse nested if block
    |
721 ~         SMB1_COMMAND_NT_CREATE_ANDX
722 |             SCLogDebug!("SMB1_COMMAND_NT_CREATE_ANDX response {:08x}", r.nt_status);
723 ~             if r.nt_status == SMB_NTSTATUS_SUCCESS => {
724 |                 match parse_smb_create_andx_response_record(&r.data[*andx_offset-SMB1_HEADER_SIZE..]) {
...
763 |                 }
764 ~             },
    |

warning: this `if` can be collapsed into the outer `match`
   --> src/ike/ikev2.rs:140:25
    |
140 | /                         if direction == Direction::ToClient {
141 | |                             state.ikev2_container.dh_group = kex.dh_group;
142 | |                         }
    | |_________________________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#collapsible_match
help: collapse nested if block
    |
138 ~                     IkeV2PayloadContent::KE(ref kex)
139 |                         SCLogDebug!("KEX {:?}", kex.dh_group);
140 ~                         if direction == Direction::ToClient => {
141 |                             state.ikev2_container.dh_group = kex.dh_group;
142 ~                         }
    |

Reproducer

Code:

use std::env;

#[cfg(feature = "debug")]
#[macro_export]
macro_rules!print_debug {
    ($($arg:tt)*) => {
        println!($($arg)*);
    }
}

#[cfg(not(feature = "debug"))]
#[macro_export]
macro_rules!print_debug {
    ($($arg:tt)*) => {};
}


fn main() {
    match env::args().len() {
        2 => {
            println!("Not enough many");
        }
        3 => {
            print_debug!("Let's go");
            if env::args().len() > 5 {
                println!("So many");
            }
        }
        _ => {}
    }
}

Current output:

    Checking clippy v0.1.0 (/suricata/clippy)
warning: failed to automatically apply fixes suggested by rustc to crate `clippy`

after fixes were automatically applied the compiler reported errors within these files:

  * src/main.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust-clippy/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:
error: expected one of `...`, `..=`, `..`, `=>`, `if`, or `|`, found `print_debug`
  --> src/main.rs:24:13
   |
23 |         3
   |          - expected one of `...`, `..=`, `..`, `=>`, `if`, or `|`
24 |             print_debug!("Let's go");
   |             ^^^^^^^^^^^ unexpected token

error: aborting due to 1 previous error

Original diagnostics will follow.

warning: this `if` can be collapsed into the outer `match`
  --> src/main.rs:25:13
   |
25 | /             if env::args().len() > 5 {
26 | |                 println!("So many");
27 | |             }
   | |_____________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#collapsible_match
   = note: `#[warn(clippy::collapsible_match)]` on by default
help: collapse nested if block
   |
23 ~         3
24 |             print_debug!("Let's go");
25 ~             if env::args().len() > 5 => {
26 |                 println!("So many");
27 ~             }
   |

warning: `clippy` (bin "clippy") generated 1 warning (run `cargo clippy --fix --bin "clippy" -p clippy -- --no-deps` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.13s

Desired output:

Version

rustc 1.95.0 (59807616e 2026-04-14)
binary: rustc
commit-hash: 59807616e1fa2540724bfbac14d7976d7e4a3860
commit-date: 2026-04-14
host: aarch64-apple-darwin
release: 1.95.0
LLVM version: 22.1.2

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions