Don't ICE if getting the input's file_stem fails

This commit is contained in:
Chris Denton 2024-08-05 22:30:13 +00:00
parent c8d50ef2ee
commit c6d94821f0
No known key found for this signature in database
GPG Key ID: 713472F2F45627DE

View File

@ -838,10 +838,14 @@ pub enum Input {
impl Input {
pub fn filestem(&self) -> &str {
match *self {
Input::File(ref ifile) => ifile.file_stem().unwrap().to_str().unwrap(),
Input::Str { .. } => "rust_out",
if let Input::File(ifile) = self {
// If for some reason getting the file stem as a UTF-8 string fails,
// then fallback to a fixed name.
if let Some(name) = ifile.file_stem().and_then(OsStr::to_str) {
return name;
}
}
"rust_out"
}
pub fn source_name(&self) -> FileName {