Skip to content

Commit c3487a5

Browse files
Enforce stricter rustfmt rules to prevent style ambiguity (#10939)
by default rustfmt preserve local style, and Claude loves to add semi or bracket where there were none before, We should make the formatting more strict as this is a bit annoying to remind it constantly not to make unnecessary diff. ## Summary The PR is just updating https://github.com/paritytech/polkadot-sdk/blob/pg/stricter-rustfmt-rules/.rustfmt.toml every other changes are just the result of running the linter - Change `match_arm_leading_pipes` from "Preserve" to "Never" to enforce a single style - Change `trailing_semicolon` from false to true to enforce `return 42;` false unfortunately preserve the local style - Add `normalize_comments = true` to normalize comment spacing (e.g., `// comment` not `//comment`) - Add `normalize_doc_attributes = true` to enforce `///` over `#[doc = ""]` These changes ensure only one valid formatting style exists, reducing unnecessary diffs in pull requests caused by different but equally valid formatting styles. ## Not changed (for now) The following options also default to "Preserve" but were intentionally not changed due to (even) larger diff impact: - `group_imports` - Would enforce import grouping order (std → external → crate) but causes massive import reordering across the codebase - `hex_literal_case` - Would enforce `0xABCD` vs `0xabcd` consistency - edition 2024 - not sure what that change but it also probably create a big diff These could be considered in a future PR if the one-time diff cost is acceptable. --------- Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 02f16b7 commit c3487a5

File tree

1,041 files changed

+4526
-4725
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,041 files changed

+4526
-4725
lines changed

.rustfmt.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ imports_granularity = "Crate"
88
reorder_imports = true
99
# Consistency
1010
newline_style = "Unix"
11+
normalize_comments = true
12+
normalize_doc_attributes = true
1113
# Misc
1214
chain_width = 80
1315
spaces_around_ranges = false
1416
binop_separator = "Back"
1517
reorder_impl_items = false
16-
match_arm_leading_pipes = "Preserve"
18+
match_arm_leading_pipes = "Never"
1719
match_arm_blocks = false
1820
match_block_trailing_comma = true
1921
trailing_comma = "Vertical"
20-
trailing_semicolon = false
22+
trailing_semicolon = true
2123
use_field_init_shorthand = true
2224
# Format comments
2325
comment_width = 100

bridges/bin/runtime-common/src/extensions.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ where
105105
has_failed || !SubmitFinalityProofHelper::<T, I>::was_successful(bundled_block_number);
106106

107107
if !has_failed {
108-
return
108+
return;
109109
}
110110

111111
// let's slash registered relayer
@@ -176,7 +176,7 @@ where
176176
!SubmitParachainHeadsHelper::<T, ParachainsInstance>::was_successful(&update);
177177

178178
if !has_failed {
179-
return
179+
return;
180180
}
181181

182182
// let's slash registered relayer
@@ -465,7 +465,7 @@ mod tests {
465465
type ToPostDispatch = u64;
466466
fn validate(_who: &u64, call: &MockCall) -> (u64, TransactionValidity) {
467467
if call.data <= 1 {
468-
return (1, InvalidTransaction::Custom(1).into())
468+
return (1, InvalidTransaction::Custom(1).into());
469469
}
470470

471471
(1, Ok(ValidTransaction { priority: 1, ..Default::default() }))
@@ -493,7 +493,7 @@ mod tests {
493493
type ToPostDispatch = u64;
494494
fn validate(_who: &u64, call: &MockCall) -> (u64, TransactionValidity) {
495495
if call.data <= 2 {
496-
return (2, InvalidTransaction::Custom(2).into())
496+
return (2, InvalidTransaction::Custom(2).into());
497497
}
498498

499499
(2, Ok(ValidTransaction { priority: 2, ..Default::default() }))

bridges/bin/runtime-common/src/messages_benchmarking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn prepare_inbound_message<LaneId>(
4848

4949
// if we don't need a correct message, then we may just return some random blob
5050
if !params.is_successful_dispatch_expected {
51-
return vec![0u8; expected_size]
51+
return vec![0u8; expected_size];
5252
}
5353

5454
// else let's prepare successful message.

bridges/modules/beefy/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn verify_signatures<T: Config<I>, I: 'static>(
7575
if authority.verify(sig, &msg) {
7676
missing_signatures = missing_signatures.saturating_sub(1);
7777
if missing_signatures == 0 {
78-
break
78+
break;
7979
}
8080
} else {
8181
tracing::debug!(

bridges/modules/grandpa/src/call_ext.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl<T: Config<I>, I: 'static> SubmitFinalityProofHelper<T, I> {
154154
"Cannot finalize obsolete header"
155155
);
156156

157-
return Err(Error::<T, I>::OldHeader)
157+
return Err(Error::<T, I>::OldHeader);
158158
},
159159
};
160160

@@ -168,7 +168,7 @@ impl<T: Config<I>, I: 'static> SubmitFinalityProofHelper<T, I> {
168168
"Cannot finalize header signed by unknown authority set"
169169
);
170170

171-
return Err(Error::<T, I>::InvalidAuthoritySetId)
171+
return Err(Error::<T, I>::InvalidAuthoritySetId);
172172
}
173173
}
174174

@@ -200,7 +200,7 @@ pub trait CallSubType<T: Config<I, RuntimeCall = Self>, I: 'static>:
200200
justification,
201201
None,
202202
false,
203-
))
203+
));
204204
} else if let Some(crate::Call::<T, I>::submit_finality_proof_ex {
205205
finality_target,
206206
justification,
@@ -213,7 +213,7 @@ pub trait CallSubType<T: Config<I, RuntimeCall = Self>, I: 'static>:
213213
justification,
214214
Some(*current_set_id),
215215
*is_free_execution_expected,
216-
))
216+
));
217217
}
218218

219219
None
@@ -243,7 +243,7 @@ pub trait CallSubType<T: Config<I, RuntimeCall = Self>, I: 'static>:
243243
};
244244

245245
if Pallet::<T, I>::ensure_not_halted().is_err() {
246-
return Err(InvalidTransaction::Call.into())
246+
return Err(InvalidTransaction::Call.into());
247247
}
248248

249249
let result = SubmitFinalityProofHelper::<T, I>::check_obsolete_from_extension(&call_info);

bridges/modules/messages/src/benchmarking.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ impl<T: Config<I>, I: 'static> ReceiveMessagesProofSetup<T, I> {
191191
mod benchmarks {
192192
use super::*;
193193

194-
//
195194
// Benchmarks that are used directly by the runtime calls weight formulae.
196195
//
197196

@@ -501,7 +500,6 @@ mod benchmarks {
501500
assert!(T::is_relayer_rewarded(&relayer2_id));
502501
}
503502

504-
//
505503
// Benchmarks that the runtime developers may use for proper pallet configuration.
506504
//
507505

bridges/modules/messages/src/call_ext.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl<T: Config<I>, I: 'static> CallHelper<T, I> {
5454
// so if relayer slots are released, then message slots are also
5555
// released
5656
return post_occupation.free_message_slots >
57-
info.unrewarded_relayers.free_message_slots
57+
info.unrewarded_relayers.free_message_slots;
5858
}
5959

6060
inbound_lane_data.last_delivered_nonce() == *info.base.bundled_range.end()
@@ -131,7 +131,7 @@ impl<
131131
best_stored_nonce: inbound_lane_data.last_delivered_nonce(),
132132
},
133133
unrewarded_relayers: unrewarded_relayers_occupation::<T, I>(&inbound_lane_data),
134-
})
134+
});
135135
}
136136

137137
None
@@ -157,19 +157,19 @@ impl<
157157
bundled_range: outbound_lane_data.latest_received_nonce + 1..=
158158
relayers_state.last_delivered_nonce,
159159
best_stored_nonce: outbound_lane_data.latest_received_nonce,
160-
}))
160+
}));
161161
}
162162

163163
None
164164
}
165165

166166
fn call_info(&self) -> Option<MessagesCallInfo<T::LaneId>> {
167167
if let Some(info) = self.receive_messages_proof_info() {
168-
return Some(MessagesCallInfo::ReceiveMessagesProof(info))
168+
return Some(MessagesCallInfo::ReceiveMessagesProof(info));
169169
}
170170

171171
if let Some(info) = self.receive_messages_delivery_proof_info() {
172-
return Some(MessagesCallInfo::ReceiveMessagesDeliveryProof(info))
172+
return Some(MessagesCallInfo::ReceiveMessagesDeliveryProof(info));
173173
}
174174

175175
None
@@ -195,7 +195,7 @@ impl<
195195
"Rejecting messages transaction on halted pallet"
196196
);
197197

198-
return sp_runtime::transaction_validity::InvalidTransaction::Call.into()
198+
return sp_runtime::transaction_validity::InvalidTransaction::Call.into();
199199
},
200200
Some(MessagesCallInfo::ReceiveMessagesProof(proof_info))
201201
if proof_info
@@ -207,7 +207,7 @@ impl<
207207
"Rejecting obsolete messages delivery transaction"
208208
);
209209

210-
return sp_runtime::transaction_validity::InvalidTransaction::Stale.into()
210+
return sp_runtime::transaction_validity::InvalidTransaction::Stale.into();
211211
},
212212
Some(MessagesCallInfo::ReceiveMessagesDeliveryProof(proof_info))
213213
if proof_info.is_obsolete() =>
@@ -218,7 +218,7 @@ impl<
218218
"Rejecting obsolete messages confirmation transaction"
219219
);
220220

221-
return sp_runtime::transaction_validity::InvalidTransaction::Stale.into()
221+
return sp_runtime::transaction_validity::InvalidTransaction::Stale.into();
222222
},
223223
_ => {},
224224
}

bridges/modules/messages/src/inbound_lane.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ impl<S: InboundLaneStorage> InboundLane<S> {
151151

152152
if outbound_lane_data.latest_received_nonce > last_delivered_nonce {
153153
// this is something that should never happen if proofs are correct
154-
return None
154+
return None;
155155
}
156156
if outbound_lane_data.latest_received_nonce <= data.last_confirmed_nonce {
157-
return None
157+
return None;
158158
}
159159

160160
let new_confirmed_nonce = outbound_lane_data.latest_received_nonce;
@@ -191,18 +191,18 @@ impl<S: InboundLaneStorage> InboundLane<S> {
191191
) -> ReceptionResult<Dispatch::DispatchLevelResult> {
192192
let mut data = self.storage.data();
193193
if Some(nonce) != data.last_delivered_nonce().checked_add(1) {
194-
return ReceptionResult::InvalidNonce
194+
return ReceptionResult::InvalidNonce;
195195
}
196196

197197
// if there are more unrewarded relayer entries than we may accept, reject this message
198198
if data.relayers.len() as MessageNonce >= self.storage.max_unrewarded_relayer_entries() {
199-
return ReceptionResult::TooManyUnrewardedRelayers
199+
return ReceptionResult::TooManyUnrewardedRelayers;
200200
}
201201

202202
// if there are more unconfirmed messages than we may accept, reject this message
203203
let unconfirmed_messages_count = nonce.saturating_sub(data.last_confirmed_nonce);
204204
if unconfirmed_messages_count > self.storage.max_unconfirmed_messages() {
205-
return ReceptionResult::TooManyUnconfirmedMessages
205+
return ReceptionResult::TooManyUnconfirmedMessages;
206206
}
207207

208208
// then, dispatch message

bridges/modules/messages/src/outbound_lane.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ impl<S: OutboundLaneStorage> OutboundLane<S> {
142142
end: latest_delivered_nonce,
143143
};
144144
if confirmed_messages.total_messages() == 0 {
145-
return Ok(None)
145+
return Ok(None);
146146
}
147147
if confirmed_messages.end > data.latest_generated_nonce {
148-
return Err(ReceptionConfirmationError::FailedToConfirmFutureMessages)
148+
return Err(ReceptionConfirmationError::FailedToConfirmFutureMessages);
149149
}
150150
if confirmed_messages.total_messages() > max_allowed_messages {
151151
// that the relayer has declared correct number of messages that the proof contains (it
@@ -159,7 +159,7 @@ impl<S: OutboundLaneStorage> OutboundLane<S> {
159159
max_allowed=%max_allowed_messages,
160160
"Messages delivery proof contains too many messages to confirm"
161161
);
162-
return Err(ReceptionConfirmationError::TryingToConfirmMoreMessagesThanExpected)
162+
return Err(ReceptionConfirmationError::TryingToConfirmMoreMessagesThanExpected);
163163
}
164164

165165
ensure_unrewarded_relayers_are_correct(confirmed_messages.end, relayers)?;
@@ -203,18 +203,18 @@ fn ensure_unrewarded_relayers_are_correct<RelayerId>(
203203
// unrewarded relayer entry must have at least 1 unconfirmed message
204204
// (guaranteed by the `InboundLane::receive_message()`)
205205
if entry.messages.end < entry.messages.begin {
206-
return Err(ReceptionConfirmationError::EmptyUnrewardedRelayerEntry)
206+
return Err(ReceptionConfirmationError::EmptyUnrewardedRelayerEntry);
207207
}
208208
// every entry must confirm range of messages that follows previous entry range
209209
// (guaranteed by the `InboundLane::receive_message()`)
210210
if expected_entry_begin != Some(entry.messages.begin) {
211-
return Err(ReceptionConfirmationError::NonConsecutiveUnrewardedRelayerEntries)
211+
return Err(ReceptionConfirmationError::NonConsecutiveUnrewardedRelayerEntries);
212212
}
213213
expected_entry_begin = entry.messages.end.checked_add(1);
214214
// entry can't confirm messages larger than `inbound_lane_data.latest_received_nonce()`
215215
// (guaranteed by the `InboundLane::receive_message()`)
216216
if entry.messages.end > latest_received_nonce {
217-
return Err(ReceptionConfirmationError::FailedToConfirmFutureMessages)
217+
return Err(ReceptionConfirmationError::FailedToConfirmFutureMessages);
218218
}
219219
}
220220

bridges/modules/messages/src/proofs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub fn verify_messages_proof<T: Config<I>, I: 'static>(
6565
// receiving proofs where end < begin is ok (if proof includes outbound lane state)
6666
let messages_in_the_proof = nonces_range.saturating_len();
6767
if messages_in_the_proof != MessageNonce::from(messages_count) {
68-
return Err(VerificationError::MessagesCountMismatch)
68+
return Err(VerificationError::MessagesCountMismatch);
6969
}
7070

7171
// Read messages first. All messages that are claimed to be in the proof must
@@ -92,7 +92,7 @@ pub fn verify_messages_proof<T: Config<I>, I: 'static>(
9292

9393
// Now we may actually check if the proof is empty or not.
9494
if proved_lane_messages.lane_state.is_none() && proved_lane_messages.messages.is_empty() {
95-
return Err(VerificationError::EmptyMessageProof)
95+
return Err(VerificationError::EmptyMessageProof);
9696
}
9797

9898
// Check that the storage proof doesn't have any untouched keys.

0 commit comments

Comments
 (0)