From e64a7ebcb0c8633d30bc553023a6e7ed830b2709 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 18 Apr 2020 21:13:09 +0200 Subject: [PATCH] Implement check mode Fixes #973 --- src/driver/aot.rs | 12 +++++++++++- src/driver/jit.rs | 4 ++++ src/lib.rs | 1 - 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 591e1580337..b74608974b7 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -146,7 +146,13 @@ pub(super) fn run_aot( ) -> Box<(CodegenResults, FxHashMap)> { let mut work_products = FxHashMap::default(); - let (_, cgus) = tcx.collect_and_partition_mono_items(LOCAL_CRATE); + let cgus = if tcx.sess.opts.output_types.should_codegen() { + tcx.collect_and_partition_mono_items(LOCAL_CRATE).1 + } else { + // If only `--emit metadata` is used, we shouldn't perform any codegen. + // Also `tcx.collect_and_partition_mono_items` may panic in that case. + &[] + }; if tcx.dep_graph.is_fully_enabled() { for cgu in &*cgus { @@ -239,6 +245,10 @@ pub(super) fn run_aot( None }; + if tcx.sess.opts.output_types.should_codegen() { + rustc_incremental::assert_module_sources::assert_module_sources(tcx); + } + Box::new((CodegenResults { crate_name: tcx.crate_name(LOCAL_CRATE), modules, diff --git a/src/driver/jit.rs b/src/driver/jit.rs index bf388a2769a..a5dca71c330 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -39,6 +39,10 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>) -> ! { .declare_function("main", Linkage::Import, &sig) .unwrap(); + if !tcx.sess.opts.output_types.should_codegen() { + tcx.sess.fatal("JIT mode doesn't work with `cargo check`."); + } + let (_, cgus) = tcx.collect_and_partition_mono_items(LOCAL_CRATE); let mono_items = cgus .iter() diff --git a/src/lib.rs b/src/lib.rs index e7a637211d4..d679b4d7930 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -200,7 +200,6 @@ impl CodegenBackend for CraneliftCodegenBackend { ) -> Box { let res = driver::codegen_crate(tcx, metadata, need_metadata_module); - rustc_incremental::assert_module_sources::assert_module_sources(tcx); rustc_symbol_mangling::test::report_symbol_names(tcx); res