@@ -1530,21 +1530,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
1530
1530
}
1531
1531
1532
1532
#[ inline]
1533
- pub fn write_ty ( & self , node_id : ast:: NodeId , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
1533
+ pub fn write_ty ( & self , node_id : ast:: NodeId , ty : Ty < ' tcx > ) {
1534
1534
debug ! ( "write_ty({}, {:?}) in fcx {}" ,
1535
1535
node_id, ty, self . tag( ) ) ;
1536
1536
self . tables . borrow_mut ( ) . node_types . insert ( node_id, ty) ;
1537
-
1538
- // Add adjustments to !-expressions
1539
- if ty. is_never ( ) {
1540
- if let Some ( hir:: map:: NodeExpr ( _) ) = self . tcx . map . find ( node_id) {
1541
- let adj_ty = self . next_diverging_ty_var ( ) ;
1542
- let adj = adjustment:: AdjustNeverToAny ( adj_ty) ;
1543
- self . write_adjustment ( node_id, adj) ;
1544
- return adj_ty;
1545
- }
1546
- }
1547
- ty
1548
1537
}
1549
1538
1550
1539
pub fn write_substs ( & self , node_id : ast:: NodeId , substs : ty:: ItemSubsts < ' tcx > ) {
@@ -1717,16 +1706,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
1717
1706
ty_substituted
1718
1707
}
1719
1708
1720
- pub fn write_nil ( & self , node_id : ast:: NodeId ) -> Ty < ' tcx > {
1721
- self . write_ty ( node_id, self . tcx . mk_nil ( ) )
1709
+ pub fn write_nil ( & self , node_id : ast:: NodeId ) {
1710
+ self . write_ty ( node_id, self . tcx . mk_nil ( ) ) ;
1722
1711
}
1723
1712
1724
- pub fn write_never ( & self , node_id : ast:: NodeId ) -> Ty < ' tcx > {
1725
- self . write_ty ( node_id, self . tcx . types . never )
1713
+ pub fn write_never ( & self , node_id : ast:: NodeId ) {
1714
+ self . write_ty ( node_id, self . tcx . types . never ) ;
1726
1715
}
1727
1716
1728
- pub fn write_error ( & self , node_id : ast:: NodeId ) -> Ty < ' tcx > {
1729
- self . write_ty ( node_id, self . tcx . types . err )
1717
+ pub fn write_error ( & self , node_id : ast:: NodeId ) {
1718
+ self . write_ty ( node_id, self . tcx . types . err ) ;
1730
1719
}
1731
1720
1732
1721
pub fn require_type_meets ( & self ,
@@ -3314,20 +3303,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3314
3303
}
3315
3304
} ) ;
3316
3305
let referent_ty = self . check_expr_with_expectation ( subexpr, expected_inner) ;
3317
- self . write_ty ( id , tcx. mk_box ( referent_ty) )
3306
+ tcx. mk_box ( referent_ty)
3318
3307
}
3319
3308
3320
3309
hir:: ExprLit ( ref lit) => {
3321
- let typ = self . check_lit ( & lit, expected) ;
3322
- self . write_ty ( id, typ)
3310
+ self . check_lit ( & lit, expected)
3323
3311
}
3324
3312
hir:: ExprBinary ( op, ref lhs, ref rhs) => {
3325
- let ty = self . check_binop ( expr, op, lhs, rhs) ;
3326
- self . write_ty ( id, ty)
3313
+ self . check_binop ( expr, op, lhs, rhs)
3327
3314
}
3328
3315
hir:: ExprAssignOp ( op, ref lhs, ref rhs) => {
3329
- let ty = self . check_binop_assign ( expr, op, lhs, rhs) ;
3330
- self . write_ty ( id, ty)
3316
+ self . check_binop_assign ( expr, op, lhs, rhs)
3331
3317
}
3332
3318
hir:: ExprUnary ( unop, ref oprnd) => {
3333
3319
let expected_inner = match unop {
@@ -3386,7 +3372,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3386
3372
}
3387
3373
}
3388
3374
}
3389
- self . write_ty ( id , oprnd_t)
3375
+ oprnd_t
3390
3376
}
3391
3377
hir:: ExprAddrOf ( mutbl, ref oprnd) => {
3392
3378
let hint = expected. only_has_type ( self ) . map_or ( NoExpectation , |ty| {
@@ -3408,7 +3394,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3408
3394
let ty = self . check_expr_with_expectation_and_lvalue_pref ( & oprnd, hint, lvalue_pref) ;
3409
3395
3410
3396
let tm = ty:: TypeAndMut { ty : ty, mutbl : mutbl } ;
3411
- let oprnd_t = if tm. ty . references_error ( ) {
3397
+ if tm. ty . references_error ( ) {
3412
3398
tcx. types . err
3413
3399
} else {
3414
3400
// Note: at this point, we cannot say what the best lifetime
@@ -3426,8 +3412,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3426
3412
// as long as it needs to live.
3427
3413
let region = self . next_region_var ( infer:: AddrOfRegion ( expr. span ) ) ;
3428
3414
tcx. mk_ref ( region, tm)
3429
- } ;
3430
- self . write_ty ( id, oprnd_t)
3415
+ }
3431
3416
}
3432
3417
hir:: ExprPath ( ref opt_qself, ref path) => {
3433
3418
let opt_self_ty = opt_qself. as_ref ( ) . map ( |qself| self . to_ty ( & qself. ty ) ) ;
@@ -3446,7 +3431,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3446
3431
self . add_wf_bounds ( & item_substs. substs , expr) ;
3447
3432
} ) ;
3448
3433
3449
- self . write_ty ( id , ty )
3434
+ ty
3450
3435
}
3451
3436
hir:: ExprInlineAsm ( _, ref outputs, ref inputs) => {
3452
3437
for output in outputs {
@@ -3455,10 +3440,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3455
3440
for input in inputs {
3456
3441
self . check_expr ( input) ;
3457
3442
}
3458
- self . write_nil ( id )
3443
+ tcx . mk_nil ( )
3459
3444
}
3460
- hir:: ExprBreak ( _) => { self . write_never ( id ) }
3461
- hir:: ExprAgain ( _) => { self . write_never ( id ) }
3445
+ hir:: ExprBreak ( _) => { tcx . types . never }
3446
+ hir:: ExprAgain ( _) => { tcx . types . never }
3462
3447
hir:: ExprRet ( ref expr_opt) => {
3463
3448
if let Some ( ref e) = * expr_opt {
3464
3449
self . check_expr_coercable_to_type ( & e, self . ret_ty ) ;
@@ -3476,7 +3461,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3476
3461
. emit ( ) ;
3477
3462
}
3478
3463
}
3479
- self . write_never ( id )
3464
+ tcx . types . never
3480
3465
}
3481
3466
hir:: ExprAssign ( ref lhs, ref rhs) => {
3482
3467
let lhs_ty = self . check_expr_with_lvalue_pref ( & lhs, PreferMutLvalue ) ;
@@ -3497,55 +3482,49 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3497
3482
self . require_type_is_sized ( lhs_ty, lhs. span , traits:: AssignmentLhsSized ) ;
3498
3483
3499
3484
if lhs_ty. references_error ( ) || rhs_ty. references_error ( ) {
3500
- self . write_error ( id )
3485
+ tcx . types . err
3501
3486
} else {
3502
- self . write_nil ( id )
3487
+ tcx . mk_nil ( )
3503
3488
}
3504
3489
}
3505
3490
hir:: ExprIf ( ref cond, ref then_blk, ref opt_else_expr) => {
3506
- let if_ty = self . check_then_else ( & cond, & then_blk, opt_else_expr. as_ref ( ) . map ( |e| & * * e) ,
3507
- expr. span , expected) ;
3508
- self . write_ty ( id, if_ty)
3491
+ self . check_then_else ( & cond, & then_blk, opt_else_expr. as_ref ( ) . map ( |e| & * * e) ,
3492
+ expr. span , expected)
3509
3493
}
3510
3494
hir:: ExprWhile ( ref cond, ref body, _) => {
3511
3495
let cond_ty = self . check_expr_has_type ( & cond, tcx. types . bool ) ;
3512
3496
self . check_block_no_value ( & body) ;
3513
3497
let body_ty = self . node_ty ( body. id ) ;
3514
3498
if cond_ty. references_error ( ) || body_ty. references_error ( ) {
3515
- self . write_error ( id )
3499
+ tcx . types . err
3516
3500
}
3517
3501
else {
3518
- self . write_nil ( id )
3502
+ tcx . mk_nil ( )
3519
3503
}
3520
3504
}
3521
3505
hir:: ExprLoop ( ref body, _) => {
3522
3506
self . check_block_no_value ( & body) ;
3523
3507
if !may_break ( tcx, expr. id , & body) {
3524
- self . write_never ( id )
3508
+ tcx . types . never
3525
3509
} else {
3526
- self . write_nil ( id )
3510
+ tcx . mk_nil ( )
3527
3511
}
3528
3512
}
3529
3513
hir:: ExprMatch ( ref discrim, ref arms, match_src) => {
3530
- let result_ty = self . check_match ( expr, & discrim, arms, expected, match_src) ;
3531
- self . write_ty ( expr. id , result_ty)
3514
+ self . check_match ( expr, & discrim, arms, expected, match_src)
3532
3515
}
3533
3516
hir:: ExprClosure ( capture, ref decl, ref body, _) => {
3534
- let ty = self . check_expr_closure ( expr, capture, & decl, & body, expected) ;
3535
- self . write_ty ( id, ty)
3517
+ self . check_expr_closure ( expr, capture, & decl, & body, expected)
3536
3518
}
3537
3519
hir:: ExprBlock ( ref b) => {
3538
3520
self . check_block_with_expected ( & b, expected) ;
3539
- let ty = self . node_ty ( b. id ) ;
3540
- self . write_ty ( id, ty)
3521
+ self . node_ty ( b. id )
3541
3522
}
3542
3523
hir:: ExprCall ( ref callee, ref args) => {
3543
- let ret_ty = self . check_call ( expr, & callee, & args[ ..] , expected) ;
3544
- self . write_ty ( id, ret_ty)
3524
+ self . check_call ( expr, & callee, & args[ ..] , expected)
3545
3525
}
3546
3526
hir:: ExprMethodCall ( name, ref tps, ref args) => {
3547
- let ret_ty = self . check_method_call ( expr, name, & args[ ..] , & tps[ ..] , expected, lvalue_pref) ;
3548
- self . write_ty ( id, ret_ty)
3527
+ self . check_method_call ( expr, name, & args[ ..] , & tps[ ..] , expected, lvalue_pref)
3549
3528
}
3550
3529
hir:: ExprCast ( ref e, ref t) => {
3551
3530
if let hir:: TyFixedLengthVec ( _, ref count_expr) = t. node {
@@ -3561,25 +3540,25 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3561
3540
3562
3541
// Eagerly check for some obvious errors.
3563
3542
if t_expr. references_error ( ) || t_cast. references_error ( ) {
3564
- self . write_error ( id )
3543
+ tcx . types . err
3565
3544
} else {
3566
3545
// Defer other checks until we're done type checking.
3567
3546
let mut deferred_cast_checks = self . deferred_cast_checks . borrow_mut ( ) ;
3568
3547
match cast:: CastCheck :: new ( self , e, t_expr, t_cast, t. span , expr. span ) {
3569
3548
Ok ( cast_check) => {
3570
3549
deferred_cast_checks. push ( cast_check) ;
3571
- self . write_ty ( id , t_cast)
3550
+ t_cast
3572
3551
}
3573
3552
Err ( ErrorReported ) => {
3574
- self . write_error ( id )
3553
+ tcx . types . err
3575
3554
}
3576
3555
}
3577
3556
}
3578
3557
}
3579
3558
hir:: ExprType ( ref e, ref t) => {
3580
3559
let typ = self . to_ty ( & t) ;
3581
3560
self . check_expr_eq_type ( & e, typ) ;
3582
- self . write_ty ( id , typ)
3561
+ typ
3583
3562
}
3584
3563
hir:: ExprVec ( ref args) => {
3585
3564
let uty = expected. to_option ( self ) . and_then ( |uty| {
@@ -3611,7 +3590,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3611
3590
}
3612
3591
}
3613
3592
}
3614
- self . write_ty ( id , tcx. mk_array ( unified, args. len ( ) ) )
3593
+ tcx. mk_array ( unified, args. len ( ) )
3615
3594
}
3616
3595
hir:: ExprRepeat ( ref element, ref count_expr) => {
3617
3596
self . check_expr_has_type ( & count_expr, tcx. types . usize ) ;
@@ -3647,10 +3626,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3647
3626
}
3648
3627
3649
3628
if element_ty. references_error ( ) {
3650
- self . write_error ( id )
3629
+ tcx . types . err
3651
3630
} else {
3652
- let t = tcx. mk_array ( t, count) ;
3653
- self . write_ty ( id, t)
3631
+ tcx. mk_array ( t, count)
3654
3632
}
3655
3633
}
3656
3634
hir:: ExprTup ( ref elts) => {
@@ -3677,29 +3655,25 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3677
3655
t
3678
3656
} ) . collect ( ) ;
3679
3657
if err_field {
3680
- self . write_error ( id )
3658
+ tcx . types . err
3681
3659
} else {
3682
- let typ = tcx. mk_tup ( elt_ts) ;
3683
- self . write_ty ( id, typ)
3660
+ tcx. mk_tup ( elt_ts)
3684
3661
}
3685
3662
}
3686
3663
hir:: ExprStruct ( ref path, ref fields, ref base_expr) => {
3687
- let ty = self . check_expr_struct ( expr, path, fields, base_expr) ;
3688
- self . write_ty ( id, ty)
3664
+ self . check_expr_struct ( expr, path, fields, base_expr)
3689
3665
}
3690
3666
hir:: ExprField ( ref base, ref field) => {
3691
- let ty = self . check_field ( expr, lvalue_pref, & base, field) ;
3692
- self . write_ty ( id, ty)
3667
+ self . check_field ( expr, lvalue_pref, & base, field)
3693
3668
}
3694
3669
hir:: ExprTupField ( ref base, idx) => {
3695
- let ty = self . check_tup_field ( expr, lvalue_pref, & base, idx) ;
3696
- self . write_ty ( id, ty)
3670
+ self . check_tup_field ( expr, lvalue_pref, & base, idx)
3697
3671
}
3698
3672
hir:: ExprIndex ( ref base, ref idx) => {
3699
3673
let base_t = self . check_expr_with_lvalue_pref ( & base, lvalue_pref) ;
3700
3674
let idx_t = self . check_expr ( & idx) ;
3701
3675
3702
- let ty = if base_t. references_error ( ) {
3676
+ if base_t. references_error ( ) {
3703
3677
base_t
3704
3678
} else if idx_t. references_error ( ) {
3705
3679
idx_t
@@ -3747,16 +3721,26 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3747
3721
self . tcx ( ) . types . err
3748
3722
}
3749
3723
}
3750
- } ;
3751
- self . write_ty ( id, ty)
3724
+ }
3752
3725
}
3753
3726
} ;
3727
+ self . write_ty ( id, ty) ;
3754
3728
3755
3729
debug ! ( "type of expr({}) {} is..." , expr. id,
3756
3730
pprust:: expr_to_string( expr) ) ;
3757
3731
debug ! ( "... {:?}, expected is {:?}" ,
3758
3732
ty,
3759
3733
expected) ;
3734
+
3735
+ // Add adjustments to !-expressions
3736
+ if ty. is_never ( ) {
3737
+ if let Some ( hir:: map:: NodeExpr ( _) ) = self . tcx . map . find ( id) {
3738
+ let adj_ty = self . next_diverging_ty_var ( ) ;
3739
+ let adj = adjustment:: AdjustNeverToAny ( adj_ty) ;
3740
+ self . write_adjustment ( id, adj) ;
3741
+ return adj_ty;
3742
+ }
3743
+ }
3760
3744
ty
3761
3745
}
3762
3746
0 commit comments