@@ -225,14 +225,16 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
225225 }
226226}
227227
228- struct MiriBeRustCompilerCalls {
229- target_crate : bool ,
230- }
228+ struct MiriBeRustCompilerCalls ;
231229
232230impl rustc_driver:: Callbacks for MiriBeRustCompilerCalls {
233231 #[ allow( rustc:: potential_query_instability) ] // rustc_codegen_ssa (where this code is copied from) also allows this lint
234232 fn config ( & mut self , config : & mut Config ) {
235- if config. opts . prints . is_empty ( ) && self . target_crate {
233+ if config. opts . prints . is_empty ( ) {
234+ // Avoid warnings about unsupported crate types
235+ #[ allow( rustc:: bad_opt_access) ]
236+ config. opts . crate_types . retain ( |& c| c == CrateType :: Executable || c == CrateType :: Rlib ) ;
237+
236238 // Queries overridden here affect the data stored in `rmeta` files of dependencies,
237239 // which will be used later in non-`MIRI_BE_RUSTC` mode.
238240 config. override_queries = Some ( |_, local_providers| {
@@ -299,16 +301,15 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
299301 _: & rustc_interface:: interface:: Compiler ,
300302 tcx : TyCtxt < ' tcx > ,
301303 ) -> Compilation {
302- if self . target_crate {
303- // cargo-miri has patched the compiler flags to make these into check-only builds,
304- // but we are still emulating regular rustc builds, which would perform post-mono
305- // const-eval during collection. So let's also do that here, even if we might be
306- // running with `--emit=metadata`. In particular this is needed to make
307- // `compile_fail` doc tests trigger post-mono errors.
308- // In general `collect_and_partition_mono_items` is not safe to call in check-only
309- // builds, but we are setting `-Zalways-encode-mir` which avoids those issues.
310- let _ = tcx. collect_and_partition_mono_items ( ( ) ) ;
311- }
304+ // cargo-miri has patched the compiler flags to make these into check-only builds,
305+ // but we are still emulating regular rustc builds, which would perform post-mono
306+ // const-eval during collection. So let's also do that here, even if we might be
307+ // running with `--emit=metadata`. In particular this is needed to make
308+ // `compile_fail` doc tests trigger post-mono errors.
309+ // In general `collect_and_partition_mono_items` is not safe to call in check-only
310+ // builds, but we are setting `-Zalways-encode-mir` which avoids those issues.
311+ let _ = tcx. collect_and_partition_mono_items ( ( ) ) ;
312+
312313 Compilation :: Continue
313314 }
314315}
@@ -430,32 +431,25 @@ fn main() {
430431
431432 // If the environment asks us to actually be rustc, then do that.
432433 if let Some ( crate_kind) = env:: var_os ( "MIRI_BE_RUSTC" ) {
433- // Earliest rustc setup.
434- rustc_driver:: install_ice_hook ( rustc_driver:: DEFAULT_BUG_REPORT_URL , |_| ( ) ) ;
435- rustc_driver:: init_rustc_env_logger ( & early_dcx) ;
436-
437- let target_crate = if crate_kind == "target" {
438- true
439- } else if crate_kind == "host" {
440- false
434+ if crate_kind == "host" {
435+ rustc_driver:: main ( ) ;
436+ } else if crate_kind == "target" {
441437 } else {
442438 panic ! ( "invalid `MIRI_BE_RUSTC` value: {crate_kind:?}" )
443439 } ;
444440
441+ // Earliest rustc setup.
442+ rustc_driver:: install_ice_hook ( rustc_driver:: DEFAULT_BUG_REPORT_URL , |_| ( ) ) ;
443+ rustc_driver:: init_rustc_env_logger ( & early_dcx) ;
444+
445445 let mut args = args;
446- // Don't insert `MIRI_DEFAULT_ARGS`, in particular, `--cfg=miri`, if we are building
447- // a "host" crate. That may cause procedural macros (and probably build scripts) to
448- // depend on Miri-only symbols, such as `miri_resolve_frame`:
449- // https://github.com/rust-lang/miri/issues/1760
450- if target_crate {
451- // Splice in the default arguments after the program name.
452- // Some options have different defaults in Miri than in plain rustc; apply those by making
453- // them the first arguments after the binary name (but later arguments can overwrite them).
454- args. splice ( 1 ..1 , miri:: MIRI_DEFAULT_ARGS . iter ( ) . map ( ToString :: to_string) ) ;
455- }
446+ // Splice in the default arguments after the program name.
447+ // Some options have different defaults in Miri than in plain rustc; apply those by making
448+ // them the first arguments after the binary name (but later arguments can overwrite them).
449+ args. splice ( 1 ..1 , miri:: MIRI_DEFAULT_ARGS . iter ( ) . map ( ToString :: to_string) ) ;
456450
457451 // We cannot use `rustc_driver::main` as we want it to use `args` as the CLI arguments.
458- run_compiler_and_exit ( & args, & mut MiriBeRustCompilerCalls { target_crate } )
452+ run_compiler_and_exit ( & args, & mut MiriBeRustCompilerCalls )
459453 }
460454
461455 // Add an ICE bug report hook.
0 commit comments