about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChris Denton <chris@chrisdenton.dev>2024-08-05 22:30:13 +0000
committerChris Denton <chris@chrisdenton.dev>2024-08-05 22:30:13 +0000
commitc6d94821f06320108b9fd35219a13c5ec4094ed4 (patch)
treee16dc742abf6784ddecaf1d0665f9d71580177b4
parentc8d50ef2ee71b6b586e52f0834657a7fd4b42800 (diff)
downloadrust-c6d94821f06320108b9fd35219a13c5ec4094ed4.tar.gz
rust-c6d94821f06320108b9fd35219a13c5ec4094ed4.zip
Don't ICE if getting the input's file_stem fails
-rw-r--r--compiler/rustc_session/src/config.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs
index f58a991a616..a60af3f2d71 100644
--- a/compiler/rustc_session/src/config.rs
+++ b/compiler/rustc_session/src/config.rs
@@ -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 {