Skip to content

Commit

Permalink
Remove unnecessary unwrap (#2599)
Browse files Browse the repository at this point in the history
`strip_prefix` will itself check whether the string starts with the
prefix, so the extra call to `starts_with` was unnecessary.
  • Loading branch information
Hugo authored May 29, 2022
1 parent 10415a8 commit 89c6e8a
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions helix-core/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use std::path::{Component, Path, PathBuf};
/// is available, otherwise returns the path unchanged.
pub fn fold_home_dir(path: &Path) -> PathBuf {
if let Ok(home) = home_dir() {
if path.starts_with(&home) {
// it's ok to unwrap, the path starts with home dir
return PathBuf::from("~").join(path.strip_prefix(&home).unwrap());
if let Ok(stripped) = path.strip_prefix(&home) {
return PathBuf::from("~").join(stripped);
}
}

Expand Down

0 comments on commit 89c6e8a

Please sign in to comment.