@@ -5,10 +5,10 @@ use std::time::Duration;
5
5
6
6
use log:: trace;
7
7
8
- use rustc_middle:: mir;
9
- use rustc_middle:: ty:: { self , List , TyCtxt , layout:: TyAndLayout } ;
10
8
use rustc_hir:: def_id:: { DefId , CRATE_DEF_INDEX } ;
11
- use rustc_target:: abi:: { LayoutOf , Size , FieldsShape , Variants } ;
9
+ use rustc_middle:: mir;
10
+ use rustc_middle:: ty:: { self , layout:: TyAndLayout , List , TyCtxt } ;
11
+ use rustc_target:: abi:: { FieldsShape , LayoutOf , Size , Variants } ;
12
12
use rustc_target:: spec:: abi:: Abi ;
13
13
14
14
use rand:: RngCore ;
@@ -19,10 +19,8 @@ impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mi
19
19
20
20
/// Gets an instance for a path.
21
21
fn try_resolve_did < ' mir , ' tcx > ( tcx : TyCtxt < ' tcx > , path : & [ & str ] ) -> Option < DefId > {
22
- tcx. crates ( )
23
- . iter ( )
24
- . find ( |& & krate| tcx. original_crate_name ( krate) . as_str ( ) == path[ 0 ] )
25
- . and_then ( |krate| {
22
+ tcx. crates ( ) . iter ( ) . find ( |& & krate| tcx. original_crate_name ( krate) . as_str ( ) == path[ 0 ] ) . and_then (
23
+ |krate| {
26
24
let krate = DefId { krate : * krate, index : CRATE_DEF_INDEX } ;
27
25
let mut items = tcx. item_children ( krate) ;
28
26
let mut path_it = path. iter ( ) . skip ( 1 ) . peekable ( ) ;
@@ -40,7 +38,8 @@ fn try_resolve_did<'mir, 'tcx>(tcx: TyCtxt<'tcx>, path: &[&str]) -> Option<DefId
40
38
}
41
39
}
42
40
None
43
- } )
41
+ } ,
42
+ )
44
43
}
45
44
46
45
pub trait EvalContextExt < ' mir , ' tcx : ' mir > : crate :: MiriEvalContextExt < ' mir , ' tcx > {
@@ -53,10 +52,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
53
52
54
53
/// Evaluates the scalar at the specified path. Returns Some(val)
55
54
/// if the path could be resolved, and None otherwise
56
- fn eval_path_scalar (
57
- & mut self ,
58
- path : & [ & str ] ,
59
- ) -> InterpResult < ' tcx , ScalarMaybeUninit < Tag > > {
55
+ fn eval_path_scalar ( & mut self , path : & [ & str ] ) -> InterpResult < ' tcx , ScalarMaybeUninit < Tag > > {
60
56
let this = self . eval_context_mut ( ) ;
61
57
let instance = this. resolve_path ( path) ;
62
58
let cid = GlobalId { instance, promoted : None } ;
@@ -67,9 +63,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
67
63
68
64
/// Helper function to get a `libc` constant as a `Scalar`.
69
65
fn eval_libc ( & mut self , name : & str ) -> InterpResult < ' tcx , Scalar < Tag > > {
70
- self . eval_context_mut ( )
71
- . eval_path_scalar ( & [ "libc" , name] ) ?
72
- . check_init ( )
66
+ self . eval_context_mut ( ) . eval_path_scalar ( & [ "libc" , name] ) ?. check_init ( )
73
67
}
74
68
75
69
/// Helper function to get a `libc` constant as an `i32`.
@@ -101,7 +95,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
101
95
/// Helper function to get the `TyAndLayout` of a `windows` type
102
96
fn windows_ty_layout ( & mut self , name : & str ) -> InterpResult < ' tcx , TyAndLayout < ' tcx > > {
103
97
let this = self . eval_context_mut ( ) ;
104
- let ty = this. resolve_path ( & [ "std" , "sys" , "windows" , "c" , name] ) . ty ( * this. tcx , ty:: ParamEnv :: reveal_all ( ) ) ;
98
+ let ty = this
99
+ . resolve_path ( & [ "std" , "sys" , "windows" , "c" , name] )
100
+ . ty ( * this. tcx , ty:: ParamEnv :: reveal_all ( ) ) ;
105
101
this. layout_of ( ty)
106
102
}
107
103
@@ -170,7 +166,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
170
166
let param_env = ty:: ParamEnv :: reveal_all ( ) ; // in Miri this is always the param_env we use... and this.param_env is private.
171
167
let callee_abi = f. ty ( * this. tcx , param_env) . fn_sig ( * this. tcx ) . abi ( ) ;
172
168
if callee_abi != caller_abi {
173
- throw_ub_format ! ( "calling a function with ABI {} using caller ABI {}" , callee_abi. name( ) , caller_abi. name( ) )
169
+ throw_ub_format ! (
170
+ "calling a function with ABI {} using caller ABI {}" ,
171
+ callee_abi. name( ) ,
172
+ caller_abi. name( )
173
+ )
174
174
}
175
175
176
176
// Push frame.
@@ -181,9 +181,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
181
181
let mut callee_args = this. frame ( ) . body . args_iter ( ) ;
182
182
for arg in args {
183
183
let callee_arg = this. local_place (
184
- callee_args. next ( ) . ok_or_else ( ||
185
- err_ub_format ! ( "callee has fewer arguments than expected" )
186
- ) ?
184
+ callee_args
185
+ . next ( )
186
+ . ok_or_else ( || err_ub_format ! ( "callee has fewer arguments than expected" ) ) ? ,
187
187
) ?;
188
188
this. write_immediate ( * arg, & callee_arg) ?;
189
189
}
@@ -356,7 +356,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
356
356
}
357
357
}
358
358
359
- fn visit_union ( & mut self , _v : & MPlaceTy < ' tcx , Tag > , _fields : NonZeroUsize ) -> InterpResult < ' tcx > {
359
+ fn visit_union (
360
+ & mut self ,
361
+ _v : & MPlaceTy < ' tcx , Tag > ,
362
+ _fields : NonZeroUsize ,
363
+ ) -> InterpResult < ' tcx > {
360
364
bug ! ( "we should have already handled unions in `visit_value`" )
361
365
}
362
366
}
@@ -465,12 +469,21 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
465
469
} ) ?
466
470
} else if target. families . contains ( & "windows" . to_owned ( ) ) {
467
471
// FIXME: we have to finish implementing the Windows equivalent of this.
468
- this. eval_windows ( "c" , match e. kind ( ) {
469
- NotFound => "ERROR_FILE_NOT_FOUND" ,
470
- _ => throw_unsup_format ! ( "io error {} cannot be transformed into a raw os error" , e)
471
- } ) ?
472
+ this. eval_windows (
473
+ "c" ,
474
+ match e. kind ( ) {
475
+ NotFound => "ERROR_FILE_NOT_FOUND" ,
476
+ _ => throw_unsup_format ! (
477
+ "io error {} cannot be transformed into a raw os error" ,
478
+ e
479
+ ) ,
480
+ } ,
481
+ ) ?
472
482
} else {
473
- throw_unsup_format ! ( "setting the last OS error from an io::Error is unsupported for {}." , target_os)
483
+ throw_unsup_format ! (
484
+ "setting the last OS error from an io::Error is unsupported for {}." ,
485
+ target_os
486
+ )
474
487
} ;
475
488
this. set_last_error ( last_error)
476
489
}
@@ -556,8 +569,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
556
569
}
557
570
558
571
/// Check that the number of args is what we expect.
559
- pub fn check_arg_count < ' a , ' tcx , const N : usize > ( args : & ' a [ OpTy < ' tcx , Tag > ] ) -> InterpResult < ' tcx , & ' a [ OpTy < ' tcx , Tag > ; N ] >
560
- where & ' a [ OpTy < ' tcx , Tag > ; N ] : TryFrom < & ' a [ OpTy < ' tcx , Tag > ] > {
572
+ pub fn check_arg_count < ' a , ' tcx , const N : usize > (
573
+ args : & ' a [ OpTy < ' tcx , Tag > ] ,
574
+ ) -> InterpResult < ' tcx , & ' a [ OpTy < ' tcx , Tag > ; N ] >
575
+ where
576
+ & ' a [ OpTy < ' tcx , Tag > ; N ] : TryFrom < & ' a [ OpTy < ' tcx , Tag > ] > ,
577
+ {
561
578
if let Ok ( ops) = args. try_into ( ) {
562
579
return Ok ( ops) ;
563
580
}
@@ -569,7 +586,11 @@ pub fn check_abi<'a>(abi: Abi, exp_abi: Abi) -> InterpResult<'a, ()> {
569
586
if abi == exp_abi {
570
587
Ok ( ( ) )
571
588
} else {
572
- throw_ub_format ! ( "calling a function with ABI {} using caller ABI {}" , exp_abi. name( ) , abi. name( ) )
589
+ throw_ub_format ! (
590
+ "calling a function with ABI {} using caller ABI {}" ,
591
+ exp_abi. name( ) ,
592
+ abi. name( )
593
+ )
573
594
}
574
595
}
575
596
0 commit comments