Skip to content

Commit

Permalink
Don't ICE if getting the input's file_stem fails
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDenton committed Aug 5, 2024
1 parent c8d50ef commit c6d9482
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c6d9482

Please sign in to comment.