Skip to content

Commit

Permalink
chore: Fix rustfmt and clippy for rust 1.84.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dhedey committed Feb 14, 2025
1 parent ee812b2 commit ee37912
Show file tree
Hide file tree
Showing 29 changed files with 118 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ pub(crate) async fn handle_lts_transaction_status(
.filter_map(|p| p.1.intent_invalid_from_epoch)
.next();

let intent_is_permanently_rejected = invalid_from_epoch.map_or(false, |invalid_from_epoch| {
current_epoch >= invalid_from_epoch
}) || known_pending_payloads.iter().any(|p| {
p.1.earliest_permanent_rejection
.as_ref()
.map_or(false, |r| r.marks_permanent_rejection_for_intent())
});
let intent_is_permanently_rejected = invalid_from_epoch
.is_some_and(|invalid_from_epoch| current_epoch >= invalid_from_epoch)
|| known_pending_payloads.iter().any(|p| {
p.1.earliest_permanent_rejection
.as_ref()
.is_some_and(|r| r.marks_permanent_rejection_for_intent())
});

if let Some(txn_state_version) = txn_state_version_opt {
let hashes = database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ pub(crate) async fn handle_transaction_status(
.filter_map(|p| p.1.intent_invalid_from_epoch)
.next();

let intent_is_permanently_rejected = invalid_from_epoch.map_or(false, |invalid_from_epoch| {
current_epoch >= invalid_from_epoch
}) || known_pending_payloads.iter().any(|p| {
p.1.earliest_permanent_rejection
.as_ref()
.map_or(false, |r| r.marks_permanent_rejection_for_intent())
});
let intent_is_permanently_rejected = invalid_from_epoch
.is_some_and(|invalid_from_epoch| current_epoch >= invalid_from_epoch)
|| known_pending_payloads.iter().any(|p| {
p.1.earliest_permanent_rejection
.as_ref()
.is_some_and(|r| r.marks_permanent_rejection_for_intent())
});

if let Some(txn_state_version) = txn_state_version_opt {
let hashes = database
Expand Down
2 changes: 1 addition & 1 deletion core-rust/core-api-server/src/core_api/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl<'a> ByteCountWriter<'a> {
}
}

impl<'a> Write for ByteCountWriter<'a> {
impl Write for ByteCountWriter<'_> {
fn write(&mut self, data: &[u8]) -> Result<usize, std::io::Error> {
*self.bytes += data.len();
Ok(data.len())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct ObjectRoyaltyLoader<'s, S: SubstateDatabase> {
pub data_loader: EngineStateDataLoader<'s, S>,
}

impl<'s, S: SubstateDatabase> ObjectRoyaltyLoader<'s, S> {
impl<S: SubstateDatabase> ObjectRoyaltyLoader<'_, S> {
/// Returns Package and Component royalty amounts for all methods of the given object.
pub fn load_method_amounts(
&self,
Expand Down Expand Up @@ -95,7 +95,7 @@ pub struct ObjectRoleAssignmentLoader<'s, S: SubstateDatabase> {
pub data_loader: EngineStateDataLoader<'s, S>,
}

impl<'s, S: SubstateDatabase> ObjectRoleAssignmentLoader<'s, S> {
impl<S: SubstateDatabase> ObjectRoleAssignmentLoader<'_, S> {
/// Loads full information from the [`ModuleId::RoleAssignment`] module:
/// - the Owner rule and updater,
/// - the role-to-rule assignment for all roles defined by the object and its attached modules.
Expand Down Expand Up @@ -247,7 +247,7 @@ pub struct ObjectMetadataLoader<'s, S: SubstateDatabase> {
pub loader: EngineStateDataLoader<'s, S>,
}

impl<'s, S: SubstateDatabase> ObjectMetadataLoader<'s, S> {
impl<S: SubstateDatabase> ObjectMetadataLoader<'_, S> {
/// Returns an iterator of keys within the Metadata module attached to the given object,
/// starting at the given key.
pub fn iter_keys(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct EngineStateMetaLoader<'s, S: SubstateDatabase> {
pub non_instantiated_node_ids: IndexSet<NodeId>,
}

impl<'s, S: SubstateDatabase> EngineStateMetaLoader<'s, S> {
impl<S: SubstateDatabase> EngineStateMetaLoader<'_, S> {
/// Loads metadata on the given blueprint.
pub fn load_blueprint_meta(
&self,
Expand Down
20 changes: 10 additions & 10 deletions core-rust/mesh-api-server/src/mesh_api/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl From<ApiError> for ResponseError {

pub fn list_available_api_errors() -> Vec<models::Error> {
ApiError::iter()
.map(|v| ResponseError::from(v).error)
.map(|v| *ResponseError::from(v).error)
.collect()
}

Expand All @@ -89,37 +89,37 @@ impl ResponseForPanic for InternalServerErrorResponseForPanic {
#[derive(Debug, Clone)]
pub(crate) struct ResponseError {
status_code: StatusCode,
error: models::Error,
error: Box<models::Error>,
}

impl ResponseError {
pub fn new(code: i32, error_message: impl Into<String>, retryable: bool) -> Self {
Self {
// "500" should be returned in case of unexpected error
status_code: StatusCode::INTERNAL_SERVER_ERROR,
error: models::Error::new(code, error_message.into(), retryable),
error: Box::new(models::Error::new(code, error_message.into(), retryable)),
}
}

#[allow(unused)]
pub fn retryable(self, retryable: bool) -> Self {
Self {
error: models::Error {
error: Box::new(models::Error {
retriable: retryable,
..self.error
},
..*self.error
}),
..self
}
}

pub fn with_details(self, details_message: impl Into<String>) -> Self {
Self {
error: models::Error {
error: Box::new(models::Error {
details: Some(serde_json::json!({
"details_message": details_message.into(),
})),
..self.error
},
..*self.error
}),
..self
}
}
Expand Down Expand Up @@ -166,7 +166,7 @@ impl IntoResponse for ResponseError {

let error_response_event = ErrorResponseEvent {
level: resolve_level(self.status_code),
error: returned_body.clone(),
error: (*returned_body).clone(),
};
let mut framework_response = (self.status_code, Json(returned_body)).into_response();
framework_response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub(crate) async fn handle_account_balance(
// Method `dump_component_state()` might be slow on large accounts,
// therefore we use it only when user didn't specify which balances
// to get.
fn get_all_balances<'a>(
fn get_all_balances(
mapping_context: &MappingContext,
database: &impl SubstateDatabase,
component_address: &ComponentAddress,
Expand Down
2 changes: 1 addition & 1 deletion core-rust/node-common/src/locks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl<'s, D: Snapshottable<'s>> DbLock<D> {
/// do not leave database inconsistent.
// TODO(future enhancement): also provide something like `lock_snapshot_unlock()`, which would
// not need the "writes are atomic+consistent" assumption?
pub fn snapshot(&'s self) -> impl Deref<Target = D::Snapshot> + '_ {
pub fn snapshot(&'s self) -> impl Deref<Target = D::Snapshot> + 's {
LockGuard::new(
|| OwnedDeref {
owned: self.database.snapshot(),
Expand Down
2 changes: 1 addition & 1 deletion core-rust/node-common/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl<'r> TokioSpawner<'r> {
}
}

impl<'r> Spawner for TokioSpawner<'r> {
impl Spawner for TokioSpawner<'_> {
fn spawn(
&self,
interval: Duration,
Expand Down
4 changes: 2 additions & 2 deletions core-rust/node-common/src/store/rocks_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl CheckpointableRocks for DirectRocks {
}
}

impl<'db> CheckpointableRocks for SnapshotRocks<'db> {
impl CheckpointableRocks for SnapshotRocks<'_> {
fn create_checkpoint(&self, checkpoint_path: PathBuf) -> Result<(), rocksdb::Error> {
create_checkpoint(self.db, checkpoint_path)
}
Expand All @@ -227,7 +227,7 @@ pub struct SnapshotRocks<'db> {
snapshot: Snapshot<'db>,
}

impl<'db> ReadableRocks for SnapshotRocks<'db> {
impl ReadableRocks for SnapshotRocks<'_> {
fn cf_handle(&self, name: &str) -> &ColumnFamily {
self.db.cf_handle(name).expect(name)
}
Expand Down
27 changes: 11 additions & 16 deletions core-rust/node-common/src/store/typed_cf_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ impl<'r, R: WriteableRocks> BufferedWriteSupport<'r, R> {
}
}

impl<'r, R: WriteableRocks> WriteSupport for BufferedWriteSupport<'r, R> {}
impl<R: WriteableRocks> WriteSupport for BufferedWriteSupport<'_, R> {}

impl<'r, R: WriteableRocks> BufferedWriteSupport<'r, R> {
impl<R: WriteableRocks> BufferedWriteSupport<'_, R> {
/// Writes the batch to the RocksDB and flips the internal buffer.
fn flush(&self) {
let write_batch = self.buffer.flip();
Expand All @@ -116,7 +116,7 @@ impl<'r, R: WriteableRocks> BufferedWriteSupport<'r, R> {
}
}

impl<'r, R: WriteableRocks> Drop for BufferedWriteSupport<'r, R> {
impl<R: WriteableRocks> Drop for BufferedWriteSupport<'_, R> {
fn drop(&mut self) {
self.flush();
}
Expand Down Expand Up @@ -205,9 +205,7 @@ impl<'r, 'w, CF: TypedCf, R: ReadableRocks, W: WriteSupport> TypedCfApi<'r, 'w,
}
}

impl<'r, 'w, CF: TypedCf, R: WriteableRocks>
TypedCfApi<'r, 'w, CF, R, BufferedWriteSupport<'r, R>>
{
impl<'r, CF: TypedCf, R: WriteableRocks> TypedCfApi<'r, '_, CF, R, BufferedWriteSupport<'r, R>> {
/// Upserts the new value at the given key.
pub fn put(&self, key: &CF::Key, value: &CF::Value) {
self.write_support.buffer.put(
Expand All @@ -225,8 +223,8 @@ impl<'r, 'w, CF: TypedCf, R: WriteableRocks>
}
}

impl<'r, 'w, KC: BoundedDbCodec, CF: TypedCf<KeyCodec = KC>, R: WriteableRocks>
TypedCfApi<'r, 'w, CF, R, BufferedWriteSupport<'r, R>>
impl<'r, KC: BoundedDbCodec, CF: TypedCf<KeyCodec = KC>, R: WriteableRocks>
TypedCfApi<'r, '_, CF, R, BufferedWriteSupport<'r, R>>
{
/// Deletes all entries.
pub fn delete_all(&self) {
Expand All @@ -246,8 +244,8 @@ impl<'r, 'w, KC: BoundedDbCodec, CF: TypedCf<KeyCodec = KC>, R: WriteableRocks>
}
}

impl<'r, 'w, KC: GroupPreservingDbCodec, CF: TypedCf<KeyCodec = KC>, R: WriteableRocks>
TypedCfApi<'r, 'w, CF, R, BufferedWriteSupport<'r, R>>
impl<'r, KC: GroupPreservingDbCodec, CF: TypedCf<KeyCodec = KC>, R: WriteableRocks>
TypedCfApi<'r, '_, CF, R, BufferedWriteSupport<'r, R>>
{
/// Deletes all the entries from the given group.
pub fn delete_group(&self, group: &KC::Group) {
Expand All @@ -265,13 +263,12 @@ impl<'r, 'w, KC: GroupPreservingDbCodec, CF: TypedCf<KeyCodec = KC>, R: Writeabl
#[allow(dead_code)]
impl<
'r,
'w,
K,
KC: OrderPreservingDbCodec + DbCodec<K>,
CF: TypedCf<Key = K, KeyCodec = KC>,
R: ReadableRocks,
W: WriteSupport,
> TypedCfApi<'r, 'w, CF, R, W>
> TypedCfApi<'r, '_, CF, R, W>
{
/// Gets the entry of the least key.
pub fn get_first(&self) -> Option<(CF::Key, CF::Value)> {
Expand Down Expand Up @@ -365,12 +362,11 @@ impl<

impl<
'r,
'w,
K,
KC: OrderPreservingDbCodec + DbCodec<K>,
CF: TypedCf<Key = K, KeyCodec = KC>,
R: WriteableRocks,
> TypedCfApi<'r, 'w, CF, R, BufferedWriteSupport<'r, R>>
> TypedCfApi<'r, '_, CF, R, BufferedWriteSupport<'r, R>>
{
/// Deletes all the entries from the given key range.
/// Follows the classic convention of "from inclusive, to exclusive".
Expand All @@ -385,13 +381,12 @@ impl<

impl<
'r,
'w,
K,
KC: IntraGroupOrderPreservingDbCodec<K> + DbCodec<K>,
CF: TypedCf<Key = K, KeyCodec = KC>,
R: ReadableRocks,
W: WriteSupport,
> TypedCfApi<'r, 'w, CF, R, W>
> TypedCfApi<'r, '_, CF, R, W>
{
/// Returns an iterator starting at the given key (inclusive) and traversing over (potentially)
/// all the entries remaining *in this element's group*, in the requested direction.
Expand Down
1 change: 0 additions & 1 deletion core-rust/p2p/src/rocks_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ use crate::safety_store_components::SafetyState;
/// The `NAME` constants defined by `*Cf` structs (and referenced below) are used as database column
/// family names. Any change would effectively mean a ledger wipe. For this reason, we choose to
/// define them manually (rather than using the `Into<String>`, which is refactor-sensitive).
const ALL_ADDRESS_BOOK_COLUMN_FAMILIES: [&str; 3] = [
AddressBookCf::NAME,
HighPriorityPeersCf::NAME,
Expand Down
20 changes: 11 additions & 9 deletions core-rust/p2p/src/safety_store_components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,18 @@ define_single_versioned! {

/// Safety state components. Note that these structs are intended only for proper encoding/deconding
/// of the safety state. They may repeat existing structs defined elsewhere.
///
/// Timestamp of the various safety state components.
// At present it's just an alias for i64. Later we may want to replace it with struct using crono crate and
// do something like shown below to transparently convert to/from internal representation
// (once there will be real usage at Rust side).
// #[sbor(
// as_type = "i64",
// as_ref = "self.timestamp()",
// from_value = "Self(DateTime::from_timestamp(value, 0))"
// )]
/// At present it's just an alias for i64. Later we may want to replace it with struct using crono crate and
/// do something like shown below to transparently convert to/from internal representation
/// (once there will be real usage at Rust side).
/// ```rust,ignore
/// #[sbor(
/// as_type = "i64",
/// as_ref = "self.timestamp()",
/// from_value = "Self(DateTime::from_timestamp(value, 0))"
/// )]
/// ```
type SafetyStateTimestamp = i64;

#[derive(Debug, Clone, ScryptoSbor)]
Expand Down
2 changes: 1 addition & 1 deletion core-rust/state-manager/src/jni/node_rust_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl JNINodeRustEnvironment {
(base_path, config)
}

fn combine(base: &String, ext: &str) -> PathBuf {
fn combine(base: &str, ext: &str) -> PathBuf {
[base, ext].iter().collect()
}

Expand Down
5 changes: 4 additions & 1 deletion core-rust/state-manager/src/mempool/mempool_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ impl MempoolManager {
// If the transaction fails to prepare at this point then we don't even have a hash to assign against it,
// so we can't cache anything - just return an error
return Err(MempoolAddError::Rejected(
MempoolAddRejection::for_static_rejection(prepare_error.into()),
Box::new(MempoolAddRejection::for_static_rejection(
prepare_error.into(),
)),
None,
));
}
Expand Down Expand Up @@ -547,6 +549,7 @@ enum ForceRecalculation {
IfCachedAsValid,
}

#[allow(clippy::large_enum_variant)]
enum ShouldRecalculate {
Yes,
No(PendingTransactionRecord),
Expand Down
6 changes: 3 additions & 3 deletions core-rust/state-manager/src/mempool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub enum MempoolAddError {
tip_basis_points: u32,
},
Duplicate(NotarizedTransactionHash),
Rejected(MempoolAddRejection, Option<NotarizedTransactionHash>),
Rejected(Box<MempoolAddRejection>, Option<NotarizedTransactionHash>),
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -132,9 +132,9 @@ impl MempoolAddRejection {
impl<'a> ContextualDisplay<ScryptoValueDisplayContext<'a>> for MempoolAddError {
type Error = fmt::Error;

fn contextual_format<F: fmt::Write>(
fn contextual_format(
&self,
f: &mut F,
f: &mut fmt::Formatter,
context: &ScryptoValueDisplayContext<'a>,
) -> Result<(), Self::Error> {
match self {
Expand Down
Loading

0 comments on commit ee37912

Please sign in to comment.