@@ -36,6 +36,7 @@ use middle::subst;
3636use middle:: ty:: { self , Ty } ;
3737
3838use syntax:: { ast, ast_util, codemap} ;
39+ use syntax:: ast:: NodeIdAssigner ;
3940use syntax:: codemap:: Span ;
4041use syntax:: ptr:: P ;
4142
@@ -53,8 +54,9 @@ use serialize::EncoderHelpers;
5354
5455#[ cfg( test) ] use std:: io:: Cursor ;
5556#[ cfg( test) ] use syntax:: parse;
57+ #[ cfg( test) ] use syntax:: ast:: NodeId ;
5658#[ cfg( test) ] use rustc_front:: print:: pprust;
57- #[ cfg( test) ] use rustc_front:: lowering:: lower_item;
59+ #[ cfg( test) ] use rustc_front:: lowering:: { lower_item, LoweringContext } ;
5860
5961struct DecodeContext < ' a , ' b , ' tcx : ' a > {
6062 tcx : & ' a ty:: ctxt < ' tcx > ,
@@ -1376,6 +1378,22 @@ impl FakeExtCtxt for parse::ParseSess {
13761378 fn parse_sess ( & self ) -> & parse:: ParseSess { self }
13771379}
13781380
1381+ #[ cfg( test) ]
1382+ struct FakeNodeIdAssigner ;
1383+
1384+ #[ cfg( test) ]
1385+ // It should go without saying that this may give unexpected results. Avoid
1386+ // lowering anything which needs new nodes.
1387+ impl NodeIdAssigner for FakeNodeIdAssigner {
1388+ fn next_node_id ( & self ) -> NodeId {
1389+ 0
1390+ }
1391+
1392+ fn peek_node_id ( & self ) -> NodeId {
1393+ 0
1394+ }
1395+ }
1396+
13791397#[ cfg( test) ]
13801398fn mk_ctxt ( ) -> parse:: ParseSess {
13811399 parse:: ParseSess :: new ( )
@@ -1394,23 +1412,29 @@ fn roundtrip(in_item: P<hir::Item>) {
13941412#[ test]
13951413fn test_basic ( ) {
13961414 let cx = mk_ctxt ( ) ;
1397- roundtrip ( lower_item ( & quote_item ! ( & cx,
1415+ let fnia = FakeNodeIdAssigner ;
1416+ let lcx = LoweringContext :: new ( & fnia, None ) ;
1417+ roundtrip ( lower_item ( & lcx, & quote_item ! ( & cx,
13981418 fn foo( ) { }
13991419 ) . unwrap ( ) ) ) ;
14001420}
14011421
14021422#[ test]
14031423fn test_smalltalk ( ) {
14041424 let cx = mk_ctxt ( ) ;
1405- roundtrip ( lower_item ( & quote_item ! ( & cx,
1425+ let fnia = FakeNodeIdAssigner ;
1426+ let lcx = LoweringContext :: new ( & fnia, None ) ;
1427+ roundtrip ( lower_item ( & lcx, & quote_item ! ( & cx,
14061428 fn foo( ) -> isize { 3 + 4 } // first smalltalk program ever executed.
14071429 ) . unwrap ( ) ) ) ;
14081430}
14091431
14101432#[ test]
14111433fn test_more ( ) {
14121434 let cx = mk_ctxt ( ) ;
1413- roundtrip ( lower_item ( & quote_item ! ( & cx,
1435+ let fnia = FakeNodeIdAssigner ;
1436+ let lcx = LoweringContext :: new ( & fnia, None ) ;
1437+ roundtrip ( lower_item ( & lcx, & quote_item ! ( & cx,
14141438 fn foo( x: usize , y: usize ) -> usize {
14151439 let z = x + y;
14161440 return z;
@@ -1427,10 +1451,12 @@ fn test_simplification() {
14271451 return alist { eq_fn: eq_int, data: Vec :: new( ) } ;
14281452 }
14291453 ) . unwrap ( ) ;
1430- let hir_item = lower_item ( & item) ;
1454+ let fnia = FakeNodeIdAssigner ;
1455+ let lcx = LoweringContext :: new ( & fnia, None ) ;
1456+ let hir_item = lower_item ( & lcx, & item) ;
14311457 let item_in = InlinedItemRef :: Item ( & hir_item) ;
14321458 let item_out = simplify_ast ( item_in) ;
1433- let item_exp = InlinedItem :: Item ( lower_item ( & quote_item ! ( & cx,
1459+ let item_exp = InlinedItem :: Item ( lower_item ( & lcx , & quote_item ! ( & cx,
14341460 fn new_int_alist<B >( ) -> alist<isize , B > {
14351461 return alist { eq_fn: eq_int, data: Vec :: new( ) } ;
14361462 }
0 commit comments