about summary refs log tree commit diff
path: root/compiler/rustc_infer/src/infer
diff options
context:
space:
mode:
authorIQuant <quant3234@gmail.com>2023-03-03 17:49:51 +0300
committerIQuant <quant3234@gmail.com>2023-04-04 18:34:50 +0300
commit23b8567a78bd3899dd963e83ed2d698c044c877f (patch)
tree7b71b559b985d5c44df2d5ea26504a6b40ddaf12 /compiler/rustc_infer/src/infer
parentd56b304bc8bd603d5f4298793f33f1cbb6c9d0d1 (diff)
downloadrust-23b8567a78bd3899dd963e83ed2d698c044c877f.tar.gz
rust-23b8567a78bd3899dd963e83ed2d698c044c877f.zip
Migrate SuggestBoxingForReturnImplTrait, Fix typo in infer_fn_consider_casting
Diffstat (limited to 'compiler/rustc_infer/src/infer')
-rw-r--r--compiler/rustc_infer/src/infer/error_reporting/suggest.rs36
1 files changed, 16 insertions, 20 deletions
diff --git a/compiler/rustc_infer/src/infer/error_reporting/suggest.rs b/compiler/rustc_infer/src/infer/error_reporting/suggest.rs
index 88d7cab0e4c..82ee365f3a0 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/suggest.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/suggest.rs
@@ -15,7 +15,8 @@ use rustc_target::abi::FieldIdx;
 use crate::errors::{
     ConsiderAddingAwait, DiagArg, FnConsiderCasting, FnItemsAreDistinct, FnUniqTypes,
     FunctionPointerSuggestion, SuggAddLetForLetChains, SuggestAccessingField,
-    SuggestAsRefWhereAppropriate, SuggestRemoveSemiOrReturnBinding,
+    SuggestAsRefWhereAppropriate, SuggestBoxingForReturnImplTrait,
+    SuggestRemoveSemiOrReturnBinding,
 };
 
 use super::TypeErrCtxt;
@@ -80,25 +81,20 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
         return_sp: Span,
         arm_spans: impl Iterator<Item = Span>,
     ) {
-        err.multipart_suggestion(
-            "you could change the return type to be a boxed trait object",
-            vec![
-                (return_sp.with_hi(return_sp.lo() + BytePos(4)), "Box<dyn".to_string()),
-                (return_sp.shrink_to_hi(), ">".to_string()),
-            ],
-            Applicability::MaybeIncorrect,
-        );
-        let sugg = arm_spans
-            .flat_map(|sp| {
-                [(sp.shrink_to_lo(), "Box::new(".to_string()), (sp.shrink_to_hi(), ")".to_string())]
-                    .into_iter()
-            })
-            .collect::<Vec<_>>();
-        err.multipart_suggestion(
-            "if you change the return type to expect trait objects, box the returned expressions",
-            sugg,
-            Applicability::MaybeIncorrect,
-        );
+        let sugg = SuggestBoxingForReturnImplTrait::ChangeReturnType {
+            start_sp: return_sp.with_hi(return_sp.lo() + BytePos(4)),
+            end_sp: return_sp.shrink_to_hi(),
+        };
+        err.subdiagnostic(sugg);
+
+        let mut starts = Vec::new();
+        let mut ends = Vec::new();
+        for span in arm_spans {
+            starts.push(span.shrink_to_lo());
+            ends.push(span.shrink_to_hi());
+        }
+        let sugg = SuggestBoxingForReturnImplTrait::BoxReturnExpr { starts, ends };
+        err.subdiagnostic(sugg);
     }
 
     pub(super) fn suggest_tuple_pattern(