diff --git a/components/config/basedir.rs b/components/config/basedir.rs index fbae2a7edca..fd17e482b88 100644 --- a/components/config/basedir.rs +++ b/components/config/basedir.rs @@ -35,7 +35,7 @@ pub fn default_config_dir() -> Option { Some(config_dir) } -#[cfg(all(target_os = "windows"))] +#[cfg(target_os = "windows")] pub fn default_config_dir() -> Option { let mut config_dir = ::dirs_next::config_dir().unwrap(); config_dir.push("Servo"); diff --git a/components/config/opts.rs b/components/config/opts.rs index 5cf394bb297..43348fccc2e 100644 --- a/components/config/opts.rs +++ b/components/config/opts.rs @@ -7,7 +7,7 @@ use std::default::Default; use std::fs::{self, File}; -use std::io::{self, Read, Write}; +use std::io::Read; use std::path::{Path, PathBuf}; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{RwLock, RwLockReadGuard}; @@ -385,7 +385,7 @@ pub enum OutputOptions { } fn args_fail(msg: &str) -> ! { - writeln!(io::stderr(), "{}", msg).unwrap(); + eprintln!("{}", msg); process::exit(1) } @@ -793,7 +793,7 @@ pub fn from_cmdline_args(mut opts: Options, args: &[String]) -> ArgumentParsingR set_pref!(layout.threads, layout_threads as i64); } - return ArgumentParsingResult::ChromeProcess(opt_match); + ArgumentParsingResult::ChromeProcess(opt_match) } pub enum ArgumentParsingResult { diff --git a/components/config/pref_util.rs b/components/config/pref_util.rs index 11e2f7f94a8..d8cfa78aaea 100644 --- a/components/config/pref_util.rs +++ b/components/config/pref_util.rs @@ -55,10 +55,7 @@ impl PrefValue { } pub fn is_missing(&self) -> bool { - match self { - PrefValue::Missing => true, - _ => false, - } + matches!(self, PrefValue::Missing) } pub fn from_json_value(value: &Value) -> Option { @@ -164,7 +161,7 @@ impl From for [f64; 4] { let mut f = values.into_iter().map(|v| v.try_into()); if f.all(|v| v.is_ok()) { let f = f.flatten().collect::>(); - return [f[0], f[1], f[2], f[3]]; + [f[0], f[1], f[2], f[3]] } else { panic!( "Cannot convert PrefValue to {:?}", @@ -191,7 +188,7 @@ pub enum PrefError { impl fmt::Display for PrefError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - PrefError::NoSuchPref(s) | PrefError::InvalidValue(s) => f.write_str(&s), + PrefError::NoSuchPref(s) | PrefError::InvalidValue(s) => f.write_str(s), PrefError::JsonParseErr(e) => e.fmt(f), } } @@ -201,6 +198,7 @@ impl std::error::Error for PrefError {} pub struct Accessor { pub getter: Box V + Sync>, + #[allow(clippy::type_complexity)] pub setter: Box, } @@ -261,7 +259,7 @@ impl<'m, P: Clone> Preferences<'m, P> { } /// Creates an iterator over all keys and values - pub fn iter<'a>(&'a self) -> impl Iterator + 'a { + pub fn iter(&self) -> impl Iterator + '_ { let prefs = self.user_prefs.read().unwrap(); self.accessors .iter() @@ -269,16 +267,17 @@ impl<'m, P: Clone> Preferences<'m, P> { } /// Creates an iterator over all keys - pub fn keys<'a>(&'a self) -> impl Iterator + 'a { + pub fn keys(&self) -> impl Iterator { self.accessors.keys().map(String::as_str) } - fn set_inner(&self, key: &str, mut prefs: &mut P, val: V) -> Result<(), PrefError> + fn set_inner(&self, key: &str, prefs: &mut P, val: V) -> Result<(), PrefError> where V: Into, { if let Some(accessor) = self.accessors.get(key) { - Ok((accessor.setter)(&mut prefs, val.into())) + (accessor.setter)(prefs, val.into()); + Ok(()) } else { Err(PrefError::NoSuchPref(String::from(key))) } diff --git a/components/config/prefs.rs b/components/config/prefs.rs index 826605da6d9..f9c7c39bf82 100644 --- a/components/config/prefs.rs +++ b/components/config/prefs.rs @@ -67,7 +67,7 @@ pub fn add_user_prefs(prefs: HashMap) { for (key, value) in prefs.iter() { set_stylo_pref_ref(key, value); } - if let Err(error) = PREFS.set_all(prefs.into_iter()) { + if let Err(error) = PREFS.set_all(prefs) { panic!("Error setting preference: {:?}", error); } } @@ -106,15 +106,15 @@ impl TryFrom<&PrefValue> for StyloPrefValue { type Error = TryFromPrefValueError; fn try_from(value: &PrefValue) -> Result { - match value { - &PrefValue::Int(value) => { + match *value { + PrefValue::Int(value) => { if let Ok(value) = value.try_into() { Ok(Self::Int(value)) } else { Err(TryFromPrefValueError::IntegerOverflow(value)) } }, - &PrefValue::Bool(value) => Ok(Self::Bool(value)), + PrefValue::Bool(value) => Ok(Self::Bool(value)), _ => Err(TryFromPrefValueError::UnmappedType), } } @@ -122,7 +122,7 @@ impl TryFrom<&PrefValue> for StyloPrefValue { pub fn read_prefs_map(txt: &str) -> Result, PrefError> { let prefs: HashMap = - serde_json::from_str(txt).map_err(|e| PrefError::JsonParseErr(e))?; + serde_json::from_str(txt).map_err(PrefError::JsonParseErr)?; prefs .into_iter() .map(|(k, pref_value)| { @@ -133,7 +133,7 @@ pub fn read_prefs_map(txt: &str) -> Result, PrefError Value::Number(n) if n.is_f64() => PrefValue::Float(n.as_f64().unwrap()), Value::String(s) => PrefValue::Str(s.to_owned()), Value::Array(v) => { - let mut array = v.iter().map(|v| PrefValue::from_json_value(v)); + let mut array = v.iter().map(PrefValue::from_json_value); if array.all(|v| v.is_some()) { PrefValue::Array(array.flatten().collect()) } else { diff --git a/components/config_plugins/parse.rs b/components/config_plugins/parse.rs index 3a390f2f07f..63a3d66dfda 100644 --- a/components/config_plugins/parse.rs +++ b/components/config_plugins/parse.rs @@ -132,7 +132,7 @@ impl Parse for RootTypeDef { impl Parse for NewTypeDef { fn parse(input: ParseStream<'_>) -> Result { let content; - #[allow(clippy::eval_order_dependence)] + #[allow(clippy::mixed_read_write_in_expression)] Ok(NewTypeDef { _braces: braced!(content in input), fields: Punctuated::parse_terminated_with(&content, Field::parse)?,