@@ -60,28 +60,13 @@ use rustc_trait_selection::traits::ObligationCtxt;
60
60
use rustc_trait_selection:: traits:: { self , ObligationCauseCode } ;
61
61
62
62
impl < ' a , ' tcx > FnCtxt < ' a , ' tcx > {
63
- fn check_expr_eq_type ( & self , expr : & ' tcx hir:: Expr < ' tcx > , expected : Ty < ' tcx > ) {
64
- let ty = self . check_expr_with_hint ( expr, expected) ;
65
- self . demand_eqtype ( expr. span , expected, ty) ;
66
- }
67
-
68
63
pub fn check_expr_has_type_or_error (
69
64
& self ,
70
65
expr : & ' tcx hir:: Expr < ' tcx > ,
71
- expected : Ty < ' tcx > ,
72
- extend_err : impl FnMut ( & mut Diagnostic ) ,
73
- ) -> Ty < ' tcx > {
74
- self . check_expr_meets_expectation_or_error ( expr, ExpectHasType ( expected) , extend_err)
75
- }
76
-
77
- fn check_expr_meets_expectation_or_error (
78
- & self ,
79
- expr : & ' tcx hir:: Expr < ' tcx > ,
80
- expected : Expectation < ' tcx > ,
81
- mut extend_err : impl FnMut ( & mut Diagnostic ) ,
66
+ expected_ty : Ty < ' tcx > ,
67
+ extend_err : impl FnOnce ( & mut Diagnostic ) ,
82
68
) -> Ty < ' tcx > {
83
- let expected_ty = expected. to_option ( & self ) . unwrap_or ( self . tcx . types . bool ) ;
84
- let mut ty = self . check_expr_with_expectation ( expr, expected) ;
69
+ let mut ty = self . check_expr_with_expectation ( expr, ExpectHasType ( expected_ty) ) ;
85
70
86
71
// While we don't allow *arbitrary* coercions here, we *do* allow
87
72
// coercions from ! to `expected`.
@@ -341,9 +326,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
341
326
}
342
327
ExprKind :: Cast ( e, t) => self . check_expr_cast ( e, t, expr) ,
343
328
ExprKind :: Type ( e, t) => {
344
- let ty = self . to_ty_saving_user_provided_ty ( & t) ;
345
- self . check_expr_eq_type ( & e, ty) ;
346
- ty
329
+ let ascribed_ty = self . to_ty_saving_user_provided_ty ( & t) ;
330
+ let ty = self . check_expr_with_hint ( e, ascribed_ty) ;
331
+ self . demand_eqtype ( e. span , ascribed_ty, ty) ;
332
+ ascribed_ty
347
333
}
348
334
ExprKind :: If ( cond, then_expr, opt_else_expr) => {
349
335
self . check_then_else ( cond, then_expr, opt_else_expr, expr. span , expected)
@@ -666,7 +652,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
666
652
coerce. coerce_forced_unit (
667
653
self ,
668
654
& cause,
669
- & mut |mut err| {
655
+ |mut err| {
670
656
self . suggest_mismatched_types_on_tail (
671
657
& mut err, expr, ty, e_ty, target_id,
672
658
) ;
@@ -762,7 +748,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
762
748
coercion. coerce_forced_unit (
763
749
self ,
764
750
& cause,
765
- & mut |db| {
751
+ |db| {
766
752
let span = fn_decl. output . span ( ) ;
767
753
if let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( span) {
768
754
db. span_label (
@@ -774,7 +760,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
774
760
true ,
775
761
) ;
776
762
} else {
777
- coercion. coerce_forced_unit ( self , & cause, & mut |_| ( ) , true ) ;
763
+ coercion. coerce_forced_unit ( self , & cause, |_| ( ) , true ) ;
778
764
}
779
765
}
780
766
self . tcx . types . never
0 commit comments