Skip to content

Commit db95a01

Browse files
authored
Rollup merge of #128710 - ChrisDenton:null, r=jieyouxu
Don't ICE when getting an input file name's stem fails Fixes #128681 The file stem is only used as a user-friendly prefix on intermediary files. While nice to have, it's not the end of the world if it fails so there's no real reason to emit an error here. We can continue with a fixed name as we do when an anonymous string is used.
2 parents 29b25e0 + 3fd645e commit db95a01

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

compiler/rustc_session/src/config.rs

+7-3
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 {
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ only-windows
2+
// Reason: dos devices are a Windows thing
3+
4+
use std::path::Path;
5+
6+
use run_make_support::{rustc, static_lib_name};
7+
8+
fn main() {
9+
rustc().input(r"\\.\NUL").crate_type("staticlib").run();
10+
rustc().input(r"\\?\NUL").crate_type("staticlib").run();
11+
12+
assert!(Path::new(&static_lib_name("rust_out")).exists());
13+
}

0 commit comments

Comments
 (0)