@@ -70,8 +70,8 @@ use syntax::print::pprust;
70
70
use syntax:: source_map:: { respan, ExpnData , ExpnKind , DesugaringKind , Spanned } ;
71
71
use syntax:: symbol:: { kw, sym, Symbol } ;
72
72
use syntax:: tokenstream:: { TokenStream , TokenTree } ;
73
- use syntax:: parse;
74
- use syntax:: parse:: token :: { self , Token } ;
73
+ use syntax:: parse:: token :: { self , Nonterminal , Token } ;
74
+ use syntax:: parse:: ParseSess ;
75
75
use syntax:: visit:: { self , Visitor } ;
76
76
use syntax_pos:: Span ;
77
77
@@ -87,6 +87,8 @@ pub struct LoweringContext<'a> {
87
87
88
88
resolver : & ' a mut dyn Resolver ,
89
89
90
+ parser : & ' static dyn Parser ,
91
+
90
92
/// The items being lowered are collected here.
91
93
items : BTreeMap < hir:: HirId , hir:: Item > ,
92
94
@@ -181,6 +183,13 @@ pub trait Resolver {
181
183
fn has_derives ( & self , node_id : NodeId , derives : SpecialDerives ) -> bool ;
182
184
}
183
185
186
+ /// HACK(Centril): there is a cyclic dependency between the parser and lowering
187
+ /// if we don't have this trait. To avoid that dependency so that librustc is
188
+ /// independent of the parser, we use type erasure here.
189
+ pub trait Parser {
190
+ fn nt_to_tokenstream ( & self , nt : & Nonterminal , sess : & ParseSess , span : Span ) -> TokenStream ;
191
+ }
192
+
184
193
/// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree,
185
194
/// and if so, what meaning it has.
186
195
#[ derive( Debug ) ]
@@ -237,6 +246,7 @@ pub fn lower_crate(
237
246
dep_graph : & DepGraph ,
238
247
krate : & Crate ,
239
248
resolver : & mut dyn Resolver ,
249
+ parser : & ' static dyn Parser ,
240
250
) -> hir:: Crate {
241
251
// We're constructing the HIR here; we don't care what we will
242
252
// read, since we haven't even constructed the *input* to
@@ -250,6 +260,7 @@ pub fn lower_crate(
250
260
sess,
251
261
cstore,
252
262
resolver,
263
+ parser,
253
264
items : BTreeMap :: new ( ) ,
254
265
trait_items : BTreeMap :: new ( ) ,
255
266
impl_items : BTreeMap :: new ( ) ,
@@ -1023,10 +1034,7 @@ impl<'a> LoweringContext<'a> {
1023
1034
fn lower_token ( & mut self , token : Token ) -> TokenStream {
1024
1035
match token. kind {
1025
1036
token:: Interpolated ( nt) => {
1026
- // FIXME(Centril): Consider indirection `(parse_sess.nt_to_tokenstream)(...)`
1027
- // to hack around the current hack that requires `nt_to_tokenstream` to live
1028
- // in the parser.
1029
- let tts = parse:: nt_to_tokenstream ( & nt, & self . sess . parse_sess , token. span ) ;
1037
+ let tts = self . parser . nt_to_tokenstream ( & nt, & self . sess . parse_sess , token. span ) ;
1030
1038
self . lower_token_stream ( tts)
1031
1039
}
1032
1040
_ => TokenTree :: Token ( token) . into ( ) ,
0 commit comments