Skip to content

Commit

Permalink
Non-panicking Display for Path
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattias Wallin authored and Rawk committed Sep 16, 2024
1 parent d6d9e76 commit 14f3d2c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,10 @@ fn format(

for file in files {
if !file.exists() {
eprintln!("Error: file `{}` does not exist", file.to_str().unwrap());
eprintln!("Error: file `{}` does not exist", file.display());
session.add_operational_error();
} else if file.is_dir() {
eprintln!("Error: `{}` is a directory", file.to_str().unwrap());
eprintln!("Error: `{}` is a directory", file.display());
session.add_operational_error();
} else {
// Check the file directory if the config-path could not be read or not provided
Expand Down
2 changes: 1 addition & 1 deletion src/config/file_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl From<rustc_span::FileName> for FileName {
impl fmt::Display for FileName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
FileName::Real(p) => write!(f, "{}", p.to_str().unwrap()),
FileName::Real(p) => write!(f, "{}", p.display()),
FileName::Stdin => write!(f, "<stdin>"),
}
}
Expand Down
12 changes: 4 additions & 8 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ fn is_file_skip(path: &Path) -> bool {
fn get_test_files(path: &Path, recursive: bool) -> Vec<PathBuf> {
let mut files = vec![];
if path.is_dir() {
for entry in fs::read_dir(path).expect(&format!(
"couldn't read directory {}",
path.to_str().unwrap()
)) {
for entry in
fs::read_dir(path).expect(&format!("couldn't read directory {}", path.display()))
{
let entry = entry.expect("couldn't get `DirEntry`");
let path = entry.path();
if path.is_dir() && recursive {
Expand All @@ -122,10 +121,7 @@ fn get_test_files(path: &Path, recursive: bool) -> Vec<PathBuf> {
}

fn verify_config_used(path: &Path, config_name: &str) {
for entry in fs::read_dir(path).expect(&format!(
"couldn't read {} directory",
path.to_str().unwrap()
)) {
for entry in fs::read_dir(path).expect(&format!("couldn't read {} directory", path.display())) {
let entry = entry.expect("couldn't get directory entry");
let path = entry.path();
if path.extension().map_or(false, |f| f == "rs") {
Expand Down

0 comments on commit 14f3d2c

Please sign in to comment.