Open
Description
Summary
Running cargo clippy
on suricata rust subdirectory now prints
warning: this `else { if .. }` block can be collapsed
--> src/smb/smb.rs:1794:52
|
1794 | ... } else {
| ______________________________^
1795 | | ... SCLogDebug!("SMB1 request seen from server to client");
1796 | | ... if let Some(frame) = pdu_frame {
1797 | | ... frame.add_event(flow, SMBEvent::RequestToClient as u8);
1798 | | ... }
1799 | | ... }
| |_______________________^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_else_if
= note: `#[warn(clippy::collapsible_else_if)]` on by default
help: collapse nested if block
|
1794 ~ } else if let Some(frame) = pdu_frame {
1795 + frame.add_event(flow, SMBEvent::RequestToClient as u8);
1796 + }
|
But we do want the SCLogDebug!
to print a log in debug mode
cargo clippy --features debug
does not show this.
Lint Name
collapsible_else_if
Reproducer
I tried this 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() {
if env::args().len() < 2 {
println!("Not enough many");
} else {
print_debug!("Let's go");
if env::args().len() > 2 {
println!("So many");
}
}
}
I saw this happen:
warning: this `else { if .. }` block can be collapsed
--> src/main.rs:21:12
|
21 | } else {
| ____________^
22 | | print_debug!("Let's go");
23 | | if env::args().len() > 2 {
24 | | println!("So many");
25 | | }
26 | | }
| |_____^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_else_if
= note: `#[warn(clippy::collapsible_else_if)]` on by default
help: collapse nested if block
|
21 ~ } else if env::args().len() > 2 {
22 + println!("So many");
23 + }
|
I expected to see this happen:
Nothing printed
Version
rustc 1.88.0 (6b00bc388 2025-06-23)
binary: rustc
commit-hash: 6b00bc3880198600130e1cf62b8f8a93494488cc
commit-date: 2025-06-23
host: x86_64-apple-darwin
release: 1.88.0
LLVM version: 20.1.5
Additional Labels
No response