@@ -70,8 +70,8 @@ use syntax::print::pprust;
7070use syntax:: source_map:: { respan, ExpnData , ExpnKind , DesugaringKind , Spanned } ;
7171use syntax:: symbol:: { kw, sym, Symbol } ;
7272use 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 ;
7575use syntax:: visit:: { self , Visitor } ;
7676use syntax_pos:: Span ;
7777
@@ -87,6 +87,8 @@ pub struct LoweringContext<'a> {
8787
8888 resolver : & ' a mut dyn Resolver ,
8989
90+ parser : & ' static dyn Parser ,
91+
9092 /// The items being lowered are collected here.
9193 items : BTreeMap < hir:: HirId , hir:: Item > ,
9294
@@ -181,6 +183,13 @@ pub trait Resolver {
181183 fn has_derives ( & self , node_id : NodeId , derives : SpecialDerives ) -> bool ;
182184}
183185
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+
184193/// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree,
185194/// and if so, what meaning it has.
186195#[ derive( Debug ) ]
@@ -237,6 +246,7 @@ pub fn lower_crate(
237246 dep_graph : & DepGraph ,
238247 krate : & Crate ,
239248 resolver : & mut dyn Resolver ,
249+ parser : & ' static dyn Parser ,
240250) -> hir:: Crate {
241251 // We're constructing the HIR here; we don't care what we will
242252 // read, since we haven't even constructed the *input* to
@@ -250,6 +260,7 @@ pub fn lower_crate(
250260 sess,
251261 cstore,
252262 resolver,
263+ parser,
253264 items : BTreeMap :: new ( ) ,
254265 trait_items : BTreeMap :: new ( ) ,
255266 impl_items : BTreeMap :: new ( ) ,
@@ -1023,10 +1034,7 @@ impl<'a> LoweringContext<'a> {
10231034 fn lower_token ( & mut self , token : Token ) -> TokenStream {
10241035 match token. kind {
10251036 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 ) ;
10301038 self . lower_token_stream ( tts)
10311039 }
10321040 _ => TokenTree :: Token ( token) . into ( ) ,
0 commit comments