@@ -31,9 +31,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3131        error :  TypeError < ' tcx > , 
3232    )  { 
3333        self . annotate_expected_due_to_let_ty ( err,  expr,  error) ; 
34-         self . suggest_box_deref ( err,  expr,  expected,  expr_ty) ; 
35-         self . suggest_compatible_variants ( err,  expr,  expected,  expr_ty) ; 
3634        self . suggest_deref_ref_or_into ( err,  expr,  expected,  expr_ty,  expected_ty_expr) ; 
35+         self . suggest_compatible_variants ( err,  expr,  expected,  expr_ty) ; 
3736        if  self . suggest_calling_boxed_future_when_appropriate ( err,  expr,  expected,  expr_ty)  { 
3837            return ; 
3938        } 
@@ -259,23 +258,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
259258        } 
260259    } 
261260
262-     fn  suggest_box_deref ( 
263-         & self , 
264-         err :  & mut  DiagnosticBuilder < ' _ > , 
265-         expr :  & hir:: Expr < ' _ > , 
266-         expected :  Ty < ' tcx > , 
267-         expr_ty :  Ty < ' tcx > , 
268-     )  { 
269-         if  expr_ty. is_box ( )  && expr_ty. boxed_ty ( )  == expected { 
270-             err. span_suggestion_verbose ( 
271-                 expr. span . shrink_to_lo ( ) , 
272-                 "try dereferencing the `Box`" , 
273-                 "*" . to_string ( ) , 
274-                 Applicability :: MachineApplicable , 
275-             ) ; 
276-         } 
277-     } 
278- 
279261    /// If the expected type is an enum (Issue #55250) with any variants whose 
280262/// sole field is of the found type, suggest such variants. (Issue #42764) 
281263fn  suggest_compatible_variants ( 
@@ -857,14 +839,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
857839                                Applicability :: MachineApplicable , 
858840                                false , 
859841                            ) ) ; 
860-                         }  else  if  self . infcx . type_is_copy_modulo_regions ( 
861-                             self . param_env , 
862-                             expected, 
863-                             sp, 
864-                         )  { 
865-                             // For this suggestion to make sense, the type would need to be `Copy`. 
842+                         } 
843+ 
844+                         // For this suggestion to make sense, the type would need to be `Copy`, 
845+                         // or we have to be moving out of a `Box<T>` 
846+                         if  self . infcx . type_is_copy_modulo_regions ( self . param_env ,  expected,  sp) 
847+                             || checked_ty. is_box ( ) 
848+                         { 
866849                            if  let  Ok ( code)  = sm. span_to_snippet ( expr. span )  { 
867-                                 let  message = if  checked_ty. is_region_ptr ( )  { 
850+                                 let  message = if  checked_ty. is_box ( )  { 
851+                                     "consider unboxing the value" 
852+                                 }  else  if  checked_ty. is_region_ptr ( )  { 
868853                                    "consider dereferencing the borrow" 
869854                                }  else  { 
870855                                    "consider dereferencing the type" 
0 commit comments