diff --git a/cargo-miri/src/phases.rs b/cargo-miri/src/phases.rs index dba3000a80..81ff68545c 100644 --- a/cargo-miri/src/phases.rs +++ b/cargo-miri/src/phases.rs @@ -364,7 +364,7 @@ pub fn phase_rustc(mut args: impl Iterator, phase: RustcPhase) { let out_filename = out_filename.expect("rustdoc must pass `-o`"); cmd.args(&args); - cmd.env("MIRI_BE_RUSTC", "rustdoc"); + cmd.env("MIRI_BE_RUSTC", "target"); if verbose > 0 { eprintln!( diff --git a/src/bin/miri.rs b/src/bin/miri.rs index 581e129c9e..8028803dde 100644 --- a/src/bin/miri.rs +++ b/src/bin/miri.rs @@ -123,31 +123,14 @@ impl rustc_driver::Callbacks for MiriCompilerCalls { } } -#[derive(Copy, Clone, Debug, PartialEq)] -enum MiriBeRustcMode { - Target, - Host, - Rustdoc, -} - -impl MiriBeRustcMode { - fn target_crate(self) -> bool { - use MiriBeRustcMode::*; - match self { - Target | Rustdoc => true, - Host => false, - } - } -} - struct MiriBeRustCompilerCalls { - mode: MiriBeRustcMode, + target_crate: bool, } impl rustc_driver::Callbacks for MiriBeRustCompilerCalls { #[allow(rustc::potential_query_instability)] // rustc_codegen_ssa (where this code is copied from) also allows this lint fn config(&mut self, config: &mut Config) { - if config.opts.prints.is_empty() && self.mode == MiriBeRustcMode::Target { + if config.opts.prints.is_empty() && self.target_crate { // Queries overridden here affect the data stored in `rmeta` files of dependencies, // which will be used later in non-`MIRI_BE_RUSTC` mode. config.override_queries = Some(|_, local_providers| { @@ -203,11 +186,9 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls { queries: &'tcx rustc_interface::Queries<'tcx>, ) -> Compilation { queries.global_ctxt().unwrap().enter(|tcx| { - // Make sure compile_fail tests with post-monomorphization const-eval errors work as - // intended in rustdoc mode. - if self.mode == MiriBeRustcMode::Rustdoc { - let _ = tcx.collect_and_partition_mono_items(()); - } + // We are emulating regular rustc builds, which would perform post-mono const-eval. + // So let's also do that here, even if we might be running with `--emit=metadata`. + let _ = tcx.collect_and_partition_mono_items(()); }); Compilation::Continue } @@ -383,18 +364,19 @@ fn main() { rustc_driver::install_ice_hook(rustc_driver::DEFAULT_BUG_REPORT_URL, |_| ()); rustc_driver::init_rustc_env_logger(&early_dcx); - let mode = match crate_kind.to_str().unwrap_or_default() { - "target" => MiriBeRustcMode::Target, - "rustdoc" => MiriBeRustcMode::Rustdoc, - "host" => MiriBeRustcMode::Host, - _ => panic!("invalid `MIRI_BE_RUSTC` value: {crate_kind:?}"), + let target_crate = if crate_kind == "target" { + true + } else if crate_kind == "host" { + false + } else { + panic!("invalid `MIRI_BE_RUSTC` value: {crate_kind:?}") }; // We cannot use `rustc_driver::main` as we need to adjust the CLI arguments. run_compiler( args, - mode.target_crate(), - &mut MiriBeRustCompilerCalls { mode }, + target_crate, + &mut MiriBeRustCompilerCalls { target_crate }, using_internal_features, ) }