]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_errors/diagnostic.rs
Rollup merge of #58296 - estebank:hidden-suggestion, r=oli-obk
[rust.git] / src / librustc_errors / diagnostic.rs
index 588cdfcb1afff606b0a084f57d2276054137fa23..851b19e8177b53917f37cf4a9bcab637fb5f2abe 100644 (file)
@@ -119,7 +119,7 @@ pub fn cancelled(&self) -> bool {
         self.level == Level::Cancelled
     }
 
-    /// Add a span/label to be included in the resulting snippet.
+    /// Adds a span/label to be included in the resulting snippet.
     /// This is pushed onto the `MultiSpan` that was created when the
     /// diagnostic was first built. If you don't call this function at
     /// all, and you just supplied a `Span` to create the diagnostic,
@@ -250,6 +250,32 @@ pub fn multipart_suggestion(
         self
     }
 
+    /// Prints out a message with for a multipart suggestion without showing the suggested code.
+    ///
+    /// This is intended to be used for suggestions that are obvious in what the changes need to
+    /// be from the message, showing the span label inline would be visually unpleasant
+    /// (marginally overlapping spans or multiline spans) and showing the snippet window wouldn't
+    /// improve understandability.
+    pub fn tool_only_multipart_suggestion(
+        &mut self,
+        msg: &str,
+        suggestion: Vec<(Span, String)>,
+        applicability: Applicability,
+    ) -> &mut Self {
+        self.suggestions.push(CodeSuggestion {
+            substitutions: vec![Substitution {
+                parts: suggestion
+                    .into_iter()
+                    .map(|(span, snippet)| SubstitutionPart { snippet, span })
+                    .collect(),
+            }],
+            msg: msg.to_owned(),
+            style: SuggestionStyle::CompletelyHidden,
+            applicability,
+        });
+        self
+    }
+
     /// Prints out a message with a suggested edit of the code.
     ///
     /// In case of short messages and a simple suggestion, rustc displays it as a label:
@@ -318,7 +344,7 @@ pub fn span_suggestion_short(
             }],
             msg: msg.to_owned(),
             style: SuggestionStyle::HideCodeInline,
-            applicability: applicability,
+            applicability,
         });
         self
     }
@@ -341,7 +367,7 @@ pub fn span_suggestion_hidden(
             }],
             msg: msg.to_owned(),
             style: SuggestionStyle::HideCodeInline,
-            applicability: applicability,
+            applicability,
         });
         self
     }