Non-panicking Display for Path

This commit is contained in:
Mattias Wallin 2024-09-15 12:07:07 +02:00 committed by Yacin Tmimi
parent d6d9e76240
commit 5230e8fbe6
3 changed files with 7 additions and 11 deletions

View File

@ -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

View File

@ -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>"),
}
}

View File

@ -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 {
@ -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") {