-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-bugIssue: The suggestion compiles but changes the code to behave in an unintended wayIssue: The suggestion compiles but changes the code to behave in an unintended way
Description
Summary
Without much context, I have the following code:
if connectivity.is_offline() {
NextTunnelState::SameState(self)
} else {
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows"))]
Self::reset_dns(shared_state).await;
if self.reconnect {
NextTunnelState::NewState(ConnectingState::enter(0, self.selected_gateways, shared_state).await)
} else {
NextTunnelState::NewState(DisconnectedState::enter(None, shared_state).await)
}
}
When compiling for aarch64-apple-ios
, clippy suggests to collapse the else block disregarding the platform code:
warning: this `else { if .. }` block can be collapsed
--> crates/nym-vpn-lib/src/tunnel_state_machine/states/offline_state.rs:143:24
|
143 | } else {
| ________________________^
144 | | #[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows"))]
145 | | Self::reset_dns(shared_state).await;
... |
152 | | }
| |_________________^
|
= 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
|
143 ~ } else if self.reconnect {
144 + NextTunnelState::NewState(ConnectingState::enter(0, self.selected_gateways, shared_state).await)
145 + } else {
146 + NextTunnelState::NewState(DisconnectedState::enter(None, shared_state).await)
147 + }
Which would result into code duplication which I am trying to avoid. (I do not mind nested if)
Lint Name
No response
Reproducer
I tried this code:
<code>
I saw this happen:
<output>
I expected to see this happen:
Version
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-bugIssue: The suggestion compiles but changes the code to behave in an unintended wayIssue: The suggestion compiles but changes the code to behave in an unintended way