Skip to content

Commit

Permalink
Rollup merge of rust-lang#87427 - RalfJung:no-mir-for, r=oli-obk
Browse files Browse the repository at this point in the history
get rid of NoMirFor error variant

The only place where we throw that error, it is very quickly caught again and turned into a different error. So raise that other error immediately.
  • Loading branch information
JohnTitor authored Jul 27, 2021
2 parents 7f71da8 + 3b9f811 commit 26dd4af
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
3 changes: 0 additions & 3 deletions compiler/rustc_middle/src/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,6 @@ impl fmt::Display for UndefinedBehaviorInfo<'_> {
pub enum UnsupportedOpInfo {
/// Free-form case. Only for errors that are never caught!
Unsupported(String),
/// Could not find MIR for a function.
NoMirFor(DefId),
/// Encountered a pointer where we needed raw bytes.
ReadPointerAsBytes,
//
Expand All @@ -421,7 +419,6 @@ impl fmt::Display for UnsupportedOpInfo {
match self {
Unsupported(ref msg) => write!(f, "{}", msg),
ReadExternStatic(did) => write!(f, "cannot read from extern static ({:?})", did),
NoMirFor(did) => write!(f, "no MIR body is available for {:?}", did),
ReadPointerAsBytes => write!(f, "unable to turn pointer into raw bytes",),
ThreadLocalStatic(did) => write!(f, "cannot access thread local static ({:?})", did),
}
Expand Down
19 changes: 4 additions & 15 deletions compiler/rustc_mir/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
if ecx.tcx.is_ctfe_mir_available(def.did) {
Ok(ecx.tcx.mir_for_ctfe_opt_const_arg(def))
} else {
throw_unsup!(NoMirFor(def.did))
let path = ecx.tcx.def_path_str(def.did);
Err(ConstEvalErrKind::NeedsRfc(format!("calling extern function `{}`", path))
.into())
}
}
_ => Ok(ecx.tcx.instance_mir(instance)),
Expand Down Expand Up @@ -247,20 +249,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
}
}
// This is a const fn. Call it.
Ok(Some(match ecx.load_mir(instance.def, None) {
Ok(body) => body,
Err(err) => {
if let err_unsup!(NoMirFor(did)) = err.kind() {
let path = ecx.tcx.def_path_str(*did);
return Err(ConstEvalErrKind::NeedsRfc(format!(
"calling extern function `{}`",
path
))
.into());
}
return Err(err);
}
}))
Ok(Some(ecx.load_mir(instance.def, None)?))
}

fn call_intrinsic(
Expand Down

0 comments on commit 26dd4af

Please sign in to comment.