Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
[move][clippy] Apply clippy CI check to all targets (#17165)
Browse files Browse the repository at this point in the history
## Description 

- cargo move-clippy did not include tests 

## Test plan 

- CI

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
  • Loading branch information
tnowacki authored Apr 16, 2024
1 parent 2533e1e commit f95d1a6
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 56 deletions.
6 changes: 3 additions & 3 deletions crates/bytecode-verifier-tests/src/unit_tests/bounds_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ fn invalid_signature_for_vector_operation() {

let skeleton = basic_test_module();
let sig_index = SignatureIndex(skeleton.signatures.len() as u16);
for bytecode in vec![
for bytecode in [
VecPack(sig_index, 0),
VecLen(sig_index),
VecImmBorrow(sig_index),
Expand Down Expand Up @@ -251,7 +251,7 @@ fn invalid_struct_for_vector_operation() {
.signatures
.push(Signature(vec![Struct(StructHandleIndex::new(3))]));
let sig_index = SignatureIndex((skeleton.signatures.len() - 1) as u16);
for bytecode in vec![
for bytecode in [
VecPack(sig_index, 0),
VecLen(sig_index),
VecImmBorrow(sig_index),
Expand All @@ -278,7 +278,7 @@ fn invalid_type_param_for_vector_operation() {
let mut skeleton = basic_test_module();
skeleton.signatures.push(Signature(vec![TypeParameter(0)]));
let sig_index = SignatureIndex((skeleton.signatures.len() - 1) as u16);
for bytecode in vec![
for bytecode in [
VecPack(sig_index, 0),
VecLen(sig_index),
VecImmBorrow(sig_index),
Expand Down
2 changes: 1 addition & 1 deletion crates/invalid-mutations/src/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ fn struct_handle(token: &SignatureToken) -> Option<StructHandleIndex> {
StructInstantiation(struct_inst) => {
let (sh_idx, _) = &**struct_inst;
Some(*sh_idx)
},
}
Reference(token) | MutableReference(token) => struct_handle(token),
Bool | U8 | U16 | U32 | U64 | U128 | U256 | Address | Signer | Vector(_)
| TypeParameter(_) => None,
Expand Down
7 changes: 3 additions & 4 deletions crates/move-analyzer/src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3807,11 +3807,10 @@ fn assert_use_def_with_doc_string(
"for use in column {use_col} of line {use_line} in file {use_file}"
);
let info = def_info.get(&use_def.def_loc).unwrap();
let info_str = info.to_string();
assert!(
type_str == format!("{}", info),
"'{}' != '{}' for use in column {use_col} of line {use_line} in file {use_file}",
type_str,
format!("{}", info)
type_str == info_str,
"'{type_str}' != '{info}' for use in column {use_col} of line {use_line} in file {use_file}",
);

if doc_string.is_some() {
Expand Down
2 changes: 0 additions & 2 deletions crates/move-binary-format/src/binary_config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) The Move Contributors
// SPDX-License-Identifier: Apache-2.0


use crate::file_format_common::VERSION_MAX;

/// Configuration for the binary format related to table size.
Expand Down Expand Up @@ -98,4 +97,3 @@ impl BinaryConfig {
}
}
}

2 changes: 1 addition & 1 deletion crates/move-binary-format/src/proptest_types/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ impl BytecodeGen {
type_arguments
.iter()
.all(BytecodeGen::check_signature_token)
},
}
Reference(_) | MutableReference(_) => false,
}
}
Expand Down
10 changes: 4 additions & 6 deletions crates/move-binary-format/src/proptest_types/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,10 @@ impl SignatureTokenGen {
_ => type_params.push(SignatureToken::U64),
}
}
SignatureToken::StructInstantiation(Box::new(
(
StructHandleIndex(struct_idx as TableIndex),
type_params,
)
))
SignatureToken::StructInstantiation(Box::new((
StructHandleIndex(struct_idx as TableIndex),
type_params,
)))
}
}
}
Expand Down
28 changes: 11 additions & 17 deletions crates/move-binary-format/src/unit_tests/binary_limits_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

use crate::{
binary_config::{BinaryConfig, TableConfig},
CompiledModule,
errors::BinaryLoaderResult,
file_format::*,
CompiledModule,
};
use move_core_types::{
account_address::AccountAddress,
identifier::Identifier,
vm_status::StatusCode,
account_address::AccountAddress, identifier::Identifier, vm_status::StatusCode,
};
// Add simple proptest tests
// use proptest::prelude::*;
Expand All @@ -25,7 +23,7 @@ fn deserialize(
let mut bytes = vec![];
module.serialize(&mut bytes).unwrap();
// deserialize the module just serialized (round trip)
CompiledModule::deserialize_with_config(&bytes, &binary_config)
CompiledModule::deserialize_with_config(&bytes, binary_config)
}

//
Expand Down Expand Up @@ -273,12 +271,10 @@ fn binary_limits_test() {
});
module_test.struct_defs.push(StructDefinition {
struct_handle: StructHandleIndex(0),
field_information: StructFieldInformation::Declared(vec![
FieldDefinition {
name: IdentifierIndex(0),
signature: TypeSignature(SignatureToken::Bool),
},
]),
field_information: StructFieldInformation::Declared(vec![FieldDefinition {
name: IdentifierIndex(0),
signature: TypeSignature(SignatureToken::Bool),
}]),
});
check_limit!(
module_test,
Expand All @@ -301,12 +297,10 @@ fn binary_limits_test() {
});
module_test.struct_defs.push(StructDefinition {
struct_handle: StructHandleIndex(0),
field_information: StructFieldInformation::Declared(vec![
FieldDefinition {
name: IdentifierIndex(0),
signature: TypeSignature(SignatureToken::Bool),
},
]),
field_information: StructFieldInformation::Declared(vec![FieldDefinition {
name: IdentifierIndex(0),
signature: TypeSignature(SignatureToken::Bool),
}]),
});
module_test.field_handles.push(FieldHandle {
owner: StructDefinitionIndex(0),
Expand Down
2 changes: 1 addition & 1 deletion crates/move-binary-format/src/unit_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Copyright (c) The Move Contributors
// SPDX-License-Identifier: Apache-2.0

mod binary_limits_tests;
mod binary_tests;
mod compatibility_tests;
mod control_flow_graph_tests;
mod deserializer_tests;
mod number_tests;
mod signature_token_tests;
mod binary_limits_tests;
2 changes: 1 addition & 1 deletion crates/move-core-types/src/unit_tests/visitor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ fn nested_typed_struct_visit() {

let mut struct_visitor = PrintVisitor::default();
let from_struct =
MoveStruct::visit_deserialize(&bytes, &struct_layout, &mut struct_visitor).unwrap();
MoveStruct::visit_deserialize(&bytes, struct_layout, &mut struct_visitor).unwrap();

let expected_output = r#"
[0] struct 0x0::foo::Bar {
Expand Down
9 changes: 4 additions & 5 deletions crates/move-package/tests/test_lock_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ fn update_lock_file_toolchain_version() {
let move_manifest = pkg.path().join("Move.toml");
// The 2024.beta in the manifest should override defaults.
fs::write(
&move_manifest,
move_manifest,
r#"
[package]
name = "test"
Expand All @@ -184,8 +184,7 @@ fn update_lock_file_toolchain_version() {
lock_file: Some(lock_path.clone()),
..Default::default()
};
let _ =
build_config.update_lock_file_toolchain_version(&pkg.path().to_path_buf(), "0.0.1".into());
let _ = build_config.update_lock_file_toolchain_version(pkg.path(), "0.0.1".into());

let mut lock_file = File::open(lock_path).unwrap();
let toolchain_version =
Expand Down Expand Up @@ -220,7 +219,7 @@ fn test_update_managed_address() {
let mut lock = LockFile::from(pb, &lock_path).unwrap();
update_managed_address(
&mut lock,
"default".into(),
"default",
ManagedAddressUpdate::Published {
original_id: "0x123".into(),
chain_id: "35834a8a".into(),
Expand All @@ -230,7 +229,7 @@ fn test_update_managed_address() {

update_managed_address(
&mut lock,
"default".into(),
"default",
ManagedAddressUpdate::Upgraded {
latest_id: "0x456".into(),
version: 2,
Expand Down
6 changes: 3 additions & 3 deletions crates/move-stackless-bytecode/src/borrow_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ impl BorrowInfo {
fn get_children(&self, node: &BorrowNode) -> Vec<&BorrowNode> {
self.borrowed_by
.get(node)
.map(|s| s.iter().map(|(n, _)| n).collect_vec())
.map(|s| s.iter().map(|(n, _)| n).collect())
.unwrap_or_default()
}

/// Gets the parents (together with the edges) of this node.
fn get_incoming(&self, node: &BorrowNode) -> Vec<(&BorrowNode, &BorrowEdge)> {
fn get_incoming(&self, node: &BorrowNode) -> Vec<&(BorrowNode, BorrowEdge)> {
self.borrows_from
.get(node)
.map(|s| s.iter().map(|(n, e)| (n, e)).collect_vec())
.map(|s| s.iter().collect())
.unwrap_or_default()
}

Expand Down
14 changes: 10 additions & 4 deletions crates/move-stackless-bytecode/src/stackless_bytecode_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,17 +382,23 @@ impl<'a> StacklessBytecodeGenerator<'a> {
let temp_index = self.temp_count;
self.temp_stack.push(temp_index);
self.local_types.push(Type::Primitive(PrimitiveType::U256));
self.code
.push(Bytecode::Load(attr_id, temp_index, Constant::from(&**number)));
self.code.push(Bytecode::Load(
attr_id,
temp_index,
Constant::from(&**number),
));
self.temp_count += 1;
}

MoveBytecode::LdU128(number) => {
let temp_index = self.temp_count;
self.temp_stack.push(temp_index);
self.local_types.push(Type::Primitive(PrimitiveType::U128));
self.code
.push(Bytecode::Load(attr_id, temp_index, Constant::U128(**number)));
self.code.push(Bytecode::Load(
attr_id,
temp_index,
Constant::U128(**number),
));
self.temp_count += 1;
}

Expand Down
5 changes: 2 additions & 3 deletions crates/move-vm-types/src/loaded_data/runtime_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,9 @@ impl Type {
Struct(_) => Self::LEGACY_BASE_MEMORY_SIZE,
StructInstantiation(struct_inst) => {
let (_, tys) = &**struct_inst;
tys
.iter()
tys.iter()
.fold(Self::LEGACY_BASE_MEMORY_SIZE, |acc, ty| acc + ty.size())
},
}
}
}

Expand Down
10 changes: 6 additions & 4 deletions crates/test-generation/src/bytecode_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,15 @@ impl<'a> BytecodeGenerator<'a> {
}
BytecodeType::U128(instruction) => {
// Generate a random u128 constant to load
Some(instruction(Box::new(self.rng.gen_range(0..u128::max_value()))))
Some(instruction(Box::new(
self.rng.gen_range(0..u128::max_value()),
)))
}
BytecodeType::U256(instruction) => {
// Generate a random u256 constant to load
Some(instruction(
Box::new(self.rng.gen_range(U256::zero()..U256::max_value())),
))
Some(instruction(Box::new(
self.rng.gen_range(U256::zero()..U256::max_value()),
)))
}
BytecodeType::ConstantPoolIndex(instruction) => {
// Select a random address from the module's address pool
Expand Down
5 changes: 4 additions & 1 deletion crates/test-generation/src/transitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,10 @@ pub fn create_struct(
None => SignatureToken::Struct(struct_def.struct_handle),
Some(inst) => {
let ty_instantiation = state.module.instantiantiation_at(inst);
SignatureToken::StructInstantiation(Box::new((struct_def.struct_handle, ty_instantiation.clone())))
SignatureToken::StructInstantiation(Box::new((
struct_def.struct_handle,
ty_instantiation.clone(),
)))
}
};
let struct_kind = abilities_for_token(&state, &sig_tok, &state.instantiation);
Expand Down

0 comments on commit f95d1a6

Please sign in to comment.