Skip to content

Commit a8b990a

Browse files
committed
Replace StateMachine::default use with core::mem::replace
`clippy` now complains that `Default` for the interactive tx constructor `StateMachine` can be auto-derived, but its a bit weird to have a `Default` that loads an invalid ("indeterminate") state. Instead, we replace the one line that actually cares about the `Default` (which uses `core::mem::take`) with `core::mem::replace`, making it more explict.
1 parent 7adc624 commit a8b990a

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

lightning/src/ln/interactivetxs.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,12 +1492,6 @@ enum StateMachine {
14921492
NegotiationAborted(NegotiationAborted),
14931493
}
14941494

1495-
impl Default for StateMachine {
1496-
fn default() -> Self {
1497-
Self::Indeterminate
1498-
}
1499-
}
1500-
15011495
// The `StateMachine` internally executes the actual transition between two states and keeps
15021496
// track of the current state. This macro defines _how_ those state transitions happen to
15031497
// update the internal state.
@@ -1932,7 +1926,8 @@ impl InteractiveTxMessageSend {
19321926
// This macro executes a state machine transition based on a provided action.
19331927
macro_rules! do_state_transition {
19341928
($self: ident, $transition: ident, $msg: expr) => {{
1935-
let state_machine = core::mem::take(&mut $self.state_machine);
1929+
let mut state_machine = StateMachine::Indeterminate;
1930+
core::mem::swap(&mut state_machine, &mut $self.state_machine);
19361931
$self.state_machine = state_machine.$transition($msg);
19371932
match &$self.state_machine {
19381933
StateMachine::NegotiationAborted(state) => Err(state.0.clone()),

0 commit comments

Comments
 (0)