diff options
| author | Chris Denton <chris@chrisdenton.dev> | 2024-08-05 22:30:13 +0000 |
|---|---|---|
| committer | Chris Denton <chris@chrisdenton.dev> | 2024-08-05 22:30:13 +0000 |
| commit | c6d94821f06320108b9fd35219a13c5ec4094ed4 (patch) | |
| tree | e16dc742abf6784ddecaf1d0665f9d71580177b4 | |
| parent | c8d50ef2ee71b6b586e52f0834657a7fd4b42800 (diff) | |
| download | rust-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.rs | 10 |
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 { |
