Skip to content

Commit bd455ef

Browse files
committed
Auto merge of #52552 - eddyb:proc-macro-prep, r=alexcrichton
Prepare proc_macro for decoupling it from the rest of the compiler. This is #49219 up to the point where the bridge is introduced. Aside from moving some code around, the largest change is the rewrite of `proc_macro::quote` to be simpler and do less introspection. I'd like to also extend `quote!` with `${stmt;...;expr}` instead of just `$variable` (and maybe even `$(... $iter ...)*`), which seems pretty straight-forward now, but I don't know if/when I should. r? @alexcrichton or @dtolnay cc @jseyfried @petrochenkov
2 parents 17eb392 + 99eac01 commit bd455ef

File tree

8 files changed

+465
-570
lines changed

8 files changed

+465
-570
lines changed

Diff for: src/libproc_macro/diagnostic.rs

+14-30
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,38 +98,21 @@ 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
}
119-
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,
131-
Level::__Nonexhaustive => unreachable!("Level::__Nonexhaustive")
132-
}
133-
}
134-
}

0 commit comments

Comments
 (0)