Skip to content

Commit 8cf463b

Browse files
committed
proc_macro: move the rustc server to syntax_ext.
1 parent 38fee30 commit 8cf463b

File tree

7 files changed

+33
-33
lines changed

7 files changed

+33
-33
lines changed

Cargo.lock

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,12 +1599,6 @@ dependencies = [
15991599
[[package]]
16001600
name = "proc_macro"
16011601
version = "0.0.0"
1602-
dependencies = [
1603-
"rustc_data_structures 0.0.0",
1604-
"rustc_errors 0.0.0",
1605-
"syntax 0.0.0",
1606-
"syntax_pos 0.0.0",
1607-
]
16081602

16091603
[[package]]
16101604
name = "profiler_builtins"

src/libproc_macro/Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,3 @@ version = "0.0.0"
77
path = "lib.rs"
88
crate-type = ["dylib"]
99

10-
[dependencies]
11-
syntax = { path = "../libsyntax" }
12-
syntax_pos = { path = "../libsyntax_pos" }
13-
rustc_errors = { path = "../librustc_errors" }
14-
rustc_data_structures = { path = "../librustc_data_structures" }

src/libproc_macro/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))]
2929

3030
#![feature(nll)]
31-
#![feature(rustc_private)]
3231
#![feature(staged_api)]
3332
#![feature(const_fn)]
3433
#![feature(extern_types)]
@@ -39,19 +38,10 @@
3938

4039
#![recursion_limit="256"]
4140

42-
extern crate syntax;
43-
extern crate syntax_pos;
44-
extern crate rustc_errors;
45-
extern crate rustc_data_structures;
46-
4741
#[unstable(feature = "proc_macro_internals", issue = "27812")]
4842
#[doc(hidden)]
4943
pub mod bridge;
5044

51-
#[unstable(feature = "proc_macro_internals", issue = "27812")]
52-
#[doc(hidden)]
53-
pub mod rustc;
54-
5545
mod diagnostic;
5646

5747
#[unstable(feature = "proc_macro_diagnostic", issue = "54140")]

src/libsyntax_ext/deriving/custom.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl MultiItemModifier for ProcMacroDerive {
7878
let token = Token::interpolated(token::NtItem(item));
7979
let input = tokenstream::TokenTree::Token(DUMMY_SP, token).into();
8080

81-
let server = ::proc_macro::rustc::Rustc::new(ecx);
81+
let server = ::proc_macro_server::Rustc::new(ecx);
8282
let stream = match self.client.run(&EXEC_STRATEGY, server, input) {
8383
Ok(stream) => stream,
8484
Err(e) => {

src/libsyntax_ext/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
1515
html_root_url = "https://doc.rust-lang.org/nightly/")]
1616

17+
#![feature(in_band_lifetimes)]
18+
#![feature(proc_macro_diagnostic)]
1719
#![feature(proc_macro_internals)]
20+
#![feature(proc_macro_span)]
1821
#![feature(decl_macro)]
1922
#![feature(nll)]
2023
#![feature(str_escape)]
@@ -57,6 +60,7 @@ mod test_case;
5760

5861
pub mod proc_macro_decls;
5962
pub mod proc_macro_impl;
63+
mod proc_macro_server;
6064

6165
use rustc_data_structures::sync::Lrc;
6266
use syntax::ast;

src/libsyntax_ext/proc_macro_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl base::AttrProcMacro for AttrProcMacro {
3232
annotation: TokenStream,
3333
annotated: TokenStream)
3434
-> TokenStream {
35-
let server = ::proc_macro::rustc::Rustc::new(ecx);
35+
let server = ::proc_macro_server::Rustc::new(ecx);
3636
match self.client.run(&EXEC_STRATEGY, server, annotation, annotated) {
3737
Ok(stream) => stream,
3838
Err(e) => {
@@ -61,7 +61,7 @@ impl base::ProcMacro for BangProcMacro {
6161
span: Span,
6262
input: TokenStream)
6363
-> TokenStream {
64-
let server = ::proc_macro::rustc::Rustc::new(ecx);
64+
let server = ::proc_macro_server::Rustc::new(ecx);
6565
match self.client.run(&EXEC_STRATEGY, server, input) {
6666
Ok(stream) => stream,
6767
Err(e) => {

src/libproc_macro/rustc.rs renamed to src/libsyntax_ext/proc_macro_server.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use bridge::{server, TokenTree};
12-
use {Delimiter, Level, LineColumn, Spacing};
11+
use errors::{self, Diagnostic, DiagnosticBuilder};
12+
use std::panic;
13+
14+
use proc_macro::bridge::{server, TokenTree};
15+
use proc_macro::{Delimiter, Level, LineColumn, Spacing};
1316

1417
use rustc_data_structures::sync::Lrc;
15-
use rustc_errors::{self as errors, Diagnostic, DiagnosticBuilder};
1618
use std::ascii;
1719
use std::ops::Bound;
1820
use syntax::ast;
@@ -24,7 +26,15 @@ use syntax_pos::hygiene::{SyntaxContext, Transparency};
2426
use syntax_pos::symbol::{keywords, Symbol};
2527
use syntax_pos::{BytePos, FileName, MultiSpan, Pos, SourceFile, Span};
2628

27-
impl Delimiter {
29+
trait FromInternal<T> {
30+
fn from_internal(x: T) -> Self;
31+
}
32+
33+
trait ToInternal<T> {
34+
fn to_internal(self) -> T;
35+
}
36+
37+
impl FromInternal<token::DelimToken> for Delimiter {
2838
fn from_internal(delim: token::DelimToken) -> Delimiter {
2939
match delim {
3040
token::Paren => Delimiter::Parenthesis,
@@ -33,7 +43,9 @@ impl Delimiter {
3343
token::NoDelim => Delimiter::None,
3444
}
3545
}
46+
}
3647

48+
impl ToInternal<token::DelimToken> for Delimiter {
3749
fn to_internal(self) -> token::DelimToken {
3850
match self {
3951
Delimiter::Parenthesis => token::Paren,
@@ -44,8 +56,10 @@ impl Delimiter {
4456
}
4557
}
4658

47-
impl TokenTree<Group, Punct, Ident, Literal> {
48-
fn from_internal(stream: TokenStream, sess: &ParseSess, stack: &mut Vec<Self>) -> Self {
59+
impl FromInternal<(TokenStream, &'_ ParseSess, &'_ mut Vec<Self>)>
60+
for TokenTree<Group, Punct, Ident, Literal>
61+
{
62+
fn from_internal((stream, sess, stack): (TokenStream, &ParseSess, &mut Vec<Self>)) -> Self {
4963
use syntax::parse::token::*;
5064

5165
let (tree, joint) = stream.as_tree();
@@ -204,7 +218,9 @@ impl TokenTree<Group, Punct, Ident, Literal> {
204218
Whitespace | Comment | Shebang(..) | Eof => unreachable!(),
205219
}
206220
}
221+
}
207222

223+
impl ToInternal<TokenStream> for TokenTree<Group, Punct, Ident, Literal> {
208224
fn to_internal(self) -> TokenStream {
209225
use syntax::parse::token::*;
210226

@@ -292,13 +308,14 @@ impl TokenTree<Group, Punct, Ident, Literal> {
292308
}
293309
}
294310

295-
impl Level {
311+
impl ToInternal<errors::Level> for Level {
296312
fn to_internal(self) -> errors::Level {
297313
match self {
298314
Level::Error => errors::Level::Error,
299315
Level::Warning => errors::Level::Warning,
300316
Level::Note => errors::Level::Note,
301317
Level::Help => errors::Level::Help,
318+
_ => unreachable!("unknown proc_macro::Level variant: {:?}", self),
302319
}
303320
}
304321
}
@@ -339,7 +356,7 @@ pub struct Literal {
339356
span: Span,
340357
}
341358

342-
pub struct Rustc<'a> {
359+
pub(crate) struct Rustc<'a> {
343360
sess: &'a ParseSess,
344361
def_site: Span,
345362
call_site: Span,
@@ -429,7 +446,7 @@ impl server::TokenStreamIter for Rustc<'_> {
429446
loop {
430447
let tree = iter.stack.pop().or_else(|| {
431448
let next = iter.cursor.next_as_stream()?;
432-
Some(TokenTree::from_internal(next, self.sess, &mut iter.stack))
449+
Some(TokenTree::from_internal((next, self.sess, &mut iter.stack)))
433450
})?;
434451
// HACK: The condition "dummy span + group with empty delimiter" represents an AST
435452
// fragment approximately converted into a token stream. This may happen, for

0 commit comments

Comments
 (0)