show proper error when using a sysroot without MIR

This commit is contained in:
Ralf Jung 2021-07-24 14:02:09 +02:00
parent e2872a3f2a
commit 46d31f9230
2 changed files with 6 additions and 2 deletions

View File

@ -132,8 +132,6 @@ pub fn report_error<'tcx, 'mir>(
}; };
#[rustfmt::skip] #[rustfmt::skip]
let helps = match e.kind() { let helps = match e.kind() {
Unsupported(UnsupportedOpInfo::NoMirFor(..)) =>
vec![(None, format!("make sure to use a Miri sysroot, which you can prepare with `cargo miri setup`"))],
Unsupported(UnsupportedOpInfo::ThreadLocalStatic(_) | UnsupportedOpInfo::ReadExternStatic(_)) => Unsupported(UnsupportedOpInfo::ThreadLocalStatic(_) | UnsupportedOpInfo::ReadExternStatic(_)) =>
panic!("Error should never be raised by Miri: {:?}", e.kind()), panic!("Error should never be raised by Miri: {:?}", e.kind()),
Unsupported(_) => Unsupported(_) =>

View File

@ -138,6 +138,12 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
EnvVars::init(&mut ecx, config.excluded_env_vars)?; EnvVars::init(&mut ecx, config.excluded_env_vars)?;
MemoryExtra::init_extern_statics(&mut ecx)?; MemoryExtra::init_extern_statics(&mut ecx)?;
// Make sure we have MIR. We check MIR for some stable monomorphic function in libcore.
let sentinel = ecx.resolve_path(&["core", "ascii", "escape_default"]);
if !tcx.is_mir_available(sentinel.def.def_id()) {
tcx.sess.fatal("the current sysroot was built without `-Zalways-encode-mir`. Use `cargo miri setup` to prepare a sysroot that is suitable for Miri.");
}
// Setup first stack-frame // Setup first stack-frame
let main_instance = ty::Instance::mono(tcx, main_id); let main_instance = ty::Instance::mono(tcx, main_id);
let main_mir = ecx.load_mir(main_instance.def, None)?; let main_mir = ecx.load_mir(main_instance.def, None)?;