@@ -138,55 +138,77 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
138138 . unwrap_or_else ( || panic ! ( "failed to find required Rust item: {path:?}" ) )
139139 }
140140
141- /// Evaluates the scalar at the specified path. Returns Some(val)
142- /// if the path could be resolved, and None otherwise
143- fn eval_path_scalar ( & self , path : & [ & str ] ) -> InterpResult < ' tcx , Scalar < Provenance > > {
141+ /// Evaluates the scalar at the specified path.
142+ fn eval_path_scalar ( & self , path : & [ & str ] ) -> Scalar < Provenance > {
144143 let this = self . eval_context_ref ( ) ;
145144 let instance = this. resolve_path ( path, Namespace :: ValueNS ) ;
146145 let cid = GlobalId { instance, promoted : None } ;
147146 // We don't give a span -- this isn't actually used directly by the program anyway.
148- let const_val = this. eval_global ( cid, None ) ?;
147+ let const_val = this
148+ . eval_global ( cid, None )
149+ . unwrap_or_else ( |err| panic ! ( "failed to evaluate required Rust item: {path:?}\n {err}" ) ) ;
149150 this. read_scalar ( & const_val. into ( ) )
151+ . unwrap_or_else ( |err| panic ! ( "failed to read required Rust item: {path:?}\n {err}" ) )
150152 }
151153
152154 /// Helper function to get a `libc` constant as a `Scalar`.
153- fn eval_libc ( & self , name : & str ) -> InterpResult < ' tcx , Scalar < Provenance > > {
155+ fn eval_libc ( & self , name : & str ) -> Scalar < Provenance > {
154156 self . eval_path_scalar ( & [ "libc" , name] )
155157 }
156158
157159 /// Helper function to get a `libc` constant as an `i32`.
158- fn eval_libc_i32 ( & self , name : & str ) -> InterpResult < ' tcx , i32 > {
160+ fn eval_libc_i32 ( & self , name : & str ) -> i32 {
159161 // TODO: Cache the result.
160- self . eval_libc ( name) ?. to_i32 ( )
162+ self . eval_libc ( name) . to_i32 ( ) . unwrap_or_else ( |_err| {
163+ panic ! ( "required libc item has unexpected type (not `i32`): {name}" )
164+ } )
165+ }
166+
167+ /// Helper function to get a `libc` constant as an `u32`.
168+ fn eval_libc_u32 ( & self , name : & str ) -> u32 {
169+ // TODO: Cache the result.
170+ self . eval_libc ( name) . to_u32 ( ) . unwrap_or_else ( |_err| {
171+ panic ! ( "required libc item has unexpected type (not `u32`): {name}" )
172+ } )
161173 }
162174
163175 /// Helper function to get a `windows` constant as a `Scalar`.
164- fn eval_windows ( & self , module : & str , name : & str ) -> InterpResult < ' tcx , Scalar < Provenance > > {
176+ fn eval_windows ( & self , module : & str , name : & str ) -> Scalar < Provenance > {
165177 self . eval_context_ref ( ) . eval_path_scalar ( & [ "std" , "sys" , "windows" , module, name] )
166178 }
167179
180+ /// Helper function to get a `windows` constant as a `u32`.
181+ fn eval_windows_u32 ( & self , module : & str , name : & str ) -> u32 {
182+ // TODO: Cache the result.
183+ self . eval_windows ( module, name) . to_u32 ( ) . unwrap_or_else ( |_err| {
184+ panic ! ( "required Windows item has unexpected type (not `u32`): {module}::{name}" )
185+ } )
186+ }
187+
168188 /// Helper function to get a `windows` constant as a `u64`.
169- fn eval_windows_u64 ( & self , module : & str , name : & str ) -> InterpResult < ' tcx , u64 > {
189+ fn eval_windows_u64 ( & self , module : & str , name : & str ) -> u64 {
170190 // TODO: Cache the result.
171- self . eval_windows ( module, name) ?. to_u64 ( )
191+ self . eval_windows ( module, name) . to_u64 ( ) . unwrap_or_else ( |_err| {
192+ panic ! ( "required Windows item has unexpected type (not `u64`): {module}::{name}" )
193+ } )
172194 }
173195
174196 /// Helper function to get the `TyAndLayout` of a `libc` type
175- fn libc_ty_layout ( & self , name : & str ) -> InterpResult < ' tcx , TyAndLayout < ' tcx > > {
197+ fn libc_ty_layout ( & self , name : & str ) -> TyAndLayout < ' tcx > {
176198 let this = self . eval_context_ref ( ) ;
177199 let ty = this
178200 . resolve_path ( & [ "libc" , name] , Namespace :: TypeNS )
179201 . ty ( * this. tcx , ty:: ParamEnv :: reveal_all ( ) ) ;
180- this. layout_of ( ty)
202+ this. layout_of ( ty) . unwrap ( )
181203 }
182204
183205 /// Helper function to get the `TyAndLayout` of a `windows` type
184- fn windows_ty_layout ( & self , name : & str ) -> InterpResult < ' tcx , TyAndLayout < ' tcx > > {
206+ fn windows_ty_layout ( & self , name : & str ) -> TyAndLayout < ' tcx > {
185207 let this = self . eval_context_ref ( ) ;
186208 let ty = this
187209 . resolve_path ( & [ "std" , "sys" , "windows" , "c" , name] , Namespace :: TypeNS )
188210 . ty ( * this. tcx , ty:: ParamEnv :: reveal_all ( ) ) ;
189- this. layout_of ( ty)
211+ this. layout_of ( ty) . unwrap ( )
190212 }
191213
192214 /// Project to the given *named* field of the mplace (which must be a struct or union type).
@@ -609,14 +631,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
609631 if target. families . iter ( ) . any ( |f| f == "unix" ) {
610632 for & ( name, kind) in UNIX_IO_ERROR_TABLE {
611633 if err_kind == kind {
612- return this. eval_libc ( name) ;
634+ return Ok ( this. eval_libc ( name) ) ;
613635 }
614636 }
615637 throw_unsup_format ! ( "io error {:?} cannot be translated into a raw os error" , err_kind)
616638 } else if target. families . iter ( ) . any ( |f| f == "windows" ) {
617639 // FIXME: we have to finish implementing the Windows equivalent of this.
618640 use std:: io:: ErrorKind :: * ;
619- this. eval_windows (
641+ Ok ( this. eval_windows (
620642 "c" ,
621643 match err_kind {
622644 NotFound => "ERROR_FILE_NOT_FOUND" ,
@@ -627,7 +649,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
627649 err_kind
628650 ) ,
629651 } ,
630- )
652+ ) )
631653 } else {
632654 throw_unsup_format ! (
633655 "converting io::Error into errnum is unsupported for OS {}" ,
@@ -647,7 +669,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
647669 if target. families . iter ( ) . any ( |f| f == "unix" ) {
648670 let errnum = errnum. to_i32 ( ) ?;
649671 for & ( name, kind) in UNIX_IO_ERROR_TABLE {
650- if errnum == this. eval_libc_i32 ( name) ? {
672+ if errnum == this. eval_libc_i32 ( name) {
651673 return Ok ( Some ( kind) ) ;
652674 }
653675 }
0 commit comments