chore: Minor changes to use more idiomatic Rust (integer max values; complicates nested expressions) (#6090)

* chore: use current way to get max value of an integer type

The std::usize::MAX way has been obsolete for quite some time now.
Found by clippy (clippy::legacy_numeric_constants).

Signed-off-by: Lars Wirzenius <liw@liw.fi>

* chore: use helper variable for a more idiomatic pattern matching

A nested expression can be harder to understand than two simpler
expressions. (Found by clippy lint clippy::blocks_in_conditions.)

Signed-off-by: Lars Wirzenius <liw@liw.fi>

---------

Signed-off-by: Lars Wirzenius <liw@liw.fi>
Co-authored-by: Lars Wirzenius <liw@liw.fi>
This commit is contained in:
larswirzenius 2024-07-24 22:06:40 +03:00 committed by GitHub
parent 1c3bae29d3
commit 6000231d12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 15 additions and 14 deletions

View File

@ -22,7 +22,7 @@ impl<'a> Default for FossilBranchConfig<'a> {
format: "on [$symbol$branch]($style) ", format: "on [$symbol$branch]($style) ",
symbol: "", symbol: "",
style: "bold purple", style: "bold purple",
truncation_length: std::i64::MAX, truncation_length: i64::MAX,
truncation_symbol: "", truncation_symbol: "",
disabled: true, disabled: true,
} }

View File

@ -25,7 +25,7 @@ impl<'a> Default for GitBranchConfig<'a> {
format: "on [$symbol$branch(:$remote_branch)]($style) ", format: "on [$symbol$branch(:$remote_branch)]($style) ",
symbol: "", symbol: "",
style: "bold purple", style: "bold purple",
truncation_length: std::i64::MAX, truncation_length: i64::MAX,
truncation_symbol: "", truncation_symbol: "",
only_attached: false, only_attached: false,
always_show_remote: false, always_show_remote: false,

View File

@ -22,7 +22,7 @@ impl<'a> Default for HgBranchConfig<'a> {
symbol: "", symbol: "",
style: "bold purple", style: "bold purple",
format: "on [$symbol$branch(:$topic)]($style) ", format: "on [$symbol$branch(:$topic)]($style) ",
truncation_length: std::i64::MAX, truncation_length: i64::MAX,
truncation_symbol: "", truncation_symbol: "",
disabled: true, disabled: true,
} }

View File

@ -19,7 +19,7 @@ pub struct MesonConfig<'a> {
impl<'a> Default for MesonConfig<'a> { impl<'a> Default for MesonConfig<'a> {
fn default() -> Self { fn default() -> Self {
MesonConfig { MesonConfig {
truncation_length: std::u32::MAX, truncation_length: u32::MAX,
truncation_symbol: "", truncation_symbol: "",
format: "via [$symbol$project]($style) ", format: "via [$symbol$project]($style) ",
symbol: "", symbol: "",

View File

@ -22,7 +22,7 @@ impl<'a> Default for PijulConfig<'a> {
symbol: "", symbol: "",
style: "bold purple", style: "bold purple",
format: "on [$symbol$channel]($style) ", format: "on [$symbol$channel]($style) ",
truncation_length: std::i64::MAX, truncation_length: i64::MAX,
truncation_symbol: "", truncation_symbol: "",
disabled: true, disabled: true,
} }

View File

@ -33,7 +33,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
"\"truncation_length\" should be a positive value, found {}", "\"truncation_length\" should be a positive value, found {}",
config.truncation_length config.truncation_length
); );
std::usize::MAX usize::MAX
} else { } else {
config.truncation_length as usize config.truncation_length as usize
}; };

View File

@ -19,7 +19,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
"\"truncation_length\" should be a positive value, found {}", "\"truncation_length\" should be a positive value, found {}",
config.truncation_length config.truncation_length
); );
std::usize::MAX usize::MAX
} else { } else {
config.truncation_length as usize config.truncation_length as usize
}; };

View File

@ -426,13 +426,13 @@ fn git_status_wsl(context: &Context, conf: &GitStatusConfig) -> Option<String> {
log::trace!("Using WSL mode"); log::trace!("Using WSL mode");
// Get Windows path // Get Windows path
let winpath = match create_command("wslpath") let wslpath = create_command("wslpath")
.map(|mut c| { .map(|mut c| {
c.arg("-w").arg(&context.current_dir); c.arg("-w").arg(&context.current_dir);
c c
}) })
.and_then(|mut c| c.output()) .and_then(|mut c| c.output());
{ let winpath = match wslpath {
Ok(r) => r, Ok(r) => r,
Err(e) => { Err(e) => {
// Not found might means this might not be WSL after all // Not found might means this might not be WSL after all
@ -472,7 +472,7 @@ fn git_status_wsl(context: &Context, conf: &GitStatusConfig) -> Option<String> {
|e| e + ":STARSHIP_CONFIG/wp", |e| e + ":STARSHIP_CONFIG/wp",
); );
let out = match create_command(starship_exe) let exe = create_command(starship_exe)
.map(|mut c| { .map(|mut c| {
c.env( c.env(
"STARSHIP_CONFIG", "STARSHIP_CONFIG",
@ -484,8 +484,9 @@ fn git_status_wsl(context: &Context, conf: &GitStatusConfig) -> Option<String> {
.args(["module", "git_status", "--path", winpath]); .args(["module", "git_status", "--path", winpath]);
c c
}) })
.and_then(|mut c| c.output()) .and_then(|mut c| c.output());
{
let out = match exe {
Ok(r) => r, Ok(r) => r,
Err(e) => { Err(e) => {
log::error!("Failed to run Git Status module on Windows:\n{}", e); log::error!("Failed to run Git Status module on Windows:\n{}", e);

View File

@ -26,7 +26,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
"\"truncation_length\" should be a positive value, found {}", "\"truncation_length\" should be a positive value, found {}",
config.truncation_length config.truncation_length
); );
std::usize::MAX usize::MAX
} else { } else {
config.truncation_length as usize config.truncation_length as usize
}; };