Fix clippy (#15489)

# Description
There are some clippy(version 0.1.86) errors on nushell repo. This pr is
trying to fix it.

# User-Facing Changes
Hopefully none.

# Tests + Formatting
NaN

# After Submitting
NaN
This commit is contained in:
Wind
2025-04-06 09:49:28 +08:00
committed by GitHub
parent 67ea25afca
commit 1c6c85d35d
19 changed files with 30 additions and 35 deletions

View File

@ -46,7 +46,7 @@ pub fn expand_ndots(path: impl AsRef<Path>) -> PathBuf {
pub fn expand_dots(path: impl AsRef<Path>) -> PathBuf {
// Check if the last component of the path is a normal component.
fn last_component_is_normal(path: &Path) -> bool {
matches!(path.components().last(), Some(Component::Normal(_)))
matches!(path.components().next_back(), Some(Component::Normal(_)))
}
let path = path.as_ref();
@ -61,7 +61,7 @@ pub fn expand_dots(path: impl AsRef<Path>) -> PathBuf {
// no-op
}
_ => {
let prev_component = result.components().last();
let prev_component = result.components().next_back();
if prev_component == Some(Component::RootDir) && component == Component::ParentDir {
continue;
}

View File

@ -29,7 +29,7 @@ fn expand_tilde_with_home(path: impl AsRef<Path>, home: Option<PathBuf>) -> Path
};
}
let path_last_char = path.as_os_str().to_string_lossy().chars().last();
let path_last_char = path.as_os_str().to_string_lossy().chars().next_back();
let need_trailing_slash = path_last_char == Some('/') || path_last_char == Some('\\');
match home {
@ -94,7 +94,7 @@ fn user_home_dir(username: &str) -> PathBuf {
if !cfg!(target_os = "android")
&& expected_path
.components()
.last()
.next_back()
.map(|last| last != Component::Normal(username.as_ref()))
.unwrap_or(false)
{