diff options
| author | Sergio Benitez <sb@sergio.bz> | 2017-08-28 02:56:43 -0700 |
|---|---|---|
| committer | Sergio Benitez <sb@sergio.bz> | 2017-08-28 02:58:22 -0700 |
| commit | 8be132e9d76232feb2376de9edcbb34fe3ac99ac (patch) | |
| tree | e1cdbc4e0e9e64151a896c49af2d52fae00d48a8 /src/librustc_errors | |
| parent | a0c3bd2d23f6d08ecf9b4191ee4fff5866a120d1 (diff) | |
| download | rust-8be132e9d76232feb2376de9edcbb34fe3ac99ac.tar.gz rust-8be132e9d76232feb2376de9edcbb34fe3ac99ac.zip | |
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.
Diffstat (limited to 'src/librustc_errors')
| -rw-r--r-- | src/librustc_errors/diagnostic.rs | 2 | ||||
| -rw-r--r-- | src/librustc_errors/diagnostic_builder.rs | 13 |
2 files changed, 14 insertions, 1 deletions
diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs index 0f063542383..9aae188f9ec 100644 --- a/src/librustc_errors/diagnostic.rs +++ b/src/librustc_errors/diagnostic.rs @@ -288,7 +288,7 @@ impl Diagnostic { /// Convenience function for internal use, clients should use one of the /// public methods above. - fn sub(&mut self, + pub(crate) fn sub(&mut self, level: Level, message: &str, span: MultiSpan, 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<S: Into<MultiSpan>>( + &mut self, + level: Level, + message: &str, + span: Option<S>, + ) -> &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 |
