@@ -50,6 +50,7 @@ use session::Session;
5050use std:: collections:: BTreeMap ;
5151use std:: iter;
5252use syntax:: ast:: * ;
53+ use syntax:: errors;
5354use syntax:: ptr:: P ;
5455use syntax:: codemap:: { respan, Spanned } ;
5556use syntax:: parse:: token;
@@ -60,7 +61,7 @@ use syntax_pos::Span;
6061pub struct LoweringContext < ' a > {
6162 crate_root : Option < & ' static str > ,
6263 // Use to assign ids to hir nodes that do not directly correspond to an ast node
63- id_assigner : & ' a NodeIdAssigner ,
64+ sess : Option < & ' a Session > ,
6465 // As we walk the AST we must keep track of the current 'parent' def id (in
6566 // the form of a DefIndex) so that if we create a new node which introduces
6667 // a definition, then we can properly create the def id.
@@ -99,7 +100,6 @@ impl Resolver for DummyResolver {
99100
100101pub fn lower_crate ( sess : & Session ,
101102 krate : & Crate ,
102- id_assigner : & NodeIdAssigner ,
103103 resolver : & mut Resolver )
104104 -> hir:: Crate {
105105 // We're constructing the HIR here; we don't care what we will
@@ -115,17 +115,17 @@ pub fn lower_crate(sess: &Session,
115115 } else {
116116 Some ( "std" )
117117 } ,
118- id_assigner : id_assigner ,
118+ sess : Some ( sess ) ,
119119 parent_def : None ,
120120 resolver : resolver,
121121 } . lower_crate ( krate)
122122}
123123
124124impl < ' a > LoweringContext < ' a > {
125- pub fn testing_context ( id_assigner : & ' a NodeIdAssigner , resolver : & ' a mut Resolver ) -> Self {
125+ pub fn testing_context ( resolver : & ' a mut Resolver ) -> Self {
126126 LoweringContext {
127127 crate_root : None ,
128- id_assigner : id_assigner ,
128+ sess : None ,
129129 parent_def : None ,
130130 resolver : resolver,
131131 }
@@ -161,7 +161,12 @@ impl<'a> LoweringContext<'a> {
161161 }
162162
163163 fn next_id ( & self ) -> NodeId {
164- self . id_assigner . next_node_id ( )
164+ self . sess . map ( Session :: next_node_id) . unwrap_or ( 0 )
165+ }
166+
167+ fn diagnostic ( & self ) -> & errors:: Handler {
168+ self . sess . map ( Session :: diagnostic)
169+ . unwrap_or_else ( || panic ! ( "this lowerer cannot emit diagnostics" ) )
165170 }
166171
167172 fn str_to_ident ( & self , s : & ' static str ) -> Name {
@@ -786,7 +791,7 @@ impl<'a> LoweringContext<'a> {
786791 if let Some ( SelfKind :: Explicit ( ..) ) = sig. decl . get_self ( ) . map ( |eself| eself. node ) {
787792 match hir_sig. decl . get_self ( ) . map ( |eself| eself. node ) {
788793 Some ( hir:: SelfKind :: Value ( ..) ) | Some ( hir:: SelfKind :: Region ( ..) ) => {
789- self . id_assigner . diagnostic ( ) . span_err ( sig. decl . inputs [ 0 ] . ty . span ,
794+ self . diagnostic ( ) . span_err ( sig. decl . inputs [ 0 ] . ty . span ,
790795 "the type placeholder `_` is not allowed within types on item signatures" ) ;
791796 }
792797 _ => { }
@@ -1212,7 +1217,7 @@ impl<'a> LoweringContext<'a> {
12121217 make_struct ( self , e, & [ "RangeInclusive" , "NonEmpty" ] ,
12131218 & [ ( "start" , e1) , ( "end" , e2) ] ) ,
12141219
1215- _ => panic ! ( self . id_assigner . diagnostic( )
1220+ _ => panic ! ( self . diagnostic( )
12161221 . span_fatal( e. span, "inclusive range with no end" ) ) ,
12171222 } ;
12181223 }
0 commit comments