From c8d50ef2ee71b6b586e52f0834657a7fd4b42800 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Mon, 5 Aug 2024 22:13:12 +0000 Subject: [PATCH 1/3] Windows: Test if `\\.\NUL` works as an input file --- tests/run-make/dos-device-input/rmake.rs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tests/run-make/dos-device-input/rmake.rs diff --git a/tests/run-make/dos-device-input/rmake.rs b/tests/run-make/dos-device-input/rmake.rs new file mode 100644 index 0000000000000..cc34dd551071d --- /dev/null +++ b/tests/run-make/dos-device-input/rmake.rs @@ -0,0 +1,9 @@ +//@ only-windows +// Reason: dos devices are a Windows thing + +use run_make_support::rustc; + +fn main() { + rustc().input(r"\\.\NUL").crate_type("staticlib").run(); + rustc().input(r"\\?\NUL").crate_type("staticlib").run(); +} From c6d94821f06320108b9fd35219a13c5ec4094ed4 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Mon, 5 Aug 2024 22:30:13 +0000 Subject: [PATCH 2/3] Don't ICE if getting the input's file_stem fails --- compiler/rustc_session/src/config.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index f58a991a616da..a60af3f2d7137 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 { From 3fd645e254564b0f71027f42b940625670bc35ff Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Mon, 5 Aug 2024 23:50:15 +0000 Subject: [PATCH 3/3] Check staticlib name falls back to `rust_out` --- tests/run-make/dos-device-input/rmake.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/run-make/dos-device-input/rmake.rs b/tests/run-make/dos-device-input/rmake.rs index cc34dd551071d..dee3b86f09591 100644 --- a/tests/run-make/dos-device-input/rmake.rs +++ b/tests/run-make/dos-device-input/rmake.rs @@ -1,9 +1,13 @@ //@ only-windows // Reason: dos devices are a Windows thing -use run_make_support::rustc; +use std::path::Path; + +use run_make_support::{rustc, static_lib_name}; fn main() { rustc().input(r"\\.\NUL").crate_type("staticlib").run(); rustc().input(r"\\?\NUL").crate_type("staticlib").run(); + + assert!(Path::new(&static_lib_name("rust_out")).exists()); }