about summary refs log tree commit diff
path: root/src/librustc_errors/diagnostic.rs
diff options
context:
space:
mode:
authorMathias Blikstad <mathias@blikstad.se>2019-01-08 22:14:04 +0100
committerNiko Matsakis <niko@alum.mit.edu>2019-10-22 15:24:33 -0400
commitef5acdecebb48a02cb34d19fa17d1bd59e41a4d3 (patch)
treecb6e20d78485549efc93763e17677eefe09ab6fc /src/librustc_errors/diagnostic.rs
parentd28a9c38fe14396e86ae274c7847e20ee0f78ca9 (diff)
RFC 2027: "first draft" of implementation
These are a squashed series of commits.
Diffstat (limited to 'src/librustc_errors/diagnostic.rs')
-rw-r--r--src/librustc_errors/diagnostic.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs
index fd74d8673da..1781f2e1650 100644
--- a/src/librustc_errors/diagnostic.rs
+++ b/src/librustc_errors/diagnostic.rs
@@ -152,6 +152,32 @@ impl Diagnostic {
         self.note_expected_found_extra(label, expected, found, &"", &"")
     }
 
+    pub fn note_unsuccessfull_coercion(&mut self,
+                                       expected: DiagnosticStyledString,
+                                       found: DiagnosticStyledString)
+                                       -> &mut Self
+    {
+        let mut msg: Vec<_> =
+            vec![(format!("required when trying to coerce from type `"),
+                  Style::NoStyle)];
+        msg.extend(expected.0.iter()
+                   .map(|x| match *x {
+                       StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
+                       StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
+                   }));
+        msg.push((format!("` to type '"), Style::NoStyle));
+        msg.extend(found.0.iter()
+                   .map(|x| match *x {
+                       StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
+                       StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
+                   }));
+        msg.push((format!("`"), Style::NoStyle));
+
+        // For now, just attach these as notes
+        self.highlighted_note(msg);
+        self
+    }
+
     pub fn note_expected_found_extra(&mut self,
                                      label: &dyn fmt::Display,
                                      expected: DiagnosticStyledString,