@@ -36,6 +36,7 @@ use middle::subst;
36
36
use middle:: ty:: { self , Ty } ;
37
37
38
38
use syntax:: { ast, ast_util, codemap} ;
39
+ use syntax:: ast:: NodeIdAssigner ;
39
40
use syntax:: codemap:: Span ;
40
41
use syntax:: ptr:: P ;
41
42
@@ -53,8 +54,9 @@ use serialize::EncoderHelpers;
53
54
54
55
#[ cfg( test) ] use std:: io:: Cursor ;
55
56
#[ cfg( test) ] use syntax:: parse;
57
+ #[ cfg( test) ] use syntax:: ast:: NodeId ;
56
58
#[ 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 } ;
58
60
59
61
struct DecodeContext < ' a , ' b , ' tcx : ' a > {
60
62
tcx : & ' a ty:: ctxt < ' tcx > ,
@@ -1376,6 +1378,22 @@ impl FakeExtCtxt for parse::ParseSess {
1376
1378
fn parse_sess ( & self ) -> & parse:: ParseSess { self }
1377
1379
}
1378
1380
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
+
1379
1397
#[ cfg( test) ]
1380
1398
fn mk_ctxt ( ) -> parse:: ParseSess {
1381
1399
parse:: ParseSess :: new ( )
@@ -1394,23 +1412,29 @@ fn roundtrip(in_item: P<hir::Item>) {
1394
1412
#[ test]
1395
1413
fn test_basic ( ) {
1396
1414
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,
1398
1418
fn foo( ) { }
1399
1419
) . unwrap ( ) ) ) ;
1400
1420
}
1401
1421
1402
1422
#[ test]
1403
1423
fn test_smalltalk ( ) {
1404
1424
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,
1406
1428
fn foo( ) -> isize { 3 + 4 } // first smalltalk program ever executed.
1407
1429
) . unwrap ( ) ) ) ;
1408
1430
}
1409
1431
1410
1432
#[ test]
1411
1433
fn test_more ( ) {
1412
1434
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,
1414
1438
fn foo( x: usize , y: usize ) -> usize {
1415
1439
let z = x + y;
1416
1440
return z;
@@ -1427,10 +1451,12 @@ fn test_simplification() {
1427
1451
return alist { eq_fn: eq_int, data: Vec :: new( ) } ;
1428
1452
}
1429
1453
) . 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) ;
1431
1457
let item_in = InlinedItemRef :: Item ( & hir_item) ;
1432
1458
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,
1434
1460
fn new_int_alist<B >( ) -> alist<isize , B > {
1435
1461
return alist { eq_fn: eq_int, data: Vec :: new( ) } ;
1436
1462
}
0 commit comments