From af75ebdc3a4d01c62ae1af96931f6fa1b188b698 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 21 May 2018 18:06:28 +0200 Subject: Improve the diagnostic around impl Trait <-> generic param mismatch --- src/librustc_errors/diagnostic.rs | 19 +++++++++++++++++++ src/librustc_errors/diagnostic_builder.rs | 5 +++++ 2 files changed, 24 insertions(+) (limited to 'src/librustc_errors') diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs index 75401f21862..81b32f436c8 100644 --- a/src/librustc_errors/diagnostic.rs +++ b/src/librustc_errors/diagnostic.rs @@ -259,6 +259,25 @@ impl Diagnostic { self } + pub fn multipart_suggestion( + &mut self, + msg: &str, + suggestion: Vec<(Span, String)>, + ) -> &mut Self { + self.suggestions.push(CodeSuggestion { + substitutions: vec![Substitution { + parts: suggestion + .into_iter() + .map(|(span, snippet)| SubstitutionPart { snippet, span }) + .collect(), + }], + msg: msg.to_owned(), + show_code_when_inline: true, + applicability: Applicability::Unspecified, + }); + self + } + /// Prints out a message with multiple suggested edits of the code. pub fn span_suggestions(&mut self, sp: Span, msg: &str, suggestions: Vec) -> &mut Self { self.suggestions.push(CodeSuggestion { diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs index 7e9ca8633a5..b813edadc57 100644 --- a/src/librustc_errors/diagnostic_builder.rs +++ b/src/librustc_errors/diagnostic_builder.rs @@ -178,6 +178,11 @@ impl<'a> DiagnosticBuilder<'a> { msg: &str, suggestion: String) -> &mut Self); + forward!(pub fn multipart_suggestion( + &mut self, + msg: &str, + suggestion: Vec<(Span, String)> + ) -> &mut Self); forward!(pub fn span_suggestion(&mut self, sp: Span, msg: &str, -- cgit 1.4.1-3-g733a5