]> git.lizzy.rs Git - rust.git/commitdiff
introducing `span_suggestion_short_with_applicability`
authorZack M. Davis <code@zackmdavis.net>
Sun, 13 May 2018 03:44:50 +0000 (20:44 -0700)
committerZack M. Davis <code@zackmdavis.net>
Sun, 20 May 2018 19:57:19 +0000 (12:57 -0700)
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.

src/librustc_errors/diagnostic.rs
src/librustc_errors/diagnostic_builder.rs

index 75401f21862b67a683b9fab3450f082061d77432..bb2badaf293b6a41a5e7b112b14bf0df846804d3 100644 (file)
@@ -311,6 +311,23 @@ pub fn span_suggestions_with_applicability(&mut self, sp: Span, msg: &str,
         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
index 7e9ca8633a53e4ea119fb8a0832cccae45c19137..41c3f7ce841e3a0d8c2a37354c844026512b284d 100644 (file)
@@ -200,6 +200,12 @@ pub fn span_label<T: Into<String>>(&mut self, span: Span, label: T) -> &mut Self
                                                  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);