@@ -2844,7 +2844,7 @@ fn check_lit<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
2844
2844
ast:: LitInt ( _, ast:: SignedIntLit ( t, _) ) => ty:: mk_mach_int ( tcx, t) ,
2845
2845
ast:: LitInt ( _, ast:: UnsignedIntLit ( t) ) => ty:: mk_mach_uint ( tcx, t) ,
2846
2846
ast:: LitInt ( _, ast:: UnsuffixedIntLit ( _) ) => {
2847
- let opt_ty = expected. map_to_option ( fcx, |ty| {
2847
+ let opt_ty = expected. to_option ( fcx) . and_then ( |ty| {
2848
2848
match ty. sty {
2849
2849
ty:: ty_int( _) | ty:: ty_uint( _) => Some ( ty) ,
2850
2850
ty:: ty_char => Some ( tcx. types . u8 ) ,
@@ -2858,7 +2858,7 @@ fn check_lit<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
2858
2858
}
2859
2859
ast:: LitFloat ( _, t) => ty:: mk_mach_float ( tcx, t) ,
2860
2860
ast:: LitFloatUnsuffixed ( _) => {
2861
- let opt_ty = expected. map_to_option ( fcx, |ty| {
2861
+ let opt_ty = expected. to_option ( fcx) . and_then ( |ty| {
2862
2862
match ty. sty {
2863
2863
ty:: ty_float( _) => Some ( ty) ,
2864
2864
_ => None
@@ -3761,7 +3761,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
3761
3761
}
3762
3762
}
3763
3763
ast:: ExprUnary ( unop, ref oprnd) => {
3764
- let expected_inner = expected. map ( fcx, |ty| {
3764
+ let expected_inner = expected. to_option ( fcx) . map_or ( NoExpectation , |ty| {
3765
3765
match unop {
3766
3766
ast:: UnUniq => match ty. sty {
3767
3767
ty:: ty_uniq( ty) => {
@@ -3851,8 +3851,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
3851
3851
fcx. write_ty ( id, oprnd_t) ;
3852
3852
}
3853
3853
ast:: ExprAddrOf ( mutbl, ref oprnd) => {
3854
- let expected = expected. only_has_type ( ) ;
3855
- let hint = expected. map ( fcx, |ty| {
3854
+ let hint = expected. only_has_type ( fcx) . map_or ( NoExpectation , |ty| {
3856
3855
match ty. sty {
3857
3856
ty:: ty_rptr( _, ref mt) | ty:: ty_ptr( ref mt) => {
3858
3857
if ty:: expr_is_lval ( fcx. tcx ( ) , & * * oprnd) {
@@ -4065,7 +4064,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
4065
4064
check_cast ( fcx, expr, & * * e, & * * t) ;
4066
4065
}
4067
4066
ast:: ExprVec ( ref args) => {
4068
- let uty = expected. map_to_option ( fcx, |uty| {
4067
+ let uty = expected. to_option ( fcx) . and_then ( |uty| {
4069
4068
match uty. sty {
4070
4069
ty:: ty_vec( ty, _) => Some ( ty) ,
4071
4070
_ => None
@@ -4134,8 +4133,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
4134
4133
}
4135
4134
}
4136
4135
ast:: ExprTup ( ref elts) => {
4137
- let expected = expected. only_has_type ( ) ;
4138
- let flds = expected. map_to_option ( fcx, |ty| {
4136
+ let flds = expected. only_has_type ( fcx) . and_then ( |ty| {
4139
4137
match ty. sty {
4140
4138
ty:: ty_tup( ref flds) => Some ( & flds[ ] ) ,
4141
4139
_ => None
@@ -4428,13 +4426,6 @@ impl<'tcx> Expectation<'tcx> {
4428
4426
}
4429
4427
}
4430
4428
4431
- fn only_has_type ( self ) -> Expectation < ' tcx > {
4432
- match self {
4433
- ExpectHasType ( t) => ExpectHasType ( t) ,
4434
- _ => NoExpectation
4435
- }
4436
- }
4437
-
4438
4429
// Resolves `expected` by a single level if it is a variable. If
4439
4430
// there is no expected type or resolution is not possible (e.g.,
4440
4431
// no constraints yet present), just returns `None`.
@@ -4458,25 +4449,19 @@ impl<'tcx> Expectation<'tcx> {
4458
4449
}
4459
4450
}
4460
4451
4461
- fn map < ' a , F > ( self , fcx : & FnCtxt < ' a , ' tcx > , unpack : F ) -> Expectation < ' tcx > where
4462
- F : FnOnce ( Ty < ' tcx > ) -> Expectation < ' tcx >
4463
- {
4452
+ fn to_option < ' a > ( self , fcx : & FnCtxt < ' a , ' tcx > ) -> Option < Ty < ' tcx > > {
4464
4453
match self . resolve ( fcx) {
4465
- NoExpectation => NoExpectation ,
4454
+ NoExpectation => None ,
4466
4455
ExpectCastableToType ( ty) |
4467
4456
ExpectHasType ( ty) |
4468
- ExpectRvalueLikeUnsized ( ty) => unpack ( ty) ,
4457
+ ExpectRvalueLikeUnsized ( ty) => Some ( ty) ,
4469
4458
}
4470
4459
}
4471
4460
4472
- fn map_to_option < ' a , O , F > ( self , fcx : & FnCtxt < ' a , ' tcx > , unpack : F ) -> Option < O > where
4473
- F : FnOnce ( Ty < ' tcx > ) -> Option < O > ,
4474
- {
4461
+ fn only_has_type < ' a > ( self , fcx : & FnCtxt < ' a , ' tcx > ) -> Option < Ty < ' tcx > > {
4475
4462
match self . resolve ( fcx) {
4476
- NoExpectation => None ,
4477
- ExpectCastableToType ( ty) |
4478
- ExpectHasType ( ty) |
4479
- ExpectRvalueLikeUnsized ( ty) => unpack ( ty) ,
4463
+ ExpectHasType ( ty) => Some ( ty) ,
4464
+ _ => None
4480
4465
}
4481
4466
}
4482
4467
}
0 commit comments