Skip to content

Commit dc3401f

Browse files
committed
Fix compiler error from Rust 1.87, pacify Clippy 1.88
1 parent b4dcc84 commit dc3401f

10 files changed

Lines changed: 59 additions & 45 deletions

File tree

api-server/scanner-lib/src/blockchain_state/pos_adapter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ impl PoSAdapter {
3838
) -> Self {
3939
let pool_balances = (pool_data.staker_balance().expect("cannot fail")
4040
+ delegations
41-
.iter()
42-
.map(|(_, d)| *d.balance())
41+
.values()
42+
.map(|d| *d.balance())
4343
.sum::<Option<Amount>>()
4444
.expect("cannot fail"))
4545
.expect("cannot fail");

clippy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ disallowed-methods = []
22
disallowed-types = []
33
enforced-import-renames = []
44
large-error-threshold = 256
5+
enum-variant-size-threshold = 256

dns-server/src/crawler_p2p/crawler/tests/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,8 @@ fn long_offline(#[case] seed: Seed) {
444444
for _ in 0..24 * 7 {
445445
crawler.timer(Duration::from_secs(3600), &mut rng);
446446
}
447-
assert!(!crawler.connect_requests.iter().any(|addr| *addr == loaded_node));
448-
assert!(crawler.connect_requests.iter().any(|addr| *addr == added_node));
447+
assert!(!crawler.connect_requests.contains(&loaded_node));
448+
assert!(crawler.connect_requests.contains(&added_node));
449449
crawler.connect_requests.clear();
450450
}
451451

do_checks.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@ cargo fmt --check -- --config newline_style=Unix
1313
# Note: "--allow duplicate" silences the warning "found x duplicate entries for crate y".
1414
cargo deny check --allow duplicate --hide-inclusion-graph
1515

16-
# Checks enabled everywhere, including tests, benchmarks
16+
# Checks enabled everywhere, including tests, benchmarks.
17+
# Note about "uninlined_format_args": this is about changing `format!("{}", x)` to `format!("{x}")`.
18+
# Most of the time this makes the code look better, but:
19+
# * there are way too many places like this;
20+
# * in some cases it may lead to uglier code; in particular, when the format string is already
21+
# quite long.
22+
# So we disable it for now.
1723
cargo clippy --all-features --workspace --all-targets -- \
1824
-D warnings \
1925
-A clippy::unnecessary_literal_unwrap \
2026
-A clippy::new_without_default \
27+
-A clippy::uninlined_format_args \
2128
-D clippy::implicit_saturating_sub \
2229
-D clippy::implicit_clone \
2330
-D clippy::map_unwrap_or \

mempool/src/pool/tx_pool/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@ pub enum TxAdditionAttemptOutcome {
701701
}
702702

703703
/// Result of transaction validation
704+
#[allow(clippy::large_enum_variant)]
704705
enum TxValidationOutcome {
705706
Valid {
706707
fee: Fee,

serialization/core/tests/simple_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ fn test_scale_options() {
201201
assert_eq!(dec, Some(OptionWrapper::new(result)));
202202

203203
// Decode and encode 1_048_576 chars 'X'
204-
let result = Some(format!("!{:X<4194304}!", ""));
204+
let result = Some(std::iter::repeat_n('X', 1_048_576).collect::<String>());
205205
let enc = OptionWrapper::encode(&OptionWrapper::new(result.clone()));
206206
assert!(!enc.is_empty());
207207
let dec = OptionWrapper::decode_all(&mut &enc[..]).ok();

test/runner/functional.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ where
7070
fn find_python_exe() -> PathBuf {
7171
let possible_python_execs = ["python3", "python"];
7272

73-
let file_suffix = (env::consts::OS == "windows").then_some(".exe").unwrap_or_default();
73+
let file_suffix = if env::consts::OS == "windows" {
74+
".exe"
75+
} else {
76+
""
77+
};
7478

7579
let python_exe = possible_python_execs
7680
.into_iter()

wallet/src/wallet/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ pub enum WalletError {
249249
#[error("Input cannot be spent {0:?}")]
250250
InputCannotBeSpent(TxOutput),
251251
#[error("Failed to convert partially signed tx to signed")]
252-
FailedToConvertPartiallySignedTx(PartiallySignedTransaction),
252+
FailedToConvertPartiallySignedTx(Box<PartiallySignedTransaction>),
253253
#[error("The specified address is not found in this wallet")]
254254
AddressNotFound,
255255
#[error("The specified standalone address {0} is not found in this wallet")]
@@ -1163,7 +1163,7 @@ where
11631163

11641164
if !is_fully_signed {
11651165
return Err(error_mapper(WalletError::FailedToConvertPartiallySignedTx(
1166-
ptx,
1166+
Box::new(ptx),
11671167
)));
11681168
}
11691169

wallet/wallet-cli-commands/src/command_handler/mod.rs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -634,12 +634,12 @@ where
634634
let summary = signed_tx.transaction().text_summary(chain_config);
635635
let result_hex: HexEncoded<SignedTransaction> = signed_tx.into();
636636

637-
let qr_code_string = (!self.no_qr)
638-
.then(|| {
639-
let qr_code = qrcode_or_error_string(&result_hex.to_string());
640-
format!("\n\nOr scan the Qr code with it:\n\n{qr_code}")
641-
})
642-
.unwrap_or_default();
637+
let qr_code_string = if self.no_qr {
638+
String::new()
639+
} else {
640+
let qr_code = qrcode_or_error_string(&result_hex.to_string());
641+
format!("\n\nOr scan the Qr code with it:\n\n{qr_code}")
642+
};
643643

644644
format!(
645645
"The transaction has been fully signed and is ready to be broadcast to network. \
@@ -651,12 +651,12 @@ where
651651
let result_hex: HexEncoded<PartiallySignedTransaction> =
652652
partially_signed_tx.into();
653653

654-
let qr_code_string = (!self.no_qr)
655-
.then(|| {
656-
let qr_code = qrcode_or_error_string(&result_hex.to_string());
657-
format!("\n\nOr scan the Qr code with it:\n\n{qr_code}")
658-
})
659-
.unwrap_or_default();
654+
let qr_code_string = if self.no_qr {
655+
String::new()
656+
} else {
657+
let qr_code = qrcode_or_error_string(&result_hex.to_string());
658+
format!("\n\nOr scan the Qr code with it:\n\n{qr_code}")
659+
};
660660

661661
let prev_sigs = result
662662
.previous_signatures
@@ -692,12 +692,12 @@ where
692692
let result =
693693
wallet.sign_challenge_hex(selected_account, challenge, address).await?;
694694

695-
let qr_code_string = (!self.no_qr)
696-
.then(|| {
697-
let qr_code = qrcode_or_error_string(&result);
698-
format!("\n\nThe following qr code also contains the signature for easy transport:\n{qr_code}")
699-
})
700-
.unwrap_or_default();
695+
let qr_code_string = if self.no_qr {
696+
String::new()
697+
} else {
698+
let qr_code = qrcode_or_error_string(&result);
699+
format!("\n\nThe following qr code also contains the signature for easy transport:\n{qr_code}")
700+
};
701701

702702
Ok(ConsoleCommand::Print(format!(
703703
"The generated hex encoded signature is\n\n{result}{qr_code_string}",
@@ -711,12 +711,12 @@ where
711711
let (wallet, selected_account) = wallet_and_selected_acc(&mut self.wallet).await?;
712712
let result = wallet.sign_challenge(selected_account, challenge, address).await?;
713713

714-
let qr_code_string = (!self.no_qr)
715-
.then(|| {
716-
let qr_code = qrcode_or_error_string(&result);
717-
format!("\n\nThe following qr code also contains the signature for easy transport:\n{qr_code}")
718-
})
719-
.unwrap_or_default();
714+
let qr_code_string = if self.no_qr {
715+
String::new()
716+
} else {
717+
let qr_code = qrcode_or_error_string(&result);
718+
format!("\n\nThe following qr code also contains the signature for easy transport:\n{qr_code}")
719+
};
720720

721721
Ok(ConsoleCommand::Print(format!(
722722
"The generated hex encoded signature is\n\n{result}{qr_code_string}",
@@ -1461,12 +1461,12 @@ where
14611461

14621462
let summary = tx.tx().text_summary(chain_config);
14631463

1464-
let qr_code_string = (!self.no_qr)
1465-
.then(|| {
1466-
let qr_code = qrcode_or_error_string(&hex);
1467-
format!("\n\nOr scan the Qr code with it:\n\n{qr_code}")
1468-
})
1469-
.unwrap_or_default();
1464+
let qr_code_string = if self.no_qr {
1465+
String::new()
1466+
} else {
1467+
let qr_code = qrcode_or_error_string(&hex);
1468+
format!("\n\nOr scan the Qr code with it:\n\n{qr_code}")
1469+
};
14701470

14711471
let mut output_str = format!(
14721472
"Send transaction created. \
@@ -1761,12 +1761,12 @@ where
17611761
)
17621762
.await?;
17631763

1764-
let qr_code_string = (!self.no_qr)
1765-
.then(|| {
1766-
let qr_code = qrcode_or_error_string(&result_hex.to_string());
1767-
format!("\n\nOr scan the Qr code with it:\n\n{qr_code}")
1768-
})
1769-
.unwrap_or_default();
1764+
let qr_code_string = if self.no_qr {
1765+
String::new()
1766+
} else {
1767+
let qr_code = qrcode_or_error_string(&result_hex.to_string());
1768+
format!("\n\nOr scan the Qr code with it:\n\n{qr_code}")
1769+
};
17701770

17711771
let output_str = format!(
17721772
"Decommission transaction created. \

wallet/wallet-controller/src/runtime_wallet.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ use wallet_types::{
6262
#[cfg(feature = "trezor")]
6363
use wallet::signer::trezor_signer::TrezorSignerProvider;
6464

65+
#[allow(clippy::large_enum_variant)]
6566
pub enum RuntimeWallet<B: storage::Backend + 'static> {
6667
Software(Wallet<B, SoftwareSignerProvider>),
6768
#[cfg(feature = "trezor")]

0 commit comments

Comments
 (0)