@@ -371,32 +371,31 @@ pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: @expr)
371
371
expr_cast( base, _) => {
372
372
let ety = ty:: expr_ty ( tcx, e) ;
373
373
let base = eval_const_expr_partial ( tcx, base) ;
374
- match ty:: get ( ety) . sty {
375
- ty:: ty_float( _) => {
376
- match base {
377
- Ok ( const_uint( u) ) => Ok ( const_float ( u as f64 ) ) ,
378
- Ok ( const_int( i) ) => Ok ( const_float ( i as f64 ) ) ,
379
- Ok ( const_float( _) ) => base,
380
- _ => Err ( ~"Can ' t cast float to str")
381
- }
382
- }
383
- ty:: ty_uint( _) => {
384
- match base {
385
- Ok ( const_uint( _) ) => base,
386
- Ok ( const_int( i) ) => Ok ( const_uint ( i as u64 ) ) ,
387
- Ok ( const_float( f) ) => Ok ( const_uint ( f as u64 ) ) ,
388
- _ => Err ( ~"Can ' t cast str to uint")
389
- }
390
- }
391
- ty:: ty_int( _) | ty:: ty_bool => {
392
- match base {
393
- Ok ( const_uint( u) ) => Ok ( const_int ( u as i64 ) ) ,
394
- Ok ( const_int( _) ) => base,
395
- Ok ( const_float( f) ) => Ok ( const_int ( f as i64 ) ) ,
396
- _ => Err ( ~"Can ' t cast str to int")
374
+ match /*bad*/ copy base {
375
+ Err ( _) => base,
376
+ Ok ( val) => {
377
+ match ty:: get ( ety) . sty {
378
+ ty:: ty_float( _) => match val {
379
+ const_uint( u) => Ok ( const_float ( u as f64 ) ) ,
380
+ const_int( i) => Ok ( const_float ( i as f64 ) ) ,
381
+ const_float( _) => base,
382
+ _ => Err ( ~"Can ' t cast float to str") ,
383
+ } ,
384
+ ty:: ty_uint( _) => match val {
385
+ const_uint( _) => base,
386
+ const_int( i) => Ok ( const_uint ( i as u64 ) ) ,
387
+ const_float( f) => Ok ( const_uint ( f as u64 ) ) ,
388
+ _ => Err ( ~"Can ' t cast str to uint") ,
389
+ } ,
390
+ ty:: ty_int( _) | ty:: ty_bool => match val {
391
+ const_uint( u) => Ok ( const_int ( u as i64 ) ) ,
392
+ const_int( _) => base,
393
+ const_float( f) => Ok ( const_int ( f as i64 ) ) ,
394
+ _ => Err ( ~"Can ' t cast str to int") ,
395
+ } ,
396
+ _ => Err ( ~"Can ' t cast this type")
397
+ }
397
398
}
398
- }
399
- _ => Err ( ~"Can ' t cast this type")
400
399
}
401
400
}
402
401
expr_path( _) => {
0 commit comments