Repository: rust-lang/rust
File: src/bootstrap/src/core/build_steps/test.rs (Rust)

Code before:
            eprintln!("cargo-miri cannot be tested at stage 0");
            std::process::exit(1);
        }

        // This compiler runs on the host, we'll just use it for the target.
        let build_compiler = builder.compiler(stage, host);

        // Run `cargo miri test`.
        // This is just a smoke test (Miri's own CI invokes this in a bunch of different ways and ensures
        // that we get the desired output), but that is sufficient to make sure that the libtest harness
        // itself executes properly under Miri, and that all the logic in `cargo-miri` does not explode.
        let mut cargo = tool::prepare_tool_cargo(
            builder,
            build_compiler,
            Mode::ToolStd, // it's unclear what to use here, we're not building anything just doing a smoke test!
            target,
            Kind::MiriTest,
            "src/tools/miri/test-cargo-miri",
            SourceType::Submodule,
            &[],
        );

        // If we are testing stage 2+ cargo miri, make sure that it works with the in-tree cargo.
        if stage >= 2 {
            let built_cargo = builder
                .ensure(tool::Cargo::from_build_compiler(
                    // For stage 2 cargo miri, we want to use stage 1 cargo. So we need to build it
                    // with stage 0 rustc.
                    builder.compiler(stage - 2, builder.host_target),
                    target,
                ))
                .tool_path;
            cargo.env("CARGO", built_cargo);
        }

        // We're not using `prepare_cargo_test` so we have to do this ourselves.
        // (We're not using that as the test-cargo-miri crate is not known to bootstrap.)
        match builder.doc_tests {
            DocTests::Yes => {}
            DocTests::No => {
                cargo.args(["--lib", "--bins", "--examples", "--tests", "--benches"]);
            }
            DocTests::Only => {
                cargo.arg("--doc");
            }
        }
        cargo.arg("--").args(builder.config.test_args());

        // Finally, run everything.
        let mut cargo = BootstrapCommand::from(cargo);
        {

Review comment (suggestion):
Question: should we explicitly note that this necessarily will require checking out the cargo submodule? (I.e. otherwise I don't know what in-tree cargo we are testing lol)

Code after:
            eprintln!("cargo-miri cannot be tested at stage 0");
            std::process::exit(1);
        }

        // This compiler runs on the host, we'll just use it for the target.
        let build_compiler = builder.compiler(stage, host);

        // Run `cargo miri test`.
        // This is just a smoke test (Miri's own CI invokes this in a bunch of different ways and ensures
        // that we get the desired output), but that is sufficient to make sure that the libtest harness
        // itself executes properly under Miri, and that all the logic in `cargo-miri` does not explode.
        let mut cargo = tool::prepare_tool_cargo(
            builder,
            build_compiler,
            Mode::ToolStd, // it's unclear what to use here, we're not building anything just doing a smoke test!
            target,
            Kind::MiriTest,
            "src/tools/miri/test-cargo-miri",
            SourceType::Submodule,
            &[],
        );

        // If we are testing stage 2+ cargo miri, make sure that it works with the in-tree cargo.
        // We want to do this *somewhere* to ensure that Miri + nightly cargo actually works.
        if stage >= 2 {
            let built_cargo = builder
                .ensure(tool::Cargo::from_build_compiler(
                    // Build stage 1 cargo here, we don't need it to be built in any special way,
                    // just that it is built from in-tree sources.
                    builder.compiler(0, builder.host_target),
                    builder.host_target,
                ))
                .tool_path;
            cargo.env("CARGO", built_cargo);
        }

        // We're not using `prepare_cargo_test` so we have to do this ourselves.
        // (We're not using that as the test-cargo-miri crate is not known to bootstrap.)
        match builder.doc_tests {
            DocTests::Yes => {}
            DocTests::No => {
                cargo.args(["--lib", "--bins", "--examples", "--tests", "--benches"]);
            }
            DocTests::Only => {
                cargo.arg("--doc");
            }
        }
        cargo.arg("--").args(builder.config.test_args());

        // Finally, run everything.
        let mut cargo = BootstrapCommand::from(cargo);