1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-05-28 14:10:53 +00:00

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 {
// Extract all the requested sections into a new configuration.
let mut subset = toml::value::Table::new();
let config = if let Some(config) = config.as_table_mut() {
config
} else {
let Some(config) = config.as_table_mut() else {
// This function doesn't make any sense if the root is not a table.
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.
let value = if let Some(value) = source_cursor.remove(end) {
value
} else {
let Some(value) = source_cursor.remove(end) else {
// We didn't find a value for this path, so move on to the next path.
continue 'paths;
};

View File

@ -250,9 +250,9 @@ impl<'a> Context<'a> {
}
/// 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
.get_or_try_init(|| -> Result<Repo, git::discover::Error> {
.get_or_try_init(|| -> Result<Repo, Box<git::discover::Error>> {
// custom open options
let mut git_open_opts_map =
git_sec::trust::Mapping::<git::open::Options>::default();
@ -286,7 +286,7 @@ impl<'a> Context<'a> {
Ok(repo) => repo,
Err(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.
pub fn cleanup_log_files<P: AsRef<Path>>(path: P) {
let log_dir = path.as_ref();
let log_files = match fs::read_dir(log_dir) {
Ok(log_files) => log_files,
let Ok(log_files) = fs::read_dir(log_dir) else {
// Avoid noisily handling errors in this cleanup function.
Err(_) => return,
return
};
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"))]
fn undistract_me<'a, 'b>(
fn undistract_me<'a>(
module: Module<'a>,
_config: &'b CmdDurationConfig,
_config: &CmdDurationConfig,
_context: &'a Context,
_elapsed: u128,
) -> Module<'a> {
@ -62,9 +62,9 @@ fn undistract_me<'a, 'b>(
}
#[cfg(feature = "notify")]
fn undistract_me<'a, 'b>(
fn undistract_me<'a>(
module: Module<'a>,
config: &'b CmdDurationConfig,
config: &CmdDurationConfig,
context: &'a Context,
elapsed: u128,
) -> 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 {
Some(name) => format!("env_var.{}", name),
Some(name) => format!("env_var.{name}"),
None => "env_var".to_owned(),
};
@ -78,7 +78,7 @@ fn filter_config(config: &toml::Value) -> Option<toml::Value> {
table
.iter()
.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>()
})
.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
// https://devblogs.microsoft.com/commandline/share-environment-vars-between-wsl-and-windows/
let wslenv = env::var("WSLENV")
.map(|e| e + ":STARSHIP_CONFIG/wp")
.unwrap_or_else(|_| "STARSHIP_CONFIG/wp".to_string());
let wslenv = env::var("WSLENV").map_or_else(
|_| "STARSHIP_CONFIG/wp".to_string(),
|e| e + ":STARSHIP_CONFIG/wp",
);
let out = match create_command(starship_exe)
.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) {
truncate_text(&topic, len, config.truncation_symbol)
} else {
String::from("")
String::new()
};
let parsed = StringFormatter::new(config.format).and_then(|formatter| {

View File

@ -12,8 +12,8 @@ enum NixShellType {
}
impl NixShellType {
fn detect_shell_type(use_heuristic: bool, context: &Context) -> Option<NixShellType> {
use NixShellType::*;
fn detect_shell_type(use_heuristic: bool, context: &Context) -> Option<Self> {
use NixShellType::{Impure, Pure, Unknown};
let shell_type = context.get_env("IN_NIX_SHELL");
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 {
let (nodejs_version, engines_version) = match (nodejs_version, engines_version) {
(Some(nv), Some(ev)) => (nv, ev),
_ => return true,
let (Some(nodejs_version), Some(engines_version)) = (nodejs_version, engines_version) else {
return true;
};
let r = match VersionReq::parse(&engines_version) {
Ok(r) => r,
Err(_e) => return true,
let Ok(r) = VersionReq::parse(&engines_version) else {
return true;
};
let re = Regex::new(r"\d+\.\d+\.\d+").unwrap();
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 {
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) {
Some(offset) => offset,
None => return Err("Invalid offset"),
let Some(timezone_offset) = FixedOffset::east_opt(utc_offset_in_seconds) else {
return Err("Invalid offset")
};
log::trace!("Target timezone offset is {}", timezone_offset);

View File

@ -334,7 +334,7 @@ fn handle_module<'a>(
for (child, config) in context
.config
.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()
.flatten()
{