summary refs log tree commit diff
path: root/src/librustc_errors
diff options
context:
space:
mode:
authorZack M. Davis <code@zackmdavis.net>2018-05-12 20:44:50 -0700
committerZack M. Davis <code@zackmdavis.net>2018-05-20 12:57:19 -0700
commit6bb4aad51f40536447cd7603ab5be7792bab0a3d (patch)
tree4ea5459b0377e8d8c4b64a3a1eb700806553608b /src/librustc_errors
parentb4384491615e2159653207b74760643b507d12f8 (diff)
downloadrust-6bb4aad51f40536447cd7603ab5be7792bab0a3d.tar.gz
rust-6bb4aad51f40536447cd7603ab5be7792bab0a3d.zip
introducing `span_suggestion_short_with_applicability`
Some would argue that this 40-character method name is ludicrously
unwieldy (even ironic), but it's the unique continuation of the
precedent set by the other suggestion methods. (And there is some hope
that someday we'll just fold `Applicability` into the signature of the
"basic" method `span_suggestion`.)

This is in support of #50723.
Diffstat (limited to 'src/librustc_errors')
-rw-r--r--src/librustc_errors/diagnostic.rs17
-rw-r--r--src/librustc_errors/diagnostic_builder.rs6
2 files changed, 23 insertions, 0 deletions
diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs
index 75401f21862..bb2badaf293 100644
--- a/src/librustc_errors/diagnostic.rs
+++ b/src/librustc_errors/diagnostic.rs
@@ -311,6 +311,23 @@ impl Diagnostic {
         self
     }
 
+    pub fn span_suggestion_short_with_applicability(
+        &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(),
+            show_code_when_inline: false,
+            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 7e9ca8633a5..41c3f7ce841 100644
--- a/src/librustc_errors/diagnostic_builder.rs
+++ b/src/librustc_errors/diagnostic_builder.rs
@@ -200,6 +200,12 @@ impl<'a> DiagnosticBuilder<'a> {
                                                  suggestions: Vec<String>,
                                                  applicability: Applicability)
                                                  -> &mut Self);
+    forward!(pub fn span_suggestion_short_with_applicability(&mut self,
+                                                             sp: Span,
+                                                             msg: &str,
+                                                             suggestion: String,
+                                                             applicability: Applicability)
+                                                             -> &mut 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);