Skip to content

Commit df1f0d2

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. Backport of a8b990a
1 parent e53c9fc commit df1f0d2

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.
@@ -1930,7 +1924,8 @@ impl InteractiveTxMessageSend {
19301924
// This macro executes a state machine transition based on a provided action.
19311925
macro_rules! do_state_transition {
19321926
($self: ident, $transition: ident, $msg: expr) => {{
1933-
let state_machine = core::mem::take(&mut $self.state_machine);
1927+
let mut state_machine = StateMachine::Indeterminate;
1928+
core::mem::swap(&mut state_machine, &mut $self.state_machine);
19341929
$self.state_machine = state_machine.$transition($msg);
19351930
match &$self.state_machine {
19361931
StateMachine::NegotiationAborted(state) => Err(state.0.clone()),

0 commit comments

Comments
 (0)