From 8be132e9d76232feb2376de9edcbb34fe3ac99ac Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Mon, 28 Aug 2017 02:56:43 -0700 Subject: Initial diagnostic API for proc-macros. This commit introduces the ability to create and emit `Diagnostic` structures from proc-macros, allowing for proc-macro authors to emit warning, error, note, and help messages just like the compiler does. --- src/librustc_errors/diagnostic_builder.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/librustc_errors/diagnostic_builder.rs') diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs index 2c8d8b4691f..2cd433bfe3a 100644 --- a/src/librustc_errors/diagnostic_builder.rs +++ b/src/librustc_errors/diagnostic_builder.rs @@ -110,6 +110,19 @@ impl<'a> DiagnosticBuilder<'a> { // } } + /// Convenience function for internal use, clients should use one of the + /// span_* methods instead. + pub fn sub>( + &mut self, + level: Level, + message: &str, + span: Option, + ) -> &mut Self { + let span = span.map(|s| s.into()).unwrap_or(MultiSpan::new()); + self.diagnostic.sub(level, message, span, None); + self + } + /// Delay emission of this diagnostic as a bug. /// /// This can be useful in contexts where an error indicates a bug but -- cgit 1.4.1-3-g733a5