proc_macro: don't use DiagnosticBuilder for building up Diagnostics.

This commit is contained in:
Eduard-Mihai Burtescu 2018-04-21 21:33:20 +03:00
parent 11864c4e6c
commit c0adb05d34
2 changed files with 24 additions and 28 deletions

View File

@ -10,7 +10,8 @@
use Span;
use rustc_errors as rustc;
use rustc_errors as errors;
use syntax_pos::MultiSpan;
/// An enum representing a diagnostic level.
#[unstable(feature = "proc_macro_diagnostic", issue = "38356")]
@ -97,37 +98,32 @@ impl Diagnostic {
/// Emit the diagnostic.
#[unstable(feature = "proc_macro_diagnostic", issue = "38356")]
pub fn emit(self) {
let level = self.level.to_internal();
let mut diag = errors::Diagnostic::new(level, &*self.message);
if let Some(span) = self.span {
diag.set_span(span.0);
}
for child in self.children {
let span = child.span.map_or(MultiSpan::new(), |s| s.0.into());
let level = child.level.to_internal();
diag.sub(level, &*child.message, span, None);
}
::__internal::with_sess(move |sess, _| {
let handler = &sess.span_diagnostic;
let level = __internal::level_to_internal_level(self.level);
let mut diag = rustc::DiagnosticBuilder::new(handler, level, &*self.message);
if let Some(span) = self.span {
diag.set_span(span.0);
}
for child in self.children {
let span = child.span.map(|s| s.0);
let level = __internal::level_to_internal_level(child.level);
diag.sub(level, &*child.message, span);
}
diag.emit();
errors::DiagnosticBuilder::new_diagnostic(&sess.span_diagnostic, diag).emit();
});
}
}
#[unstable(feature = "proc_macro_internals", issue = "27812")]
#[doc(hidden)]
pub mod __internal {
use super::{Level, rustc};
pub fn level_to_internal_level(level: Level) -> rustc::Level {
match level {
Level::Error => rustc::Level::Error,
Level::Warning => rustc::Level::Warning,
Level::Note => rustc::Level::Note,
Level::Help => rustc::Level::Help,
impl Level {
fn to_internal(self) -> errors::Level {
match self {
Level::Error => errors::Level::Error,
Level::Warning => errors::Level::Warning,
Level::Note => errors::Level::Note,
Level::Help => errors::Level::Help,
Level::__Nonexhaustive => unreachable!("Level::__Nonexhaustive")
}
}

View File

@ -379,7 +379,7 @@ impl Diagnostic {
/// Convenience function for internal use, clients should use one of the
/// public methods above.
pub(crate) fn sub(&mut self,
pub fn sub(&mut self,
level: Level,
message: &str,
span: MultiSpan,