File tree 2 files changed +16
-8
lines changed
2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -172,15 +172,18 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
172
172
Evaluator :: late_init ( & mut ecx, config) ?;
173
173
174
174
// 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
+ ) ;
178
181
}
179
182
180
- // Setup first stack- frame
183
+ // Setup first stack frame.
181
184
let entry_instance = ty:: Instance :: mono ( tcx, entry_id) ;
182
185
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].
184
187
185
188
// Second argument (argc): length of `config.args`.
186
189
let argc = Scalar :: from_machine_usize ( u64:: try_from ( config. args . len ( ) ) . unwrap ( ) , & ecx) ;
Original file line number Diff line number Diff line change @@ -71,11 +71,16 @@ fn try_resolve_did<'tcx>(tcx: TyCtxt<'tcx>, path: &[&str]) -> Option<DefId> {
71
71
}
72
72
73
73
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
+
74
80
/// Gets an instance for a path.
75
81
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) )
79
84
}
80
85
81
86
/// Evaluates the scalar at the specified path. Returns Some(val)
You can’t perform that action at this time.
0 commit comments