about summary refs log tree commit diff
path: root/compiler/rustc_driver_impl
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2023-11-17 11:04:38 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2023-11-18 07:38:05 +1100
commit8aee35e2ed51a9f782c1bff3f8a165b5a85f0c43 (patch)
treece1e8a9f800780e6b93334b0917c516f24fa2c0e /compiler/rustc_driver_impl
parent706eb1604b45e922858e04cf6abee7e58aa92730 (diff)
downloadrust-8aee35e2ed51a9f782c1bff3f8a165b5a85f0c43.tar.gz
rust-8aee35e2ed51a9f782c1bff3f8a165b5a85f0c43.zip
Merge `interface::run_compiler` calls.
`rustc_driver_impl::run_compiler` currently has two
`interface::run_compiler` calls: one for the "no input" case, and one
for the normal case.

This commit merges the former into the latter, which makes the control
flow easier to read and avoids some duplication.

It also makes it clearer that the "no input" case will describe lints
before printing crate info, while the normal case does it in the reverse
order. Possibly a bug?
Diffstat (limited to 'compiler/rustc_driver_impl')
-rw-r--r--compiler/rustc_driver_impl/src/lib.rs48
1 files changed, 18 insertions, 30 deletions
diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs
index c24d74d1b9b..f74eb028364 100644
--- a/compiler/rustc_driver_impl/src/lib.rs
+++ b/compiler/rustc_driver_impl/src/lib.rs
@@ -338,41 +338,14 @@ fn run_compiler(
         expanded_args: args,
     };
 
-    match make_input(&default_handler, &matches.free) {
+    let has_input = match make_input(&default_handler, &matches.free) {
         Err(reported) => return Err(reported),
         Ok(Some(input)) => {
             config.input = input;
-
-            callbacks.config(&mut config);
+            true // has input: normal compilation
         }
         Ok(None) => match matches.free.len() {
-            0 => {
-                callbacks.config(&mut config);
-
-                default_handler.abort_if_errors();
-
-                interface::run_compiler(config, |compiler| {
-                    let sopts = &compiler.session().opts;
-                    let handler = EarlyErrorHandler::new(sopts.error_format);
-
-                    if sopts.describe_lints {
-                        describe_lints(compiler.session());
-                        return;
-                    }
-                    let should_stop = print_crate_info(
-                        &handler,
-                        compiler.codegen_backend(),
-                        compiler.session(),
-                        false,
-                    );
-
-                    if should_stop == Compilation::Stop {
-                        return;
-                    }
-                    handler.early_error("no input filename given")
-                });
-                return Ok(());
-            }
+            0 => false, // no input: we will exit early
             1 => panic!("make_input should have provided valid inputs"),
             _ => default_handler.early_error(format!(
                 "multiple input filenames provided (first two filenames are `{}` and `{}`)",
@@ -381,13 +354,28 @@ fn run_compiler(
         },
     };
 
+    callbacks.config(&mut config);
+
     default_handler.abort_if_errors();
+    drop(default_handler);
 
     interface::run_compiler(config, |compiler| {
         let sess = compiler.session();
         let codegen_backend = compiler.codegen_backend();
         let handler = EarlyErrorHandler::new(sess.opts.error_format);
 
+        if !has_input {
+            if sess.opts.describe_lints {
+                describe_lints(sess);
+                return sess.compile_status();
+            }
+            let should_stop = print_crate_info(&handler, codegen_backend, sess, false);
+            if should_stop == Compilation::Continue {
+                handler.early_error("no input filename given")
+            }
+            return sess.compile_status();
+        }
+
         let should_stop = print_crate_info(&handler, codegen_backend, sess, true)
             .and_then(|| list_metadata(&handler, sess, &*codegen_backend.metadata_loader()))
             .and_then(|| try_process_rlink(sess, compiler));