Skip to content

Commit 6bcd9bc

Browse files
committed
Auto merge of rust-lang#3392 - RalfJung:post-mono, r=oli-obk
fix compile_fail doctests with post-mono errors Fixes rust-lang/miri#2423
2 parents 67966f3 + e539804 commit 6bcd9bc

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

src/tools/miri/src/bin/miri.rs

+20
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,26 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
179179
});
180180
}
181181
}
182+
183+
fn after_analysis<'tcx>(
184+
&mut self,
185+
_: &rustc_interface::interface::Compiler,
186+
queries: &'tcx rustc_interface::Queries<'tcx>,
187+
) -> Compilation {
188+
queries.global_ctxt().unwrap().enter(|tcx| {
189+
if self.target_crate {
190+
// cargo-miri has patched the compiler flags to make these into check-only builds,
191+
// but we are still emulating regular rustc builds, which would perform post-mono
192+
// const-eval during collection. So let's also do that here, even if we might be
193+
// running with `--emit=metadata`. In particular this is needed to make
194+
// `compile_fail` doc tests trigger post-mono errors.
195+
// In general `collect_and_partition_mono_items` is not safe to call in check-only
196+
// builds, but we are setting `-Zalways-encode-mir` which avoids those issues.
197+
let _ = tcx.collect_and_partition_mono_items(());
198+
}
199+
});
200+
Compilation::Continue
201+
}
182202
}
183203

184204
fn show_error(msg: &impl std::fmt::Display) -> ! {

src/tools/miri/test-cargo-miri/src/lib.rs

+18
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
/// Doc-test test
2+
///
23
/// ```rust
34
/// assert!(cargo_miri_test::make_true());
45
/// ```
6+
///
7+
/// `no_run` test:
8+
///
59
/// ```rust,no_run
610
/// assert!(!cargo_miri_test::make_true());
711
/// ```
12+
///
13+
/// `compile_fail` test:
14+
///
815
/// ```rust,compile_fail
916
/// assert!(cargo_miri_test::make_true() == 5);
1017
/// ```
18+
///
19+
/// Post-monomorphization error in `compile_fail` test:
20+
///
21+
/// ```rust,compile_fail
22+
/// struct Fail<T>(T);
23+
/// impl<T> Fail<T> {
24+
/// const C: () = panic!();
25+
/// }
26+
///
27+
/// let _val = Fail::<i32>::C;
28+
/// ```
1129
#[no_mangle]
1230
pub fn make_true() -> bool {
1331
issue_1567::use_the_dependency();

src/tools/miri/test-cargo-miri/test.default.stdout.ref

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ running 6 tests
1010
test result: ok. 5 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out
1111

1212

13-
running 4 tests
14-
....
15-
test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
13+
running 5 tests
14+
.....
15+
test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
1616

src/tools/miri/test-cargo-miri/test.filter.stdout.ref

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 5 filtered out
1313

1414
running 0 tests
1515

16-
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 4 filtered out; finished in $TIME
16+
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 5 filtered out; finished in $TIME
1717

0 commit comments

Comments
 (0)