@@ -84,7 +84,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8484
8585 self . annotate_expected_due_to_let_ty ( err, expr, error) ;
8686 self . annotate_loop_expected_due_to_inference ( err, expr, error) ;
87- if self . annotate_mut_binding_to_immutable_binding ( err, expr, error) {
87+ if self . annotate_mut_binding_to_immutable_binding ( err, expr, expr_ty , expected , error) {
8888 return ;
8989 }
9090
@@ -799,17 +799,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
799799 /// Detect the following case
800800 ///
801801 /// ```text
802- /// fn change_object(mut a : &Ty) {
802+ /// fn change_object(mut b : &Ty) {
803803 /// let a = Ty::new();
804804 /// b = a;
805805 /// }
806806 /// ```
807807 ///
808- /// where the user likely meant to modify the value behind there reference, use `a ` as an out
808+ /// where the user likely meant to modify the value behind there reference, use `b ` as an out
809809 /// parameter, instead of mutating the local binding. When encountering this we suggest:
810810 ///
811811 /// ```text
812- /// fn change_object(a : &'_ mut Ty) {
812+ /// fn change_object(b : &'_ mut Ty) {
813813 /// let a = Ty::new();
814814 /// *b = a;
815815 /// }
@@ -818,13 +818,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
818818 & self ,
819819 err : & mut Diag < ' _ > ,
820820 expr : & hir:: Expr < ' _ > ,
821+ expr_ty : Ty < ' tcx > ,
822+ expected : Ty < ' tcx > ,
821823 error : Option < TypeError < ' tcx > > ,
822824 ) -> bool {
823- if let Some ( TypeError :: Sorts ( ExpectedFound { expected , found } ) ) = error
825+ if let Some ( TypeError :: Sorts ( ExpectedFound { .. } ) ) = error
824826 && let ty:: Ref ( _, inner, hir:: Mutability :: Not ) = expected. kind ( )
825827
826828 // The difference between the expected and found values is one level of borrowing.
827- && self . can_eq ( self . param_env , * inner, found )
829+ && self . can_eq ( self . param_env , * inner, expr_ty )
828830
829831 // We have an `ident = expr;` assignment.
830832 && let hir:: Node :: Expr ( hir:: Expr { kind : hir:: ExprKind :: Assign ( lhs, rhs, _) , .. } ) =
0 commit comments