Skip to content

Commit 8f7c8f7

Browse files
committed
Auto merge of #2121 - RalfJung:less-ice, r=RalfJung
don't ICE when libcore is missing Fixes #2120
2 parents 90d28ea + 90a190e commit 8f7c8f7

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/eval.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,18 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
172172
Evaluator::late_init(&mut ecx, config)?;
173173

174174
// Make sure we have MIR. We check MIR for some stable monomorphic function in libcore.
175-
let sentinel = ecx.resolve_path(&["core", "ascii", "escape_default"]);
176-
if !tcx.is_mir_available(sentinel.def.def_id()) {
177-
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.");
175+
let sentinel = ecx.try_resolve_path(&["core", "ascii", "escape_default"]);
176+
if !matches!(sentinel, Some(s) if tcx.is_mir_available(s.def.def_id())) {
177+
tcx.sess.fatal(
178+
"the current sysroot was built without `-Zalways-encode-mir`, or libcore seems missing. \
179+
Use `cargo miri setup` to prepare a sysroot that is suitable for Miri."
180+
);
178181
}
179182

180-
// Setup first stack-frame
183+
// Setup first stack frame.
181184
let entry_instance = ty::Instance::mono(tcx, entry_id);
182185

183-
// First argument is constructed later, because its skipped if the entry function uses #[start]
186+
// First argument is constructed later, because it's skipped if the entry function uses #[start].
184187

185188
// Second argument (argc): length of `config.args`.
186189
let argc = Scalar::from_machine_usize(u64::try_from(config.args.len()).unwrap(), &ecx);

src/helpers.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,16 @@ fn try_resolve_did<'tcx>(tcx: TyCtxt<'tcx>, path: &[&str]) -> Option<DefId> {
7171
}
7272

7373
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
74+
/// Gets an instance for a path; fails gracefully if the path does not exist.
75+
fn try_resolve_path(&self, path: &[&str]) -> Option<ty::Instance<'tcx>> {
76+
let did = try_resolve_did(self.eval_context_ref().tcx.tcx, path)?;
77+
Some(ty::Instance::mono(self.eval_context_ref().tcx.tcx, did))
78+
}
79+
7480
/// Gets an instance for a path.
7581
fn resolve_path(&self, path: &[&str]) -> ty::Instance<'tcx> {
76-
let did = try_resolve_did(self.eval_context_ref().tcx.tcx, path)
77-
.unwrap_or_else(|| panic!("failed to find required Rust item: {:?}", path));
78-
ty::Instance::mono(self.eval_context_ref().tcx.tcx, did)
82+
self.try_resolve_path(path)
83+
.unwrap_or_else(|| panic!("failed to find required Rust item: {:?}", path))
7984
}
8085

8186
/// Evaluates the scalar at the specified path. Returns Some(val)

0 commit comments

Comments
 (0)