about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-02-10 15:28:47 +0100
committerGitHub <noreply@github.com>2023-02-10 15:28:47 +0100
commitd494cd3eab38c319985e38f5fd43465391fa2bbe (patch)
tree64ae71d86c346778201e8328c13e24677ea02a9f
parentdc7559b599d70419b079d4b97949dfe85d1c17ac (diff)
parent257389882de113945d3f9f1abb9d0a431ca3cf92 (diff)
downloadrust-d494cd3eab38c319985e38f5fd43465391fa2bbe.tar.gz
rust-d494cd3eab38c319985e38f5fd43465391fa2bbe.zip
Rollup merge of #107836 - chenyukang:yukang/fix-107822, r=oli-obk
Handle properly when there is no crate attrs

Fixes #107822

r? `@oli-obk`
-rw-r--r--compiler/rustc_driver_impl/src/lib.rs5
-rw-r--r--tests/run-make/no-input-file/Makefile4
-rw-r--r--tests/run-make/no-input-file/no-input-file.stderr2
3 files changed, 10 insertions, 1 deletions
diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs
index bdf2978cee2..37967bfdff5 100644
--- a/compiler/rustc_driver_impl/src/lib.rs
+++ b/compiler/rustc_driver_impl/src/lib.rs
@@ -624,7 +624,10 @@ fn print_crate_info(
                 println!("{}", serde_json::to_string_pretty(&sess.target.to_json()).unwrap());
             }
             FileNames | CrateName => {
-                let attrs = attrs.as_ref().unwrap();
+                let Some(attrs) = attrs.as_ref() else {
+                    // no crate attributes, print out an error and exit
+                    return Compilation::Continue;
+                };
                 let t_outputs = rustc_interface::util::build_output_filenames(attrs, sess);
                 let id = rustc_session::output::find_crate_name(sess, attrs);
                 if *req == PrintRequest::CrateName {
diff --git a/tests/run-make/no-input-file/Makefile b/tests/run-make/no-input-file/Makefile
new file mode 100644
index 00000000000..2f02159229d
--- /dev/null
+++ b/tests/run-make/no-input-file/Makefile
@@ -0,0 +1,4 @@
+include ../../run-make-fulldeps/tools.mk
+
+all:
+	$(RUSTC) --print crate-name 2>&1 | diff - no-input-file.stderr
diff --git a/tests/run-make/no-input-file/no-input-file.stderr b/tests/run-make/no-input-file/no-input-file.stderr
new file mode 100644
index 00000000000..b843eb524f3
--- /dev/null
+++ b/tests/run-make/no-input-file/no-input-file.stderr
@@ -0,0 +1,2 @@
+error: no input filename given
+