about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2024-03-19 19:35:35 +0100
committerRalf Jung <post@ralfj.de>2024-03-20 11:01:08 +0100
commite5398041b4ed1a65a108e06cd7bdf8122177fb92 (patch)
tree75f747171a64be7decd100ba688d9f8525d89aaa
parent67966f3e80f9e5abd65f3fd98ff0fc3b861d06f3 (diff)
downloadrust-e5398041b4ed1a65a108e06cd7bdf8122177fb92.tar.gz
rust-e5398041b4ed1a65a108e06cd7bdf8122177fb92.zip
run full mono-item collection on all MIRI_BE_RUSTC=target builds
this fixes compile_fail doctests with post-mono errors
-rw-r--r--src/tools/miri/src/bin/miri.rs20
-rw-r--r--src/tools/miri/test-cargo-miri/src/lib.rs18
-rw-r--r--src/tools/miri/test-cargo-miri/test.default.stdout.ref6
-rw-r--r--src/tools/miri/test-cargo-miri/test.filter.stdout.ref2
4 files changed, 42 insertions, 4 deletions
diff --git a/src/tools/miri/src/bin/miri.rs b/src/tools/miri/src/bin/miri.rs
index 6955e649b4d..c12382527e7 100644
--- a/src/tools/miri/src/bin/miri.rs
+++ b/src/tools/miri/src/bin/miri.rs
@@ -179,6 +179,26 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
             });
         }
     }
+
+    fn after_analysis<'tcx>(
+        &mut self,
+        _: &rustc_interface::interface::Compiler,
+        queries: &'tcx rustc_interface::Queries<'tcx>,
+    ) -> Compilation {
+        queries.global_ctxt().unwrap().enter(|tcx| {
+            if self.target_crate {
+                // cargo-miri has patched the compiler flags to make these into check-only builds,
+                // but we are still emulating regular rustc builds, which would perform post-mono
+                // const-eval during collection. So let's also do that here, even if we might be
+                // running with `--emit=metadata`. In particular this is needed to make
+                // `compile_fail` doc tests trigger post-mono errors.
+                // In general `collect_and_partition_mono_items` is not safe to call in check-only
+                // builds, but we are setting `-Zalways-encode-mir` which avoids those issues.
+                let _ = tcx.collect_and_partition_mono_items(());
+            }
+        });
+        Compilation::Continue
+    }
 }
 
 fn show_error(msg: &impl std::fmt::Display) -> ! {
diff --git a/src/tools/miri/test-cargo-miri/src/lib.rs b/src/tools/miri/test-cargo-miri/src/lib.rs
index 66c8aa2eac5..e6b8c4ef65b 100644
--- a/src/tools/miri/test-cargo-miri/src/lib.rs
+++ b/src/tools/miri/test-cargo-miri/src/lib.rs
@@ -1,13 +1,31 @@
 /// Doc-test test
+///
 /// ```rust
 /// assert!(cargo_miri_test::make_true());
 /// ```
+///
+/// `no_run` test:
+///
 /// ```rust,no_run
 /// assert!(!cargo_miri_test::make_true());
 /// ```
+///
+/// `compile_fail` test:
+///
 /// ```rust,compile_fail
 /// assert!(cargo_miri_test::make_true() == 5);
 /// ```
+///
+/// Post-monomorphization error in `compile_fail` test:
+///
+/// ```rust,compile_fail
+/// struct Fail<T>(T);
+/// impl<T> Fail<T> {
+///     const C: () = panic!();
+/// }
+///
+/// let _val = Fail::<i32>::C;
+/// ```
 #[no_mangle]
 pub fn make_true() -> bool {
     issue_1567::use_the_dependency();
diff --git a/src/tools/miri/test-cargo-miri/test.default.stdout.ref b/src/tools/miri/test-cargo-miri/test.default.stdout.ref
index 9a17f3d61b6..922d2120bed 100644
--- a/src/tools/miri/test-cargo-miri/test.default.stdout.ref
+++ b/src/tools/miri/test-cargo-miri/test.default.stdout.ref
@@ -10,7 +10,7 @@ running 6 tests
 test result: ok. 5 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out
 
 
-running 4 tests
-....
-test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
+running 5 tests
+.....
+test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
 
diff --git a/src/tools/miri/test-cargo-miri/test.filter.stdout.ref b/src/tools/miri/test-cargo-miri/test.filter.stdout.ref
index c618956656a..5c819dd5323 100644
--- a/src/tools/miri/test-cargo-miri/test.filter.stdout.ref
+++ b/src/tools/miri/test-cargo-miri/test.filter.stdout.ref
@@ -13,5 +13,5 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 5 filtered out
 
 running 0 tests
 
-test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 4 filtered out; finished in $TIME
+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 5 filtered out; finished in $TIME