Skip to content

Commit 26cdd6a

Browse files
authored
Fix some pedantic Clippy warnings. (#4531)
## Motivation Many of the non-default Clippy lints in the "pedantic" category are actually useful, especially the "don't re-implement the standard library" ones. ## Proposal Fix many pedantic warnings. Deny some of the lints. ## Test Plan CI ## Release Plan - Nothing to do / These changes follow the usual release cycle. - (But could be backported.) ## Links - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent d075c01 commit 26cdd6a

File tree

81 files changed

+441
-646
lines changed

Some content is hidden

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

81 files changed

+441
-646
lines changed

Cargo.lock

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,4 +361,21 @@ branch = "post-message"
361361
config = "spellcheck-cfg.toml"
362362

363363
[workspace.lints.clippy]
364+
doc_link_with_quotes = "deny"
365+
filter_map_next = "deny"
366+
iter_filter_is_some = "deny"
364367
large_futures = "deny"
368+
large_stack_arrays = "deny"
369+
large_types_passed_by_value = "deny"
370+
macro_use_imports = "deny"
371+
manual_instant_elapsed = "deny"
372+
manual_is_power_of_two = "deny"
373+
manual_is_variant_and = "deny"
374+
map_unwrap_or = "deny"
375+
mismatching_type_param_order = "deny"
376+
naive_bytecount = "deny"
377+
non_std_lazy_statics = "deny"
378+
range_minus_one = "deny"
379+
range_plus_one = "deny"
380+
ref_option_ref = "deny"
381+
str_split_at_newline = "deny"

examples/create-and-call/tests/test_create_and_call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async fn test_create_and_call() {
2424
.expect("Failed to get absolute path to counter-no-graphql");
2525

2626
// Build and find the counter-no-graphql bytecode files
27-
ActiveChain::build_bytecode_files_in(&counter_no_graphql_path).await;
27+
ActiveChain::build_bytecode_files_in(&counter_no_graphql_path);
2828
let (counter_contract, counter_service) =
2929
ActiveChain::find_bytecode_files_in(&counter_no_graphql_path).await;
3030

examples/gen-nft/src/model.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ impl ModelContext {
135135
if index_pos == 256 {
136136
return Ok(output
137137
.rsplit_once('.')
138-
.map(|(before, _)| format!("{}.", before))
139-
.unwrap_or_else(|| output.to_string()));
138+
.map_or_else(|| output.to_string(), |(before, _)| format!("{}.", before)));
140139
}
141140
let logits = model.forward(&input, index_pos)?;
142141
let logits = logits.i((0, logits.dim(1)? - 1))?;

examples/llm/src/service.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,7 @@ impl ModelContext {
223223
if index_pos == 256 {
224224
return Ok(output
225225
.rsplit_once('.')
226-
.map(|(before, _)| format!("{}.", before))
227-
.unwrap_or_else(|| output.to_string()));
226+
.map_or_else(|| output.to_string(), |(before, _)| format!("{}.", before)));
228227
}
229228
let logits = model.forward(&input, index_pos)?;
230229
let logits = logits.i((0, logits.dim(1)? - 1))?;

linera-base/src/crypto/ed25519.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Ed25519SecretKey {
3737
#[cfg(all(with_getrandom, with_testing))]
3838
/// Generates a new key pair using the operating system's RNG.
3939
///
40-
/// If you want control over the RNG, use `generate_from`[Ed25519SecretKey::generate_from].
40+
/// If you want control over the RNG, use [`Ed25519SecretKey::generate_from`].
4141
pub fn generate() -> Self {
4242
let mut rng = rand::rngs::OsRng;
4343
Self::generate_from(&mut rng)
@@ -345,7 +345,7 @@ impl Ed25519Signature {
345345
let mut messages = Vec::new();
346346
let mut signatures = Vec::new();
347347
let mut public_keys = Vec::new();
348-
for (addr, sig) in votes.into_iter() {
348+
for (addr, sig) in votes {
349349
messages.push(msg.as_slice());
350350
signatures.push(sig.0);
351351
public_keys.push(dalek::VerifyingKey::from_bytes(&addr.0)?);

linera-base/src/crypto/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ impl AccountSignature {
272272
bcs::from_bytes(bytes).map_err(CryptoError::SignatureParseError)
273273
}
274274

275-
/// Returns the AccountOwner of the account that signed the value.
275+
/// Returns the [`AccountOwner`] of the account that signed the value.
276276
pub fn owner(&self) -> AccountOwner {
277277
match self {
278278
AccountSignature::Ed25519 { public_key, .. } => AccountOwner::from(*public_key),

linera-base/src/data_types.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,16 +1013,14 @@ impl ApplicationPermissions {
10131013
pub fn can_call_services(&self, app_id: &ApplicationId) -> bool {
10141014
self.call_service_as_oracle
10151015
.as_ref()
1016-
.map(|app_ids| app_ids.contains(app_id))
1017-
.unwrap_or(true)
1016+
.is_none_or(|app_ids| app_ids.contains(app_id))
10181017
}
10191018

10201019
/// Returns whether the given application can make HTTP requests.
10211020
pub fn can_make_http_requests(&self, app_id: &ApplicationId) -> bool {
10221021
self.make_http_requests
10231022
.as_ref()
1024-
.map(|app_ids| app_ids.contains(app_id))
1025-
.unwrap_or(true)
1023+
.is_none_or(|app_ids| app_ids.contains(app_id))
10261024
}
10271025
}
10281026

@@ -1120,7 +1118,7 @@ impl Bytecode {
11201118
}
11211119

11221120
/// Load bytecode from a Wasm module file.
1123-
pub async fn load_from_file(path: impl AsRef<std::path::Path>) -> std::io::Result<Self> {
1121+
pub fn load_from_file(path: impl AsRef<std::path::Path>) -> std::io::Result<Self> {
11241122
let bytes = fs::read(path)?;
11251123
Ok(Bytecode { bytes })
11261124
}
@@ -1332,13 +1330,13 @@ impl BlobContent {
13321330
&self.bytes
13331331
}
13341332

1335-
/// Convert a BlobContent into `Vec<u8>` without cloning if possible.
1333+
/// Converts a `BlobContent` into `Vec<u8>` without cloning if possible.
13361334
pub fn into_vec_or_clone(self) -> Vec<u8> {
13371335
let bytes = Arc::unwrap_or_clone(self.bytes);
13381336
bytes.into_vec()
13391337
}
13401338

1341-
/// Get the Arc<Box<[u8]>> directly without cloning.
1339+
/// Gets the `Arc<Box<[u8]>>` directly without cloning.
13421340
pub fn into_arc_bytes(self) -> Arc<Box<[u8]>> {
13431341
self.bytes
13441342
}
@@ -1459,7 +1457,7 @@ impl Blob {
14591457
}
14601458

14611459
/// Loads data blob from a file.
1462-
pub async fn load_data_blob_from_file(path: impl AsRef<Path>) -> io::Result<Self> {
1460+
pub fn load_data_blob_from_file(path: impl AsRef<Path>) -> io::Result<Self> {
14631461
Ok(Self::new_data(fs::read(path)?))
14641462
}
14651463

linera-base/src/ownership.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,7 @@ impl ChainOwnership {
137137
Some(tc.base_timeout)
138138
}
139139
Round::MultiLeader(_) => None,
140-
Round::SingleLeader(r) => {
141-
let increment = tc.timeout_increment.saturating_mul(u64::from(r));
142-
Some(tc.base_timeout.saturating_add(increment))
143-
}
144-
Round::Validator(r) => {
140+
Round::SingleLeader(r) | Round::Validator(r) => {
145141
let increment = tc.timeout_increment.saturating_mul(u64::from(r));
146142
Some(tc.base_timeout.saturating_add(increment))
147143
}

linera-base/src/tracing.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ pub fn init(log_name: &str) {
4040

4141
let span_events = std::env::var("RUST_LOG_SPAN_EVENTS")
4242
.ok()
43-
.map(|s| fmt_span_from_str(&s))
44-
.unwrap_or(FmtSpan::NONE);
43+
.map_or(FmtSpan::NONE, |s| fmt_span_from_str(&s));
4544

4645
let format = std::env::var("RUST_LOG_FORMAT").ok();
4746

0 commit comments

Comments
 (0)