@@ -84,7 +84,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
84
84
85
85
self . annotate_expected_due_to_let_ty ( err, expr, error) ;
86
86
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) {
88
88
return ;
89
89
}
90
90
@@ -799,17 +799,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
799
799
/// Detect the following case
800
800
///
801
801
/// ```text
802
- /// fn change_object(mut a : &Ty) {
802
+ /// fn change_object(mut b : &Ty) {
803
803
/// let a = Ty::new();
804
804
/// b = a;
805
805
/// }
806
806
/// ```
807
807
///
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
809
809
/// parameter, instead of mutating the local binding. When encountering this we suggest:
810
810
///
811
811
/// ```text
812
- /// fn change_object(a : &'_ mut Ty) {
812
+ /// fn change_object(b : &'_ mut Ty) {
813
813
/// let a = Ty::new();
814
814
/// *b = a;
815
815
/// }
@@ -818,13 +818,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
818
818
& self ,
819
819
err : & mut Diag < ' _ > ,
820
820
expr : & hir:: Expr < ' _ > ,
821
+ expr_ty : Ty < ' tcx > ,
822
+ expected : Ty < ' tcx > ,
821
823
error : Option < TypeError < ' tcx > > ,
822
824
) -> bool {
823
- if let Some ( TypeError :: Sorts ( ExpectedFound { expected , found } ) ) = error
825
+ if let Some ( TypeError :: Sorts ( ExpectedFound { .. } ) ) = error
824
826
&& let ty:: Ref ( _, inner, hir:: Mutability :: Not ) = expected. kind ( )
825
827
826
828
// 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 )
828
830
829
831
// We have an `ident = expr;` assignment.
830
832
&& let hir:: Node :: Expr ( hir:: Expr { kind : hir:: ExprKind :: Assign ( lhs, rhs, _) , .. } ) =
0 commit comments