@@ -836,6 +836,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
836836 lhs : & ' tcx hir:: Expr < ' tcx > ,
837837 err_code : & ' static str ,
838838 op_span : Span ,
839+ adjust_err : impl FnOnce ( & mut DiagnosticBuilder < ' tcx , ErrorGuaranteed > ) ,
839840 ) {
840841 if lhs. is_syntactic_place_expr ( ) {
841842 return ;
@@ -858,6 +859,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
858859 ) ;
859860 } ) ;
860861
862+ adjust_err ( & mut err) ;
863+
861864 err. emit ( ) ;
862865 }
863866
@@ -1050,9 +1053,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10501053 return self . tcx . ty_error ( ) ;
10511054 }
10521055
1053- self . check_lhs_assignable ( lhs, "E0070" , span) ;
1054-
10551056 let lhs_ty = self . check_expr_with_needs ( & lhs, Needs :: MutPlace ) ;
1057+
1058+ self . check_lhs_assignable ( lhs, "E0070" , span, |err| {
1059+ let rhs_ty = self . check_expr ( & rhs) ;
1060+
1061+ if let ty:: Ref ( _, lhs_inner_ty, hir:: Mutability :: Mut ) = lhs_ty. kind ( ) {
1062+ if self . can_coerce ( rhs_ty, * lhs_inner_ty) {
1063+ err. span_suggestion_verbose (
1064+ lhs. span . shrink_to_lo ( ) ,
1065+ "consider dereferencing here to assign to the mutable \
1066+ borrowed piece of memory",
1067+ "*" . to_string ( ) ,
1068+ Applicability :: MachineApplicable ,
1069+ ) ;
1070+ }
1071+ }
1072+ } ) ;
1073+
10561074 let rhs_ty = self . check_expr_coercable_to_type ( & rhs, lhs_ty, Some ( lhs) ) ;
10571075
10581076 self . require_type_is_sized ( lhs_ty, lhs. span , traits:: AssignmentLhsSized ) ;
0 commit comments