Skip to content

Commit c2e4916

Browse files
committed
adjust frame_in_std to recognize std tests
1 parent 9e35555 commit c2e4916

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/tools/miri/src/helpers.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -968,10 +968,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
968968

969969
fn frame_in_std(&self) -> bool {
970970
let this = self.eval_context_ref();
971-
let Some(start_fn) = this.tcx.lang_items().start_fn() else {
972-
// no_std situations
973-
return false;
974-
};
975971
let frame = this.frame();
976972
// Make an attempt to get at the instance of the function this is inlined from.
977973
let instance: Option<_> = try {
@@ -982,13 +978,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
982978
};
983979
// Fall back to the instance of the function itself.
984980
let instance = instance.unwrap_or(frame.instance);
985-
// Now check if this is in the same crate as start_fn.
986-
// As a special exception we also allow unit tests from
987-
// <https://github.com/rust-lang/miri-test-libstd/tree/master/std_miri_test> to call these
988-
// shims.
981+
// Now check the crate it is in. We could try to be clever here and e.g. check if this is
982+
// the same crate as `start_fn`, but that would not work for running std tests in Miri, so
983+
// we'd need some more hacks anyway. So we just check the name of the crate. If someone
984+
// calls their crate `std` then we'll just let them keep the pieces.
989985
let frame_crate = this.tcx.def_path(instance.def_id()).krate;
990-
frame_crate == this.tcx.def_path(start_fn).krate
991-
|| this.tcx.crate_name(frame_crate).as_str() == "std_miri_test"
986+
let crate_name = this.tcx.crate_name(frame_crate);
987+
let crate_name = crate_name.as_str();
988+
// On miri-test-libstd, the name of the crate is different.
989+
crate_name == "std" || crate_name == "std_miri_test"
992990
}
993991

994992
/// Handler that should be called when unsupported functionality is encountered.

0 commit comments

Comments
 (0)