@@ -54,8 +54,9 @@ use serialize::EncoderHelpers;
5454
5555#[ cfg( test) ] use std:: io:: Cursor ;
5656#[ cfg( test) ] use syntax:: parse;
57+ #[ cfg( test) ] use syntax:: ast:: NodeId ;
5758#[ cfg( test) ] use rustc_front:: print:: pprust;
58- #[ cfg( test) ] use rustc_front:: lowering:: lower_item;
59+ #[ cfg( test) ] use rustc_front:: lowering:: { lower_item, LoweringContext } ;
5960
6061struct DecodeContext < ' a , ' b , ' tcx : ' a > {
6162 tcx : & ' a ty:: ctxt < ' tcx > ,
@@ -1374,6 +1375,22 @@ impl FakeExtCtxt for parse::ParseSess {
13741375 fn parse_sess ( & self ) -> & parse:: ParseSess { self }
13751376}
13761377
1378+ #[ cfg( test) ]
1379+ struct FakeNodeIdAssigner ;
1380+
1381+ #[ cfg( test) ]
1382+ // It should go without sayingt that this may give unexpected results. Avoid
1383+ // lowering anything which needs new nodes.
1384+ impl NodeIdAssigner for FakeNodeIdAssigner {
1385+ fn next_node_id ( & self ) -> NodeId {
1386+ 0
1387+ }
1388+
1389+ fn peek_node_id ( & self ) -> NodeId {
1390+ 0
1391+ }
1392+ }
1393+
13771394#[ cfg( test) ]
13781395fn mk_ctxt ( ) -> parse:: ParseSess {
13791396 parse:: ParseSess :: new ( )
@@ -1392,23 +1409,29 @@ fn roundtrip(in_item: P<hir::Item>) {
13921409#[ test]
13931410fn test_basic ( ) {
13941411 let cx = mk_ctxt ( ) ;
1395- roundtrip ( lower_item ( & quote_item ! ( & cx,
1412+ let fnia = FakeNodeIdAssigner ;
1413+ let lcx = LoweringContext :: new ( & fnia, None ) ;
1414+ roundtrip ( lower_item ( & lcx, & quote_item ! ( & cx,
13961415 fn foo( ) { }
13971416 ) . unwrap ( ) ) ) ;
13981417}
13991418
14001419#[ test]
14011420fn test_smalltalk ( ) {
14021421 let cx = mk_ctxt ( ) ;
1403- roundtrip ( lower_item ( & quote_item ! ( & cx,
1422+ let fnia = FakeNodeIdAssigner ;
1423+ let lcx = LoweringContext :: new ( & fnia, None ) ;
1424+ roundtrip ( lower_item ( & lcx, & quote_item ! ( & cx,
14041425 fn foo( ) -> isize { 3 + 4 } // first smalltalk program ever executed.
14051426 ) . unwrap ( ) ) ) ;
14061427}
14071428
14081429#[ test]
14091430fn test_more ( ) {
14101431 let cx = mk_ctxt ( ) ;
1411- roundtrip ( lower_item ( & quote_item ! ( & cx,
1432+ let fnia = FakeNodeIdAssigner ;
1433+ let lcx = LoweringContext :: new ( & fnia, None ) ;
1434+ roundtrip ( lower_item ( & lcx, & quote_item ! ( & cx,
14121435 fn foo( x: usize , y: usize ) -> usize {
14131436 let z = x + y;
14141437 return z;
@@ -1425,10 +1448,12 @@ fn test_simplification() {
14251448 return alist { eq_fn: eq_int, data: Vec :: new( ) } ;
14261449 }
14271450 ) . unwrap ( ) ;
1428- let hir_item = lower_item ( & item) ;
1451+ let fnia = FakeNodeIdAssigner ;
1452+ let lcx = LoweringContext :: new ( & fnia, None ) ;
1453+ let hir_item = lower_item ( & lcx, & item) ;
14291454 let item_in = InlinedItemRef :: Item ( & hir_item) ;
14301455 let item_out = simplify_ast ( item_in) ;
1431- let item_exp = InlinedItem :: Item ( lower_item ( & quote_item ! ( & cx,
1456+ let item_exp = InlinedItem :: Item ( lower_item ( & lcx , & quote_item ! ( & cx,
14321457 fn new_int_alist<B >( ) -> alist<isize , B > {
14331458 return alist { eq_fn: eq_int, data: Vec :: new( ) } ;
14341459 }
0 commit comments