@@ -50,6 +50,7 @@ use session::Session;
50
50
use std:: collections:: BTreeMap ;
51
51
use std:: iter;
52
52
use syntax:: ast:: * ;
53
+ use syntax:: errors;
53
54
use syntax:: ptr:: P ;
54
55
use syntax:: codemap:: { respan, Spanned } ;
55
56
use syntax:: parse:: token;
@@ -60,7 +61,7 @@ use syntax_pos::Span;
60
61
pub struct LoweringContext < ' a > {
61
62
crate_root : Option < & ' static str > ,
62
63
// 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 > ,
64
65
// As we walk the AST we must keep track of the current 'parent' def id (in
65
66
// the form of a DefIndex) so that if we create a new node which introduces
66
67
// a definition, then we can properly create the def id.
@@ -99,7 +100,6 @@ impl Resolver for DummyResolver {
99
100
100
101
pub fn lower_crate ( sess : & Session ,
101
102
krate : & Crate ,
102
- id_assigner : & NodeIdAssigner ,
103
103
resolver : & mut Resolver )
104
104
-> hir:: Crate {
105
105
// We're constructing the HIR here; we don't care what we will
@@ -115,17 +115,17 @@ pub fn lower_crate(sess: &Session,
115
115
} else {
116
116
Some ( "std" )
117
117
} ,
118
- id_assigner : id_assigner ,
118
+ sess : Some ( sess ) ,
119
119
parent_def : None ,
120
120
resolver : resolver,
121
121
} . lower_crate ( krate)
122
122
}
123
123
124
124
impl < ' 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 {
126
126
LoweringContext {
127
127
crate_root : None ,
128
- id_assigner : id_assigner ,
128
+ sess : None ,
129
129
parent_def : None ,
130
130
resolver : resolver,
131
131
}
@@ -161,7 +161,12 @@ impl<'a> LoweringContext<'a> {
161
161
}
162
162
163
163
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" ) )
165
170
}
166
171
167
172
fn str_to_ident ( & self , s : & ' static str ) -> Name {
@@ -786,7 +791,7 @@ impl<'a> LoweringContext<'a> {
786
791
if let Some ( SelfKind :: Explicit ( ..) ) = sig. decl . get_self ( ) . map ( |eself| eself. node ) {
787
792
match hir_sig. decl . get_self ( ) . map ( |eself| eself. node ) {
788
793
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 ,
790
795
"the type placeholder `_` is not allowed within types on item signatures" ) ;
791
796
}
792
797
_ => { }
@@ -1212,7 +1217,7 @@ impl<'a> LoweringContext<'a> {
1212
1217
make_struct ( self , e, & [ "RangeInclusive" , "NonEmpty" ] ,
1213
1218
& [ ( "start" , e1) , ( "end" , e2) ] ) ,
1214
1219
1215
- _ => panic ! ( self . id_assigner . diagnostic( )
1220
+ _ => panic ! ( self . diagnostic( )
1216
1221
. span_fatal( e. span, "inclusive range with no end" ) ) ,
1217
1222
} ;
1218
1223
}
0 commit comments