all: Fix remaining lint suggestions from Clippy 0.1.79.

This commit is contained in:
Lina Butler 2024-07-10 12:47:34 -07:00
Родитель a4c2b67deb
Коммит d4272d9230
25 изменённых файлов: 72 добавлений и 88 удалений

Просмотреть файл

@ -374,7 +374,7 @@ mod tests {
scope: "profile".to_string(),
token: "profiletok".to_string(),
key: None,
expires_at: u64::max_value(),
expires_at: u64::MAX,
},
);

Просмотреть файл

@ -121,7 +121,7 @@ mod tests {
scope: "profile".to_string(),
token: "profiletok".to_string(),
key: None,
expires_at: u64::max_value(),
expires_at: u64::MAX,
},
);
@ -159,7 +159,7 @@ mod tests {
scope: "profile".to_string(),
token: "bad_access_token".to_string(),
key: None,
expires_at: u64::max_value(),
expires_at: u64::MAX,
},
);
let mut refresh_token_scopes = std::collections::HashSet::new();

Просмотреть файл

@ -257,7 +257,7 @@ impl StateManager {
/// Used by the application to test auth token issues
pub fn simulate_temporary_auth_token_issue(&mut self) {
for (_, access_token) in self.persisted_state.access_token_cache.iter_mut() {
access_token.token = "invalid-data".to_owned()
"invalid-data".clone_into(&mut access_token.token)
}
}

Просмотреть файл

@ -844,7 +844,7 @@ mod event_store_tests {
assert_eq!(
store
.events
.get(&"event-1".to_string())
.get("event-1")
.unwrap()
.intervals
.get(&Interval::Months)
@ -857,7 +857,7 @@ mod event_store_tests {
assert_eq!(
store
.events
.get(&"event-1".to_string())
.get("event-1")
.unwrap()
.intervals
.get(&Interval::Months)
@ -869,7 +869,7 @@ mod event_store_tests {
assert_eq!(
store
.events
.get(&"event-1".to_string())
.get("event-1")
.unwrap()
.intervals
.get(&Interval::Days)
@ -882,7 +882,7 @@ mod event_store_tests {
assert_eq!(
store
.events
.get(&"event-1".to_string())
.get("event-1")
.unwrap()
.intervals
.get(&Interval::Days)
@ -894,7 +894,7 @@ mod event_store_tests {
assert_eq!(
store
.events
.get(&"event-1".to_string())
.get("event-1")
.unwrap()
.intervals
.get(&Interval::Days)
@ -906,7 +906,7 @@ mod event_store_tests {
assert_eq!(
store
.events
.get(&"event-1".to_string())
.get("event-1")
.unwrap()
.intervals
.get(&Interval::Days)
@ -919,7 +919,7 @@ mod event_store_tests {
assert_eq!(
store
.events
.get(&"event-2".to_string())
.get("event-2")
.unwrap()
.intervals
.get(&Interval::Days)
@ -932,7 +932,7 @@ mod event_store_tests {
assert_eq!(
store
.events
.get(&"event-2".to_string())
.get("event-2")
.unwrap()
.intervals
.get(&Interval::Days)
@ -953,7 +953,7 @@ mod event_store_tests {
assert_eq!(
store
.events
.get(&"test".to_string())
.get("test")
.unwrap()
.intervals
.get(&Interval::Minutes)
@ -965,7 +965,7 @@ mod event_store_tests {
assert_eq!(
store
.events
.get(&"test".to_string())
.get("test")
.unwrap()
.intervals
.get(&Interval::Hours)
@ -977,7 +977,7 @@ mod event_store_tests {
assert_eq!(
store
.events
.get(&"test".to_string())
.get("test")
.unwrap()
.intervals
.get(&Interval::Days)
@ -989,7 +989,7 @@ mod event_store_tests {
assert_eq!(
store
.events
.get(&"test".to_string())
.get("test")
.unwrap()
.intervals
.get(&Interval::Weeks)
@ -1001,7 +1001,7 @@ mod event_store_tests {
assert_eq!(
store
.events
.get(&"test".to_string())
.get("test")
.unwrap()
.intervals
.get(&Interval::Months)
@ -1013,7 +1013,7 @@ mod event_store_tests {
assert_eq!(
store
.events
.get(&"test".to_string())
.get("test")
.unwrap()
.intervals
.get(&Interval::Years)

Просмотреть файл

@ -735,7 +735,7 @@ fn test_evolver_experiment_update_enrolled_then_experiment_paused() -> Result<()
fn test_evolver_experiment_update_enrolled_then_targeting_changed() -> Result<()> {
let exp = get_test_experiments()[0].clone();
let (_, mut app_ctx, aru) = local_ctx();
app_ctx.app_name = "foobar".to_owned(); // Make the experiment targeting fail.
"foobar".clone_into(&mut app_ctx.app_name); // Make the experiment targeting fail.
let mut th = app_ctx.into();
let ids = no_coenrolling_features();
let mut evolver = enrollment_evolver(&mut th, &aru, &ids);
@ -1581,7 +1581,7 @@ fn test_evolver_multi_feature_experiments() -> Result<()> {
let feature_map =
map_features_by_feature_id(&enrollments, &next_experiments, &no_coenrolling_features());
assert_eq!(feature_map.len(), 1);
assert!(feature_map.get("about_welcome").is_none());
assert!(!feature_map.contains_key("about_welcome"));
assert_eq!(
feature_map.get("newtab").unwrap().slug,
"newtab-feature-experiment"
@ -2244,7 +2244,7 @@ fn test_map_features_by_feature_id_with_slug_replacement() -> Result<()> {
#[test]
fn test_evolve_enrollments_error_handling() -> Result<()> {
let existing_enrollments = vec![ExperimentEnrollment {
let existing_enrollments = [ExperimentEnrollment {
slug: "secure-gold".to_owned(),
status: EnrollmentStatus::Enrolled {
branch: "hello".to_owned(), // XXX this OK?

Просмотреть файл

@ -97,8 +97,7 @@ impl<'de> serde::de::Visitor<'de> for VisitTransitionSerdeVisitor {
}
fn visit_u64<E: serde::de::Error>(self, value: u64) -> Result<VisitType, E> {
use std::u8::MAX as U8_MAX;
if value > u64::from(U8_MAX) {
if value > u64::from(u8::MAX) {
// In practice this is *way* out of the valid range of VisitType, but
// serde requires us to implement this as visit_u64 so...
return Err(E::custom(format!("value out of u8 range: {}", value)));
@ -134,7 +133,7 @@ pub enum BookmarkType {
impl FromSql for BookmarkType {
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
let v = value.as_i64()?;
if v < 0 || v > i64::from(u8::max_value()) {
if v < 0 || v > i64::from(u8::MAX) {
return Err(FromSqlError::OutOfRange(v));
}
BookmarkType::from_u8(v as u8).ok_or(FromSqlError::OutOfRange(v))
@ -219,7 +218,7 @@ impl SyncStatus {
impl FromSql for SyncStatus {
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
let v = value.as_i64()?;
if v < 0 || v > i64::from(u8::max_value()) {
if v < 0 || v > i64::from(u8::MAX) {
return Err(FromSqlError::OutOfRange(v));
}
Ok(SyncStatus::from_u8(v as u8))

Просмотреть файл

@ -9,7 +9,7 @@
#[derive(Debug, thiserror::Error)]
struct Error {}
impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Ok(())
}
}
@ -18,7 +18,7 @@
struct ExternalError {}
impl Display for ExternalError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Ok(())
}
}

Просмотреть файл

@ -25,14 +25,14 @@
struct OtherExternalError {}
impl Display for ExternalError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Ok(())
}
}
impl Display for OtherExternalError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Ok(())
}
}

Просмотреть файл

@ -13,7 +13,7 @@
struct ExternalError {}
impl Display for ExternalError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Ok(())
}
}

Просмотреть файл

@ -2,8 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#![cfg(feature = "rusqlite_support")]
use crate::Guid;
use rusqlite::{
self,

Просмотреть файл

@ -2,8 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#![cfg(feature = "serde_support")]
use std::fmt;
use serde::{

Просмотреть файл

@ -22,7 +22,7 @@ use error::Result;
pub use error::{EncryptorDecryptorError, JwCryptoError};
use rc_crypto::agreement::EphemeralKeyPair;
use serde_derive::{Deserialize, Serialize};
use std::str::FromStr;
use std::{fmt, str::FromStr};
mod aes;
mod direct;
@ -210,10 +210,10 @@ impl FromStr for CompactJwe {
}
}
impl ToString for CompactJwe {
fn to_string(&self) -> String {
impl fmt::Display for CompactJwe {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
assert!(self.jwe_segments.len() == 5);
self.jwe_segments.join(".")
write!(f, "{}", self.jwe_segments.join("."))
}
}

Просмотреть файл

@ -197,10 +197,10 @@ impl Patch for Value {
(Value::Object(t), Value::Object(p)) => {
t.patch(p);
}
(Value::String(t), Value::String(p)) => *t = p.clone(),
(Value::String(t), Value::String(p)) => t.clone_from(p),
(Value::Bool(t), Value::Bool(p)) => *t = *p,
(Value::Number(t), Value::Number(p)) => *t = p.clone(),
(Value::Array(t), Value::Array(p)) => *t = p.clone(),
(Value::Array(t), Value::Array(p)) => t.clone_from(p),
(Value::Null, Value::Null) => (),
_ => return false,
};

Просмотреть файл

@ -345,7 +345,7 @@ impl ManifestFrontEnd {
fn get_prop_def_from_feature_field(&self, nm: &str, body: &FeatureFieldBody) -> PropDef {
let mut prop = self.get_prop_def_from_field(nm, &body.field);
prop.pref_key = body.pref_key.clone();
prop.pref_key.clone_from(&body.pref_key);
if let Some(s) = &body.string_alias {
prop.string_alias = Some(TypeRef::StringAlias(s.clone()));
}

Просмотреть файл

@ -69,7 +69,7 @@ mod tests {
#[test]
fn digest_cleanly_rejects_gigantic_messages() {
let message = vec![0; (std::i32::MAX as usize) + 1];
let message = vec![0; (i32::MAX as usize) + 1];
assert!(digest(&SHA256, &message).is_err());
}
}

Просмотреть файл

@ -66,8 +66,8 @@ mod tests {
#[test]
fn hkdf_rejects_gigantic_salt() {
if (std::u32::MAX as usize) < std::usize::MAX {
let salt_bytes = vec![0; (std::u32::MAX as usize) + 1];
if (u32::MAX as usize) < usize::MAX {
let salt_bytes = vec![0; (u32::MAX as usize) + 1];
let salt = hmac::SigningKey {
digest_alg: &digest::SHA256,
key_value: salt_bytes,
@ -79,9 +79,9 @@ mod tests {
#[test]
fn hkdf_rejects_gigantic_secret() {
if (std::u32::MAX as usize) < std::usize::MAX {
if (u32::MAX as usize) < usize::MAX {
let salt = hmac::SigningKey::new(&digest::SHA256, b"salt");
let secret = vec![0; (std::u32::MAX as usize) + 1];
let secret = vec![0; (u32::MAX as usize) + 1];
let mut out = vec![0u8; 8];
assert!(extract_and_expand(&salt, secret.as_slice(), b"info", &mut out).is_err());
}

Просмотреть файл

@ -151,8 +151,8 @@ mod tests {
#[test]
fn hmac_sign_cleanly_rejects_gigantic_keys() {
if (std::u32::MAX as usize) < std::usize::MAX {
let key_bytes = vec![0; (std::u32::MAX as usize) + 1];
if (u32::MAX as usize) < usize::MAX {
let key_bytes = vec![0; (u32::MAX as usize) + 1];
// Direct construction of SigningKey to avoid instantiating the array.
let key = SigningKey {
digest_alg: &digest::SHA256,
@ -164,8 +164,8 @@ mod tests {
#[test]
fn hmac_verify_cleanly_rejects_gigantic_keys() {
if (std::u32::MAX as usize) < std::usize::MAX {
let key_bytes = vec![0; (std::u32::MAX as usize) + 1];
if (u32::MAX as usize) < usize::MAX {
let key_bytes = vec![0; (u32::MAX as usize) + 1];
// Direct construction of VerificationKey to avoid instantiating the array.
let key = VerificationKey {
wrapped: SigningKey {
@ -180,19 +180,19 @@ mod tests {
#[test]
fn hmac_sign_cleanly_rejects_gigantic_messages() {
if (std::u32::MAX as usize) < std::usize::MAX {
if (u32::MAX as usize) < usize::MAX {
let key = SigningKey::new(&digest::SHA256, KEY);
let message = vec![0; (std::u32::MAX as usize) + 1];
let message = vec![0; (u32::MAX as usize) + 1];
assert!(sign(&key, &message).is_err());
}
}
#[test]
fn hmac_verify_cleanly_rejects_gigantic_messages() {
if (std::u32::MAX as usize) < std::usize::MAX {
if (u32::MAX as usize) < usize::MAX {
let key = VerificationKey::new(&digest::SHA256, KEY);
let signature = hex::decode(SIGNATURE_HEX).unwrap();
let message = vec![0; (std::u32::MAX as usize) + 1];
let message = vec![0; (u32::MAX as usize) + 1];
assert!(verify(&key, &message, &signature).is_err());
}
}

Просмотреть файл

@ -152,8 +152,8 @@ mod tests {
#[test]
fn test_rejects_gaigantic_salt() {
if (std::u32::MAX as usize) < std::usize::MAX {
let salt = vec![0; (std::u32::MAX as usize) + 1];
if (u32::MAX as usize) < usize::MAX {
let salt = vec![0; (u32::MAX as usize) + 1];
let mut out = vec![0u8; 1];
let password = b"password";
assert!(derive(password, &salt, 1, HashAlgorithm::SHA256, &mut out).is_err());
@ -161,8 +161,8 @@ mod tests {
}
#[test]
fn test_rejects_gaigantic_password() {
if (std::u32::MAX as usize) < std::usize::MAX {
let password = vec![0; (std::u32::MAX as usize) + 1];
if (u32::MAX as usize) < usize::MAX {
let password = vec![0; (u32::MAX as usize) + 1];
let mut out = vec![0u8; 1];
let salt = b"salt";
assert!(derive(&password, salt, 1, HashAlgorithm::SHA256, &mut out).is_err());
@ -171,9 +171,9 @@ mod tests {
#[test]
fn test_rejects_gaigantic_out() {
if (std::u32::MAX as usize) < std::usize::MAX {
if (u32::MAX as usize) < usize::MAX {
let password = b"password";
let mut out = vec![0; (std::u32::MAX as usize) + 1];
let mut out = vec![0; (u32::MAX as usize) + 1];
let salt = b"salt";
assert!(derive(password, salt, 1, HashAlgorithm::SHA256, &mut out).is_err());
}
@ -184,13 +184,6 @@ mod tests {
let password = b"password";
let mut out = vec![0; 32];
let salt = b"salt";
assert!(derive(
password,
salt,
std::u32::MAX,
HashAlgorithm::SHA256,
&mut out
)
.is_err());
assert!(derive(password, salt, u32::MAX, HashAlgorithm::SHA256, &mut out).is_err());
}
}

Просмотреть файл

@ -63,7 +63,7 @@ mod tests {
#[test]
fn random_fill_rejects_attempts_to_fill_gigantic_arrays() {
let max_size: usize = std::i32::MAX as usize;
let max_size: usize = i32::MAX as usize;
let mut out = vec![0u8; max_size + 1];
assert!(fill(&mut out).is_err());
}

Просмотреть файл

@ -103,10 +103,10 @@ impl Default for InfoConfiguration {
InfoConfiguration {
max_request_bytes: default_max_request_bytes(),
max_record_payload_bytes: default_max_record_payload_bytes(),
max_post_records: usize::max_value(),
max_post_bytes: usize::max_value(),
max_total_records: usize::max_value(),
max_total_bytes: usize::max_value(),
max_post_records: usize::MAX,
max_post_bytes: usize::MAX,
max_total_records: usize::MAX,
max_total_bytes: usize::MAX,
}
}
}

Просмотреть файл

@ -36,7 +36,7 @@ pub enum Sync15ClientResponse<T> {
fn parse_seconds(seconds_str: &str) -> Option<u32> {
let secs = seconds_str.parse::<f64>().ok()?.ceil();
// Note: u32 doesn't impl TryFrom<f64> :(
if !secs.is_finite() || secs < 0.0 || secs > f64::from(u32::max_value()) {
if !secs.is_finite() || secs < 0.0 || secs > f64::from(u32::MAX) {
log::warn!("invalid backoff value: {}", secs);
None
} else {

Просмотреть файл

@ -16,9 +16,9 @@ use serde::{ser, Serialize, Serializer};
// A test helper, used by the many test modules below.
#[cfg(test)]
fn assert_json<T: ?Sized>(v: &T, expected: serde_json::Value)
fn assert_json<T>(v: &T, expected: serde_json::Value)
where
T: serde::Serialize,
T: serde::Serialize + ?Sized,
{
assert_eq!(
serde_json::to_value(v).expect("should get a value"),

Просмотреть файл

@ -494,7 +494,7 @@ impl TabsStorage {
let Some(conn) = self.open_if_exists()? else {
return Ok(Vec::new());
};
let records: Vec<Option<PendingCommand>> = match conn.query_rows_and_then_cached(
let result = conn.query_rows_and_then_cached(
&format!(
"SELECT device_id, command, url, time_requested, time_sent
FROM remote_tab_commands
@ -525,15 +525,14 @@ impl TabsStorage {
},
}))
},
) {
Ok(records) => records,
);
Ok(match result {
Ok(records) => records.into_iter().flatten().collect(),
Err(e) => {
error_support::report_error!("tabs-get_unsent", "Failed to read database: {}", e);
return Ok(Vec::new());
Vec::new()
}
};
Ok(records.into_iter().flatten().collect())
})
}
pub fn set_pending_command_sent(&mut self, command: &PendingCommand) -> Result<bool> {

Просмотреть файл

@ -30,10 +30,7 @@ impl TabsStore {
// like remote_tabs, but serves the uniffi layer
pub fn get_all(&self) -> Vec<ClientRemoteTabs> {
match self.remote_tabs() {
Some(list) => list,
None => vec![],
}
self.remote_tabs().unwrap_or_default()
}
pub fn remote_tabs(&self) -> Option<Vec<ClientRemoteTabs>> {

Просмотреть файл

@ -67,7 +67,7 @@ impl Backend for FfiBackend {
.status
.ok_or_else(|| backend_error!("Missing HTTP status"))?;
if status < 0 || status > i32::from(u16::max_value()) {
if status < 0 || status > i32::from(u16::MAX) {
return Err(backend_error!("Illegal HTTP status: {}", status));
}