chore: fix clippy warnings for rust 1.67 (#4855)

This commit is contained in:
David Knaack 2023-01-27 10:33:24 +01:00 committed by GitHub
parent 21090b2e94
commit 5e123fcbce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 27 additions and 34 deletions

View File

@ -130,9 +130,7 @@ pub fn print_configuration(use_default: bool, paths: &[String]) {
fn extract_toml_paths(mut config: toml::Value, paths: &[String]) -> toml::Value { fn extract_toml_paths(mut config: toml::Value, paths: &[String]) -> toml::Value {
// Extract all the requested sections into a new configuration. // Extract all the requested sections into a new configuration.
let mut subset = toml::value::Table::new(); let mut subset = toml::value::Table::new();
let config = if let Some(config) = config.as_table_mut() { let Some(config) = config.as_table_mut() else {
config
} else {
// This function doesn't make any sense if the root is not a table. // This function doesn't make any sense if the root is not a table.
return toml::Value::Table(subset); return toml::Value::Table(subset);
}; };
@ -156,9 +154,7 @@ fn extract_toml_paths(mut config: toml::Value, paths: &[String]) -> toml::Value
} }
// Extract the value to move. // Extract the value to move.
let value = if let Some(value) = source_cursor.remove(end) { let Some(value) = source_cursor.remove(end) else {
value
} else {
// We didn't find a value for this path, so move on to the next path. // We didn't find a value for this path, so move on to the next path.
continue 'paths; continue 'paths;
}; };

View File

@ -250,9 +250,9 @@ impl<'a> Context<'a> {
} }
/// Will lazily get repo root and branch when a module requests it. /// Will lazily get repo root and branch when a module requests it.
pub fn get_repo(&self) -> Result<&Repo, git::discover::Error> { pub fn get_repo(&self) -> Result<&Repo, Box<git::discover::Error>> {
self.repo self.repo
.get_or_try_init(|| -> Result<Repo, git::discover::Error> { .get_or_try_init(|| -> Result<Repo, Box<git::discover::Error>> {
// custom open options // custom open options
let mut git_open_opts_map = let mut git_open_opts_map =
git_sec::trust::Mapping::<git::open::Options>::default(); git_sec::trust::Mapping::<git::open::Options>::default();
@ -286,7 +286,7 @@ impl<'a> Context<'a> {
Ok(repo) => repo, Ok(repo) => repo,
Err(e) => { Err(e) => {
log::debug!("Failed to find git repo: {e}"); log::debug!("Failed to find git repo: {e}");
return Err(e); return Err(Box::new(e));
} }
}; };

View File

@ -35,10 +35,9 @@ pub fn get_log_dir() -> PathBuf {
/// Deletes all log files in the log directory that were modified more than 24 hours ago. /// Deletes all log files in the log directory that were modified more than 24 hours ago.
pub fn cleanup_log_files<P: AsRef<Path>>(path: P) { pub fn cleanup_log_files<P: AsRef<Path>>(path: P) {
let log_dir = path.as_ref(); let log_dir = path.as_ref();
let log_files = match fs::read_dir(log_dir) { let Ok(log_files) = fs::read_dir(log_dir) else {
Ok(log_files) => log_files,
// Avoid noisily handling errors in this cleanup function. // Avoid noisily handling errors in this cleanup function.
Err(_) => return, return
}; };
for file in log_files { for file in log_files {

View File

@ -52,9 +52,9 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
} }
#[cfg(not(feature = "notify"))] #[cfg(not(feature = "notify"))]
fn undistract_me<'a, 'b>( fn undistract_me<'a>(
module: Module<'a>, module: Module<'a>,
_config: &'b CmdDurationConfig, _config: &CmdDurationConfig,
_context: &'a Context, _context: &'a Context,
_elapsed: u128, _elapsed: u128,
) -> Module<'a> { ) -> Module<'a> {
@ -62,9 +62,9 @@ fn undistract_me<'a, 'b>(
} }
#[cfg(feature = "notify")] #[cfg(feature = "notify")]
fn undistract_me<'a, 'b>( fn undistract_me<'a>(
module: Module<'a>, module: Module<'a>,
config: &'b CmdDurationConfig, config: &CmdDurationConfig,
context: &'a Context, context: &'a Context,
elapsed: u128, elapsed: u128,
) -> Module<'a> { ) -> Module<'a> {

View File

@ -26,7 +26,7 @@ pub fn module<'a>(name: Option<&str>, context: &'a Context) -> Option<Module<'a>
}; };
let mod_name = match name { let mod_name = match name {
Some(name) => format!("env_var.{}", name), Some(name) => format!("env_var.{name}"),
None => "env_var".to_owned(), None => "env_var".to_owned(),
}; };
@ -78,7 +78,7 @@ fn filter_config(config: &toml::Value) -> Option<toml::Value> {
table table
.iter() .iter()
.filter(|(_key, val)| !val.is_table()) .filter(|(_key, val)| !val.is_table())
.map(|(key, val)| (key.to_owned(), val.to_owned())) .map(|(key, val)| (key.clone(), val.clone()))
.collect::<toml::value::Table>() .collect::<toml::value::Table>()
}) })
.filter(|table| !table.is_empty()) .filter(|table| !table.is_empty())

View File

@ -426,9 +426,10 @@ fn git_status_wsl(context: &Context, conf: &GitStatusConfig) -> Option<String> {
// Get foreign starship to use WSL config // Get foreign starship to use WSL config
// https://devblogs.microsoft.com/commandline/share-environment-vars-between-wsl-and-windows/ // https://devblogs.microsoft.com/commandline/share-environment-vars-between-wsl-and-windows/
let wslenv = env::var("WSLENV") let wslenv = env::var("WSLENV").map_or_else(
.map(|e| e + ":STARSHIP_CONFIG/wp") |_| "STARSHIP_CONFIG/wp".to_string(),
.unwrap_or_else(|_| "STARSHIP_CONFIG/wp".to_string()); |e| e + ":STARSHIP_CONFIG/wp",
);
let out = match create_command(starship_exe) let out = match create_command(starship_exe)
.map(|mut c| { .map(|mut c| {

View File

@ -41,7 +41,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let topic_graphemes = if let Ok(topic) = get_hg_topic_name(repo_root) { let topic_graphemes = if let Ok(topic) = get_hg_topic_name(repo_root) {
truncate_text(&topic, len, config.truncation_symbol) truncate_text(&topic, len, config.truncation_symbol)
} else { } else {
String::from("") String::new()
}; };
let parsed = StringFormatter::new(config.format).and_then(|formatter| { let parsed = StringFormatter::new(config.format).and_then(|formatter| {

View File

@ -12,8 +12,8 @@ enum NixShellType {
} }
impl NixShellType { impl NixShellType {
fn detect_shell_type(use_heuristic: bool, context: &Context) -> Option<NixShellType> { fn detect_shell_type(use_heuristic: bool, context: &Context) -> Option<Self> {
use NixShellType::*; use NixShellType::{Impure, Pure, Unknown};
let shell_type = context.get_env("IN_NIX_SHELL"); let shell_type = context.get_env("IN_NIX_SHELL");
match shell_type.as_deref() { match shell_type.as_deref() {

View File

@ -93,13 +93,11 @@ fn get_engines_version(context: &Context) -> Option<String> {
} }
fn check_engines_version(nodejs_version: Option<&str>, engines_version: Option<String>) -> bool { fn check_engines_version(nodejs_version: Option<&str>, engines_version: Option<String>) -> bool {
let (nodejs_version, engines_version) = match (nodejs_version, engines_version) { let (Some(nodejs_version), Some(engines_version)) = (nodejs_version, engines_version) else {
(Some(nv), Some(ev)) => (nv, ev), return true;
_ => return true,
}; };
let r = match VersionReq::parse(&engines_version) { let Ok(r) = VersionReq::parse(&engines_version) else {
Ok(r) => r, return true;
Err(_e) => return true,
}; };
let re = Regex::new(r"\d+\.\d+\.\d+").unwrap(); let re = Regex::new(r"\d+\.\d+\.\d+").unwrap();
let version = re let version = re

View File

@ -80,9 +80,8 @@ fn create_offset_time_string(
); );
if utc_time_offset_in_hours < 24_f32 && utc_time_offset_in_hours > -24_f32 { if utc_time_offset_in_hours < 24_f32 && utc_time_offset_in_hours > -24_f32 {
let utc_offset_in_seconds: i32 = (utc_time_offset_in_hours * 3600_f32) as i32; let utc_offset_in_seconds: i32 = (utc_time_offset_in_hours * 3600_f32) as i32;
let timezone_offset = match FixedOffset::east_opt(utc_offset_in_seconds) { let Some(timezone_offset) = FixedOffset::east_opt(utc_offset_in_seconds) else {
Some(offset) => offset, return Err("Invalid offset")
None => return Err("Invalid offset"),
}; };
log::trace!("Target timezone offset is {}", timezone_offset); log::trace!("Target timezone offset is {}", timezone_offset);

View File

@ -334,7 +334,7 @@ fn handle_module<'a>(
for (child, config) in context for (child, config) in context
.config .config
.get_config(&[module]) .get_config(&[module])
.and_then(|config| config.as_table().map(|t| t.iter())) .and_then(|config| config.as_table().map(toml::map::Map::iter))
.into_iter() .into_iter()
.flatten() .flatten()
{ {