@@ -31,9 +31,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
31
31
error : TypeError < ' tcx > ,
32
32
) {
33
33
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) ;
36
34
self . suggest_deref_ref_or_into ( err, expr, expected, expr_ty, expected_ty_expr) ;
35
+ self . suggest_compatible_variants ( err, expr, expected, expr_ty) ;
37
36
if self . suggest_calling_boxed_future_when_appropriate ( err, expr, expected, expr_ty) {
38
37
return ;
39
38
}
@@ -259,23 +258,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
259
258
}
260
259
}
261
260
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
-
279
261
/// If the expected type is an enum (Issue #55250) with any variants whose
280
262
/// sole field is of the found type, suggest such variants. (Issue #42764)
281
263
fn suggest_compatible_variants (
@@ -857,14 +839,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
857
839
Applicability :: MachineApplicable ,
858
840
false ,
859
841
) ) ;
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
+ {
866
849
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 ( ) {
868
853
"consider dereferencing the borrow"
869
854
} else {
870
855
"consider dereferencing the type"
0 commit comments