Skip to content

Handle properly when there is no crate attrs #107836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,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 {
Expand Down
4 changes: 4 additions & 0 deletions tests/run-make/no-input-file/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include ../../run-make-fulldeps/tools.mk

all:
$(RUSTC) --print crate-name 2>&1 | diff - no-input-file.stderr
2 changes: 2 additions & 0 deletions tests/run-make/no-input-file/no-input-file.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
error: no input filename given