Skip to content

Commit cc306e5

Browse files
authored
Merge pull request #5745 from stacks-network/chore/clippy-assertions-assign-op-approx-constant
Apply clippy lints `approx_constant`, `assertions_on_constants`, `assign_op_pattern`, and `bool_assert_comparison`
2 parents e77ce8d + d74d9e4 commit cc306e5

Some content is hidden

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

83 files changed

+1914
-2567
lines changed

clarity/src/vm/tests/assets.rs

Lines changed: 47 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -155,24 +155,20 @@ fn test_native_stx_ops(epoch: StacksEpochId, mut env_factory: TopLevelMemoryEnvi
155155
let p2 = execute("'SM2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQVX8X0G");
156156
let p3 = execute("'SP3X6QWWETNBZWGBK6DRGTR1KX50S74D3433WDGJY");
157157

158-
let p1_std_principal_data = match p1 {
159-
Value::Principal(PrincipalData::Standard(ref data)) => data.clone(),
160-
_ => panic!(),
158+
let Value::Principal(PrincipalData::Standard(p1_std_principal_data)) = p1.clone() else {
159+
panic!("Expected standard principal data");
161160
};
162161

163-
let p1_principal = match p1 {
164-
Value::Principal(ref data) => data.clone(),
165-
_ => panic!(),
162+
let Value::Principal(p1_principal) = p1.clone() else {
163+
panic!("Expected principal data");
166164
};
167165

168-
let p2_principal = match p2 {
169-
Value::Principal(ref data) => data.clone(),
170-
_ => panic!(),
166+
let Value::Principal(p2_principal) = p2.clone() else {
167+
panic!("Expected principal data");
171168
};
172169

173-
let p3_principal = match p3 {
174-
Value::Principal(ref data) => data.clone(),
175-
_ => panic!(),
170+
let Value::Principal(p3_principal) = p3.clone() else {
171+
panic!("Expected principal data");
176172
};
177173

178174
let token_contract_id =
@@ -212,7 +208,7 @@ fn test_native_stx_ops(epoch: StacksEpochId, mut env_factory: TopLevelMemoryEnvi
212208
.unwrap();
213209

214210
assert!(is_err_code(&result, 3));
215-
assert_eq!(asset_map.to_table().len(), 0);
211+
assert!(asset_map.to_table().is_empty());
216212

217213
let (result, asset_map, _events) = execute_transaction(
218214
&mut owned_env,
@@ -224,7 +220,7 @@ fn test_native_stx_ops(epoch: StacksEpochId, mut env_factory: TopLevelMemoryEnvi
224220
.unwrap();
225221

226222
assert!(is_err_code(&result, 3));
227-
assert_eq!(asset_map.to_table().len(), 0);
223+
assert!(asset_map.to_table().is_empty());
228224

229225
// test 2: from = to
230226

@@ -238,7 +234,7 @@ fn test_native_stx_ops(epoch: StacksEpochId, mut env_factory: TopLevelMemoryEnvi
238234
.unwrap();
239235

240236
assert!(is_err_code(&result, 2));
241-
assert_eq!(asset_map.to_table().len(), 0);
237+
assert!(asset_map.to_table().is_empty());
242238

243239
// test 3: sender is not tx-sender
244240

@@ -252,7 +248,7 @@ fn test_native_stx_ops(epoch: StacksEpochId, mut env_factory: TopLevelMemoryEnvi
252248
.unwrap();
253249

254250
assert!(is_err_code(&result, 4));
255-
assert_eq!(asset_map.to_table().len(), 0);
251+
assert!(asset_map.to_table().is_empty());
256252

257253
let (result, asset_map, _events) = execute_transaction(
258254
&mut owned_env,
@@ -264,7 +260,7 @@ fn test_native_stx_ops(epoch: StacksEpochId, mut env_factory: TopLevelMemoryEnvi
264260
.unwrap();
265261

266262
assert!(is_err_code(&result, 4));
267-
assert_eq!(asset_map.to_table().len(), 0);
263+
assert!(asset_map.to_table().is_empty());
268264

269265
// test 4: amount > balance
270266

@@ -278,7 +274,7 @@ fn test_native_stx_ops(epoch: StacksEpochId, mut env_factory: TopLevelMemoryEnvi
278274
.unwrap();
279275

280276
assert!(is_err_code(&result, 1));
281-
assert_eq!(asset_map.to_table().len(), 0);
277+
assert!(asset_map.to_table().is_empty());
282278

283279
let (result, asset_map, _events) = execute_transaction(
284280
&mut owned_env,
@@ -290,7 +286,7 @@ fn test_native_stx_ops(epoch: StacksEpochId, mut env_factory: TopLevelMemoryEnvi
290286
.unwrap();
291287

292288
assert!(is_err_code(&result, 1));
293-
assert_eq!(asset_map.to_table().len(), 0);
289+
assert!(asset_map.to_table().is_empty());
294290

295291
// test 5: overflow
296292
// NOTE: this tested behavior is no longer reachable: the total liquid ustx supply
@@ -525,19 +521,16 @@ fn test_simple_token_system(
525521
let p1 = execute("'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR");
526522
let p2 = execute("'SM2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQVX8X0G");
527523

528-
let p1_std_principal_data = match p1 {
529-
Value::Principal(PrincipalData::Standard(ref data)) => data.clone(),
530-
_ => panic!(),
524+
let Value::Principal(PrincipalData::Standard(p1_std_principal_data)) = p1.clone() else {
525+
panic!("Expected standard pincipal data");
531526
};
532527

533-
let p1_principal = match p1 {
534-
Value::Principal(ref data) => data.clone(),
535-
_ => panic!(),
528+
let Value::Principal(p1_principal) = p1.clone() else {
529+
panic!("Expected principal data");
536530
};
537531

538-
let p2_principal = match p2 {
539-
Value::Principal(ref data) => data.clone(),
540-
_ => panic!(),
532+
let Value::Principal(p2_principal) = p2.clone() else {
533+
panic!("Expected principal data");
541534
};
542535

543536
let token_contract_id =
@@ -569,7 +562,7 @@ fn test_simple_token_system(
569562
.unwrap();
570563
assert!(!is_committed(&result));
571564

572-
assert_eq!(asset_map.to_table().len(), 0);
565+
assert!(asset_map.to_table().is_empty());
573566

574567
let (result, asset_map, _events) = execute_transaction(
575568
&mut owned_env,
@@ -597,7 +590,7 @@ fn test_simple_token_system(
597590
.unwrap();
598591

599592
assert!(is_err_code(&result, 1));
600-
assert_eq!(asset_map.to_table().len(), 0);
593+
assert!(asset_map.to_table().is_empty());
601594

602595
let (result, asset_map, _events) = execute_transaction(
603596
&mut owned_env,
@@ -609,7 +602,7 @@ fn test_simple_token_system(
609602
.unwrap();
610603

611604
assert!(is_err_code(&result, 2));
612-
assert_eq!(asset_map.to_table().len(), 0);
605+
assert!(asset_map.to_table().is_empty());
613606

614607
let err = execute_transaction(
615608
&mut owned_env,
@@ -635,7 +628,7 @@ fn test_simple_token_system(
635628
.unwrap();
636629

637630
assert_eq!(result, Value::UInt(1000));
638-
assert_eq!(asset_map.to_table().len(), 0);
631+
assert!(asset_map.to_table().is_empty());
639632

640633
let (result, asset_map, _events) = execute_transaction(
641634
&mut owned_env,
@@ -647,7 +640,7 @@ fn test_simple_token_system(
647640
.unwrap();
648641

649642
assert_eq!(result, Value::UInt(9200));
650-
assert_eq!(asset_map.to_table().len(), 0);
643+
assert!(asset_map.to_table().is_empty());
651644

652645
let (result, asset_map, _events) = execute_transaction(
653646
&mut owned_env,
@@ -814,7 +807,7 @@ fn test_simple_token_system(
814807
.unwrap();
815808

816809
assert!(!is_committed(&result));
817-
assert_eq!(asset_map.to_table().len(), 0);
810+
assert!(asset_map.to_table().is_empty());
818811
}
819812

820813
#[apply(test_epochs)]
@@ -836,14 +829,12 @@ fn test_total_supply(epoch: StacksEpochId, mut env_factory: TopLevelMemoryEnviro
836829

837830
let p1 = execute("'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR");
838831

839-
let p1_std_principal_data = match p1 {
840-
Value::Principal(PrincipalData::Standard(ref data)) => data.clone(),
841-
_ => panic!(),
832+
let Value::Principal(PrincipalData::Standard(p1_std_principal_data)) = p1.clone() else {
833+
panic!("Expected standard principal data");
842834
};
843835

844-
let p1_principal = match p1 {
845-
Value::Principal(ref data) => data.clone(),
846-
_ => panic!(),
836+
let Value::Principal(p1_principal) = p1.clone() else {
837+
panic!("Expected principal data");
847838
};
848839

849840
let token_contract_id =
@@ -939,9 +930,8 @@ fn test_overlapping_nfts(
939930

940931
let p1 = execute("'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR");
941932

942-
let p1_std_principal_data = match p1 {
943-
Value::Principal(PrincipalData::Standard(ref data)) => data.clone(),
944-
_ => panic!(),
933+
let Value::Principal(PrincipalData::Standard(p1_std_principal_data)) = p1 else {
934+
panic!("Expected standard principal data");
945935
};
946936

947937
let tokens_contract_id =
@@ -991,19 +981,16 @@ fn test_simple_naming_system(
991981
let p1 = execute("'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR");
992982
let p2 = execute("'SM2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQVX8X0G");
993983

994-
let p1_std_principal_data = match p1 {
995-
Value::Principal(PrincipalData::Standard(ref data)) => data.clone(),
996-
_ => panic!(),
984+
let Value::Principal(PrincipalData::Standard(p1_std_principal_data)) = p1.clone() else {
985+
panic!("Expected standard principal data");
997986
};
998987

999-
let p1_principal = match p1 {
1000-
Value::Principal(ref data) => data.clone(),
1001-
_ => panic!(),
988+
let Value::Principal(p1_principal) = p1.clone() else {
989+
panic!("Expected principal data");
1002990
};
1003991

1004-
let p2_principal = match p2 {
1005-
Value::Principal(ref data) => data.clone(),
1006-
_ => panic!(),
992+
let Value::Principal(p2_principal) = p2.clone() else {
993+
panic!("Expected principal data");
1007994
};
1008995

1009996
let placeholder_context =
@@ -1126,7 +1113,7 @@ fn test_simple_naming_system(
11261113
)
11271114
.unwrap();
11281115
assert!(is_err_code(&result, 0));
1129-
assert_eq!(asset_map.to_table().len(), 0);
1116+
assert!(asset_map.to_table().is_empty());
11301117

11311118
let (result, asset_map, _events) = execute_transaction(
11321119
&mut owned_env,
@@ -1157,7 +1144,7 @@ fn test_simple_naming_system(
11571144
.unwrap();
11581145

11591146
assert!(is_err_code(&result, 1));
1160-
assert_eq!(asset_map.to_table().len(), 0);
1147+
assert!(asset_map.to_table().is_empty());
11611148

11621149
let (result, asset_map, _events) = execute_transaction(
11631150
&mut owned_env,
@@ -1169,7 +1156,7 @@ fn test_simple_naming_system(
11691156
.unwrap();
11701157

11711158
assert!(is_committed(&result));
1172-
assert_eq!(asset_map.to_table().len(), 0);
1159+
assert!(asset_map.to_table().is_empty());
11731160

11741161
// let's transfer name
11751162

@@ -1183,7 +1170,7 @@ fn test_simple_naming_system(
11831170
.unwrap();
11841171

11851172
assert!(is_err_code(&result, 3));
1186-
assert_eq!(asset_map.to_table().len(), 0);
1173+
assert!(asset_map.to_table().is_empty());
11871174

11881175
let (result, asset_map, _events) = execute_transaction(
11891176
&mut owned_env,
@@ -1195,7 +1182,7 @@ fn test_simple_naming_system(
11951182
.unwrap();
11961183

11971184
assert!(is_err_code(&result, 1));
1198-
assert_eq!(asset_map.to_table().len(), 0);
1185+
assert!(asset_map.to_table().is_empty());
11991186

12001187
let (result, asset_map, _events) = execute_transaction(
12011188
&mut owned_env,
@@ -1207,7 +1194,7 @@ fn test_simple_naming_system(
12071194
.unwrap();
12081195

12091196
assert!(is_err_code(&result, 2));
1210-
assert_eq!(asset_map.to_table().len(), 0);
1197+
assert!(asset_map.to_table().is_empty());
12111198

12121199
let (result, asset_map, _events) = execute_transaction(
12131200
&mut owned_env,
@@ -1314,7 +1301,7 @@ fn test_simple_naming_system(
13141301
.unwrap();
13151302

13161303
assert!(is_committed(&result));
1317-
assert_eq!(asset_map.to_table().len(), 0);
1304+
assert!(asset_map.to_table().is_empty());
13181305

13191306
// p2 burning 8 (which belongs to p1) should succeed even though sender != tx_sender.
13201307
let (result, asset_map, _events) = execute_transaction(
@@ -1375,7 +1362,7 @@ fn test_simple_naming_system(
13751362
.unwrap();
13761363

13771364
assert!(is_committed(&result));
1378-
assert_eq!(asset_map.to_table().len(), 0);
1365+
assert!(asset_map.to_table().is_empty());
13791366

13801367
{
13811368
let mut env = owned_env.get_exec_environment(None, None, &placeholder_context);

libsigner/src/tests/http.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,10 @@ fn test_decode_http_request_err() {
8787
for (data, expected_err_type) in tests.iter() {
8888
let err = decode_http_request(data.as_bytes()).unwrap_err();
8989
match (err, expected_err_type) {
90-
(EventError::Deserialize(..), EventError::Deserialize(..)) => {}
91-
(EventError::MalformedRequest(..), EventError::MalformedRequest(..)) => {}
90+
(EventError::Deserialize(..), EventError::Deserialize(..))
91+
| (EventError::MalformedRequest(..), EventError::MalformedRequest(..)) => {}
9292
(x, y) => {
93-
error!("expected error mismatch: {:?} != {:?}", &y, &x);
94-
panic!();
93+
panic!("expected error mismatch: {x:?} != {y:?}");
9594
}
9695
}
9796
}
@@ -138,11 +137,10 @@ fn test_decode_http_response_err() {
138137
let err_type = decode_http_response(data.as_bytes()).unwrap_err();
139138
match (err_type, expected_err_type) {
140139
(RPCError::HttpError(x), RPCError::HttpError(y)) => assert_eq!(x, *y),
141-
(RPCError::Deserialize(_), RPCError::Deserialize(_)) => {}
142-
(RPCError::MalformedResponse(_), RPCError::MalformedResponse(_)) => {}
140+
(RPCError::Deserialize(_), RPCError::Deserialize(_))
141+
| (RPCError::MalformedResponse(_), RPCError::MalformedResponse(_)) => {}
143142
(x, y) => {
144-
error!("expected error mismatch: {:?} != {:?}", &y, &x);
145-
panic!();
143+
panic!("expected error mismatch: {y:?} != {x:?}");
146144
}
147145
}
148146
}
@@ -338,7 +336,7 @@ fn test_run_http_request_no_body() {
338336
)
339337
.unwrap();
340338

341-
assert_eq!(result_chunked.len(), 0);
342-
assert_eq!(result_plain.len(), 0);
339+
assert!(result_chunked.is_empty());
340+
assert!(result_plain.is_empty());
343341
}
344342
}

stacks-common/src/deps_common/httparse/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ mod tests {
939939
assert_eq!(req.method.unwrap(), "GET");
940940
assert_eq!(req.path.unwrap(), "/");
941941
assert_eq!(req.version.unwrap(), 1);
942-
assert_eq!(req.headers.len(), 0);
942+
assert!(req.headers.is_empty());
943943
}
944944
}
945945

@@ -950,7 +950,7 @@ mod tests {
950950
assert_eq!(req.method.unwrap(), "GET");
951951
assert_eq!(req.path.unwrap(), "/thing?data=a");
952952
assert_eq!(req.version.unwrap(), 1);
953-
assert_eq!(req.headers.len(), 0);
953+
assert!(req.headers.is_empty());
954954
}
955955
}
956956

@@ -961,7 +961,7 @@ mod tests {
961961
assert_eq!(req.method.unwrap(), "GET");
962962
assert_eq!(req.path.unwrap(), "/thing?data=a^");
963963
assert_eq!(req.version.unwrap(), 1);
964-
assert_eq!(req.headers.len(), 0);
964+
assert!(req.headers.is_empty());
965965
}
966966
}
967967

@@ -1084,7 +1084,7 @@ mod tests {
10841084
assert_eq!(req.method.unwrap(), "GET");
10851085
assert_eq!(req.path.unwrap(), "/");
10861086
assert_eq!(req.version.unwrap(), 1);
1087-
assert_eq!(req.headers.len(), 0);
1087+
assert!(req.headers.is_empty());
10881088
}
10891089
}
10901090

@@ -1095,7 +1095,7 @@ mod tests {
10951095
assert_eq!(req.method.unwrap(), "GET");
10961096
assert_eq!(req.path.unwrap(), "/");
10971097
assert_eq!(req.version.unwrap(), 1);
1098-
assert_eq!(req.headers.len(), 0);
1098+
assert!(req.headers.is_empty());
10991099
}
11001100
}
11011101

@@ -1106,7 +1106,7 @@ mod tests {
11061106
assert_eq!(req.method.unwrap(), "GET");
11071107
assert_eq!(req.path.unwrap(), "/\\?wayne\\=5");
11081108
assert_eq!(req.version.unwrap(), 1);
1109-
assert_eq!(req.headers.len(), 0);
1109+
assert!(req.headers.is_empty());
11101110
}
11111111
}
11121112

0 commit comments

Comments
 (0)