Skip to content

Commit

Permalink
Auto merge of #3392 - RalfJung:post-mono, r=oli-obk
Browse files Browse the repository at this point in the history
fix compile_fail doctests with post-mono errors

Fixes #2423
  • Loading branch information
bors committed Mar 20, 2024
2 parents 5162995 + 73ba941 commit addad82
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
20 changes: 20 additions & 0 deletions src/bin/miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) -> ! {
Expand Down
18 changes: 18 additions & 0 deletions test-cargo-miri/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
6 changes: 3 additions & 3 deletions test-cargo-miri/test.default.stdout.ref
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion test-cargo-miri/test.filter.stdout.ref
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit addad82

Please sign in to comment.