Skip to content

Commit c6d9482

Browse files
committed
Don't ICE if getting the input's file_stem fails
1 parent c8d50ef commit c6d9482

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -838,10 +838,14 @@ pub enum Input {
838838

839839
impl Input {
840840
pub fn filestem(&self) -> &str {
841-
match *self {
842-
Input::File(ref ifile) => ifile.file_stem().unwrap().to_str().unwrap(),
843-
Input::Str { .. } => "rust_out",
841+
if let Input::File(ifile) = self {
842+
// If for some reason getting the file stem as a UTF-8 string fails,
843+
// then fallback to a fixed name.
844+
if let Some(name) = ifile.file_stem().and_then(OsStr::to_str) {
845+
return name;
846+
}
844847
}
848+
"rust_out"
845849
}
846850

847851
pub fn source_name(&self) -> FileName {

0 commit comments

Comments
 (0)