Skip to content

Commit c0adb05

Browse files
committed
proc_macro: don't use DiagnosticBuilder for building up Diagnostics.
1 parent 11864c4 commit c0adb05

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

src/libproc_macro/diagnostic.rs

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
use Span;
1212

13-
use rustc_errors as rustc;
13+
use rustc_errors as errors;
14+
use syntax_pos::MultiSpan;
1415

1516
/// An enum representing a diagnostic level.
1617
#[unstable(feature = "proc_macro_diagnostic", issue = "38356")]
@@ -97,37 +98,32 @@ impl Diagnostic {
9798
/// Emit the diagnostic.
9899
#[unstable(feature = "proc_macro_diagnostic", issue = "38356")]
99100
pub fn emit(self) {
100-
::__internal::with_sess(move |sess, _| {
101-
let handler = &sess.span_diagnostic;
102-
let level = __internal::level_to_internal_level(self.level);
103-
let mut diag = rustc::DiagnosticBuilder::new(handler, level, &*self.message);
101+
let level = self.level.to_internal();
102+
let mut diag = errors::Diagnostic::new(level, &*self.message);
104103

105-
if let Some(span) = self.span {
106-
diag.set_span(span.0);
107-
}
104+
if let Some(span) = self.span {
105+
diag.set_span(span.0);
106+
}
108107

109-
for child in self.children {
110-
let span = child.span.map(|s| s.0);
111-
let level = __internal::level_to_internal_level(child.level);
112-
diag.sub(level, &*child.message, span);
113-
}
108+
for child in self.children {
109+
let span = child.span.map_or(MultiSpan::new(), |s| s.0.into());
110+
let level = child.level.to_internal();
111+
diag.sub(level, &*child.message, span, None);
112+
}
114113

115-
diag.emit();
114+
::__internal::with_sess(move |sess, _| {
115+
errors::DiagnosticBuilder::new_diagnostic(&sess.span_diagnostic, diag).emit();
116116
});
117117
}
118118
}
119119

120-
#[unstable(feature = "proc_macro_internals", issue = "27812")]
121-
#[doc(hidden)]
122-
pub mod __internal {
123-
use super::{Level, rustc};
124-
125-
pub fn level_to_internal_level(level: Level) -> rustc::Level {
126-
match level {
127-
Level::Error => rustc::Level::Error,
128-
Level::Warning => rustc::Level::Warning,
129-
Level::Note => rustc::Level::Note,
130-
Level::Help => rustc::Level::Help,
120+
impl Level {
121+
fn to_internal(self) -> errors::Level {
122+
match self {
123+
Level::Error => errors::Level::Error,
124+
Level::Warning => errors::Level::Warning,
125+
Level::Note => errors::Level::Note,
126+
Level::Help => errors::Level::Help,
131127
Level::__Nonexhaustive => unreachable!("Level::__Nonexhaustive")
132128
}
133129
}

src/librustc_errors/diagnostic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ impl Diagnostic {
379379

380380
/// Convenience function for internal use, clients should use one of the
381381
/// public methods above.
382-
pub(crate) fn sub(&mut self,
382+
pub fn sub(&mut self,
383383
level: Level,
384384
message: &str,
385385
span: MultiSpan,

0 commit comments

Comments
 (0)