diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-02-10 15:28:47 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-10 15:28:47 +0100 |
| commit | d494cd3eab38c319985e38f5fd43465391fa2bbe (patch) | |
| tree | 64ae71d86c346778201e8328c13e24677ea02a9f | |
| parent | dc7559b599d70419b079d4b97949dfe85d1c17ac (diff) | |
| parent | 257389882de113945d3f9f1abb9d0a431ca3cf92 (diff) | |
| download | rust-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.rs | 5 | ||||
| -rw-r--r-- | tests/run-make/no-input-file/Makefile | 4 | ||||
| -rw-r--r-- | tests/run-make/no-input-file/no-input-file.stderr | 2 |
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 + |
