about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-02-09 03:39:08 -0800
committerEsteban Küber <esteban@kuber.com.ar>2019-02-11 10:01:40 -0800
commit235523c7d4acdbd38a6b31c53b7969475d460e97 (patch)
tree54fcf53733dfd37887858b66667d4c586be0ac39
parent7cfba1c5e807821095c7b874c92bf4a11674be36 (diff)
downloadrust-235523c7d4acdbd38a6b31c53b7969475d460e97.tar.gz
rust-235523c7d4acdbd38a6b31c53b7969475d460e97.zip
Add way to completely hide suggestion from cli output
-rw-r--r--src/librustc_errors/diagnostic.rs21
-rw-r--r--src/librustc_errors/diagnostic_builder.rs19
-rw-r--r--src/librustc_errors/emitter.rs4
-rw-r--r--src/librustc_errors/lib.rs6
4 files changed, 47 insertions, 3 deletions
diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs
index 8394e66850e..588cdfcb1af 100644
--- a/src/librustc_errors/diagnostic.rs
+++ b/src/librustc_errors/diagnostic.rs
@@ -346,6 +346,27 @@ impl Diagnostic {
         self
     }
 
+    /// Adds a suggestion to the json output, but otherwise remains silent/undisplayed in the cli.
+    ///
+    /// This is intended to be used for suggestions that are *very* obvious in what the changes
+    /// need to be from the message, but we still want other tools to be able to apply them.
+    pub fn tool_only_span_suggestion(
+        &mut self, sp: Span, msg: &str, suggestion: String, applicability: Applicability
+    ) -> &mut Self {
+        self.suggestions.push(CodeSuggestion {
+            substitutions: vec![Substitution {
+                parts: vec![SubstitutionPart {
+                    snippet: suggestion,
+                    span: sp,
+                }],
+            }],
+            msg: msg.to_owned(),
+            style: SuggestionStyle::CompletelyHidden,
+            applicability: applicability,
+        });
+        self
+    }
+
     pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self {
         self.span = sp.into();
         self
diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs
index 5b37a7bb346..9f838987f0c 100644
--- a/src/librustc_errors/diagnostic_builder.rs
+++ b/src/librustc_errors/diagnostic_builder.rs
@@ -281,6 +281,25 @@ impl<'a> DiagnosticBuilder<'a> {
         self
     }
 
+    pub fn tool_only_span_suggestion(
+        &mut self,
+        sp: Span,
+        msg: &str,
+        suggestion: String,
+        applicability: Applicability,
+    ) -> &mut Self {
+        if !self.allow_suggestions {
+            return self
+        }
+        self.diagnostic.tool_only_span_suggestion(
+            sp,
+            msg,
+            suggestion,
+            applicability,
+        );
+        self
+    }
+
     forward!(pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self);
     forward!(pub fn code(&mut self, s: DiagnosticId) -> &mut Self);
 
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs
index 6e411960998..5e7c5315d68 100644
--- a/src/librustc_errors/emitter.rs
+++ b/src/librustc_errors/emitter.rs
@@ -1363,7 +1363,9 @@ impl EmitterWriter {
                         }
                     }
                     for sugg in suggestions {
-                        if sugg.style == SuggestionStyle::HideCodeAlways {
+                        if sugg.style == SuggestionStyle::CompletelyHidden {
+                            // do not display this suggestion, it is meant only for tools
+                        } else if sugg.style == SuggestionStyle::HideCodeAlways {
                             match self.emit_message_default(
                                 &MultiSpan::new(),
                                 &[(sugg.msg.to_owned(), Style::HeaderMsg)],
diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs
index be959a29a55..7805bf697c6 100644
--- a/src/librustc_errors/lib.rs
+++ b/src/librustc_errors/lib.rs
@@ -72,8 +72,10 @@ pub enum Applicability {
 pub enum SuggestionStyle {
     /// Hide the suggested code when displaying this suggestion inline.
     HideCodeInline,
-    /// Always hide the suggested code.
+    /// Always hide the suggested code but display the message.
     HideCodeAlways,
+    /// Do not display this suggestion in the cli output, it is only meant for tools.
+    CompletelyHidden,
     /// Always show the suggested code.
     /// This will *not* show the code if the suggestion is inline *and* the suggested code is
     /// empty.
@@ -83,8 +85,8 @@ pub enum SuggestionStyle {
 impl SuggestionStyle {
     fn hide_inline(&self) -> bool {
         match *self {
-            SuggestionStyle::HideCodeAlways | SuggestionStyle::HideCodeInline => true,
             SuggestionStyle::ShowCode => false,
+            _ => true,
         }
     }
 }