@@ -1376,12 +1376,13 @@ fn ttdelim_span() {
1376
1376
} ) ;
1377
1377
}
1378
1378
1379
- // Uses a macro rather than a function so that failure messages mention the
1380
- // correct line in the test function.
1381
- macro_rules! look {
1382
- ( $p: ident, $dist: literal, $kind: expr) => {
1383
- $p. look_ahead( $dist, |tok| assert_eq!( $kind, tok. kind) ) ;
1384
- } ;
1379
+ #[ track_caller]
1380
+ fn look ( p : & Parser < ' _ > , dist : usize , kind : rustc_ast:: token:: TokenKind ) {
1381
+ // Do the `assert_eq` outside the closure so that `track_caller` works.
1382
+ // (`#![feature(closure_track_caller)]` + `#[track_caller]` on the closure
1383
+ // doesn't give the line number in the test below if the assertion fails.)
1384
+ let tok = p. look_ahead ( dist, |tok| tok. clone ( ) ) ;
1385
+ assert_eq ! ( kind, tok. kind) ;
1385
1386
}
1386
1387
1387
1388
#[ test]
@@ -1397,63 +1398,63 @@ fn look_ahead() {
1397
1398
let mut p = string_to_parser ( & psess, "fn f(x: u32) { x } struct S;" . to_string ( ) ) ;
1398
1399
1399
1400
// Current position is the `fn`.
1400
- look ! ( p, 0 , token:: Ident ( kw:: Fn , raw_no) ) ;
1401
- look ! ( p, 1 , token:: Ident ( sym_f, raw_no) ) ;
1402
- look ! ( p, 2 , token:: OpenDelim ( Delimiter :: Parenthesis ) ) ;
1403
- look ! ( p, 3 , token:: Ident ( sym_x, raw_no) ) ;
1404
- look ! ( p, 4 , token:: Colon ) ;
1405
- look ! ( p, 5 , token:: Ident ( sym:: u32 , raw_no) ) ;
1406
- look ! ( p, 6 , token:: CloseDelim ( Delimiter :: Parenthesis ) ) ;
1407
- look ! ( p, 7 , token:: OpenDelim ( Delimiter :: Brace ) ) ;
1408
- look ! ( p, 8 , token:: Ident ( sym_x, raw_no) ) ;
1409
- look ! ( p, 9 , token:: CloseDelim ( Delimiter :: Brace ) ) ;
1410
- look ! ( p, 10 , token:: Ident ( kw:: Struct , raw_no) ) ;
1411
- look ! ( p, 11 , token:: Ident ( sym_S, raw_no) ) ;
1412
- look ! ( p, 12 , token:: Semi ) ;
1401
+ look ( & p, 0 , token:: Ident ( kw:: Fn , raw_no) ) ;
1402
+ look ( & p, 1 , token:: Ident ( sym_f, raw_no) ) ;
1403
+ look ( & p, 2 , token:: OpenDelim ( Delimiter :: Parenthesis ) ) ;
1404
+ look ( & p, 3 , token:: Ident ( sym_x, raw_no) ) ;
1405
+ look ( & p, 4 , token:: Colon ) ;
1406
+ look ( & p, 5 , token:: Ident ( sym:: u32, raw_no) ) ;
1407
+ look ( & p, 6 , token:: CloseDelim ( Delimiter :: Parenthesis ) ) ;
1408
+ look ( & p, 7 , token:: OpenDelim ( Delimiter :: Brace ) ) ;
1409
+ look ( & p, 8 , token:: Ident ( sym_x, raw_no) ) ;
1410
+ look ( & p, 9 , token:: CloseDelim ( Delimiter :: Brace ) ) ;
1411
+ look ( & p, 10 , token:: Ident ( kw:: Struct , raw_no) ) ;
1412
+ look ( & p, 11 , token:: Ident ( sym_S, raw_no) ) ;
1413
+ look ( & p, 12 , token:: Semi ) ;
1413
1414
// Any lookahead past the end of the token stream returns `Eof`.
1414
- look ! ( p, 13 , token:: Eof ) ;
1415
- look ! ( p, 14 , token:: Eof ) ;
1416
- look ! ( p, 15 , token:: Eof ) ;
1417
- look ! ( p, 100 , token:: Eof ) ;
1415
+ look ( & p, 13 , token:: Eof ) ;
1416
+ look ( & p, 14 , token:: Eof ) ;
1417
+ look ( & p, 15 , token:: Eof ) ;
1418
+ look ( & p, 100 , token:: Eof ) ;
1418
1419
1419
1420
// Move forward to the first `x`.
1420
1421
for _ in 0 ..3 {
1421
1422
p. bump ( ) ;
1422
1423
}
1423
- look ! ( p, 0 , token:: Ident ( sym_x, raw_no) ) ;
1424
- look ! ( p, 1 , token:: Colon ) ;
1425
- look ! ( p, 2 , token:: Ident ( sym:: u32 , raw_no) ) ;
1426
- look ! ( p, 3 , token:: CloseDelim ( Delimiter :: Parenthesis ) ) ;
1427
- look ! ( p, 4 , token:: OpenDelim ( Delimiter :: Brace ) ) ;
1428
- look ! ( p, 5 , token:: Ident ( sym_x, raw_no) ) ;
1429
- look ! ( p, 6 , token:: CloseDelim ( Delimiter :: Brace ) ) ;
1430
- look ! ( p, 7 , token:: Ident ( kw:: Struct , raw_no) ) ;
1431
- look ! ( p, 8 , token:: Ident ( sym_S, raw_no) ) ;
1432
- look ! ( p, 9 , token:: Semi ) ;
1433
- look ! ( p, 10 , token:: Eof ) ;
1434
- look ! ( p, 11 , token:: Eof ) ;
1435
- look ! ( p, 100 , token:: Eof ) ;
1424
+ look ( & p, 0 , token:: Ident ( sym_x, raw_no) ) ;
1425
+ look ( & p, 1 , token:: Colon ) ;
1426
+ look ( & p, 2 , token:: Ident ( sym:: u32, raw_no) ) ;
1427
+ look ( & p, 3 , token:: CloseDelim ( Delimiter :: Parenthesis ) ) ;
1428
+ look ( & p, 4 , token:: OpenDelim ( Delimiter :: Brace ) ) ;
1429
+ look ( & p, 5 , token:: Ident ( sym_x, raw_no) ) ;
1430
+ look ( & p, 6 , token:: CloseDelim ( Delimiter :: Brace ) ) ;
1431
+ look ( & p, 7 , token:: Ident ( kw:: Struct , raw_no) ) ;
1432
+ look ( & p, 8 , token:: Ident ( sym_S, raw_no) ) ;
1433
+ look ( & p, 9 , token:: Semi ) ;
1434
+ look ( & p, 10 , token:: Eof ) ;
1435
+ look ( & p, 11 , token:: Eof ) ;
1436
+ look ( & p, 100 , token:: Eof ) ;
1436
1437
1437
1438
// Move forward to the `;`.
1438
1439
for _ in 0 ..9 {
1439
1440
p. bump ( ) ;
1440
1441
}
1441
- look ! ( p, 0 , token:: Semi ) ;
1442
+ look ( & p, 0 , token:: Semi ) ;
1442
1443
// Any lookahead past the end of the token stream returns `Eof`.
1443
- look ! ( p, 1 , token:: Eof ) ;
1444
- look ! ( p, 100 , token:: Eof ) ;
1444
+ look ( & p, 1 , token:: Eof ) ;
1445
+ look ( & p, 100 , token:: Eof ) ;
1445
1446
1446
1447
// Move one past the `;`, i.e. past the end of the token stream.
1447
1448
p. bump ( ) ;
1448
- look ! ( p, 0 , token:: Eof ) ;
1449
- look ! ( p, 1 , token:: Eof ) ;
1450
- look ! ( p, 100 , token:: Eof ) ;
1449
+ look ( & p, 0 , token:: Eof ) ;
1450
+ look ( & p, 1 , token:: Eof ) ;
1451
+ look ( & p, 100 , token:: Eof ) ;
1451
1452
1452
1453
// Bumping after Eof is idempotent.
1453
1454
p. bump ( ) ;
1454
- look ! ( p, 0 , token:: Eof ) ;
1455
- look ! ( p, 1 , token:: Eof ) ;
1456
- look ! ( p, 100 , token:: Eof ) ;
1455
+ look ( & p, 0 , token:: Eof ) ;
1456
+ look ( & p, 1 , token:: Eof ) ;
1457
+ look ( & p, 100 , token:: Eof ) ;
1457
1458
} ) ;
1458
1459
}
1459
1460
@@ -1476,24 +1477,24 @@ fn look_ahead_non_outermost_stream() {
1476
1477
for _ in 0 ..3 {
1477
1478
p. bump ( ) ;
1478
1479
}
1479
- look ! ( p, 0 , token:: Ident ( kw:: Fn , raw_no) ) ;
1480
- look ! ( p, 1 , token:: Ident ( sym_f, raw_no) ) ;
1481
- look ! ( p, 2 , token:: OpenDelim ( Delimiter :: Parenthesis ) ) ;
1482
- look ! ( p, 3 , token:: Ident ( sym_x, raw_no) ) ;
1483
- look ! ( p, 4 , token:: Colon ) ;
1484
- look ! ( p, 5 , token:: Ident ( sym:: u32 , raw_no) ) ;
1485
- look ! ( p, 6 , token:: CloseDelim ( Delimiter :: Parenthesis ) ) ;
1486
- look ! ( p, 7 , token:: OpenDelim ( Delimiter :: Brace ) ) ;
1487
- look ! ( p, 8 , token:: Ident ( sym_x, raw_no) ) ;
1488
- look ! ( p, 9 , token:: CloseDelim ( Delimiter :: Brace ) ) ;
1489
- look ! ( p, 10 , token:: Ident ( kw:: Struct , raw_no) ) ;
1490
- look ! ( p, 11 , token:: Ident ( sym_S, raw_no) ) ;
1491
- look ! ( p, 12 , token:: Semi ) ;
1492
- look ! ( p, 13 , token:: CloseDelim ( Delimiter :: Brace ) ) ;
1480
+ look ( & p, 0 , token:: Ident ( kw:: Fn , raw_no) ) ;
1481
+ look ( & p, 1 , token:: Ident ( sym_f, raw_no) ) ;
1482
+ look ( & p, 2 , token:: OpenDelim ( Delimiter :: Parenthesis ) ) ;
1483
+ look ( & p, 3 , token:: Ident ( sym_x, raw_no) ) ;
1484
+ look ( & p, 4 , token:: Colon ) ;
1485
+ look ( & p, 5 , token:: Ident ( sym:: u32, raw_no) ) ;
1486
+ look ( & p, 6 , token:: CloseDelim ( Delimiter :: Parenthesis ) ) ;
1487
+ look ( & p, 7 , token:: OpenDelim ( Delimiter :: Brace ) ) ;
1488
+ look ( & p, 8 , token:: Ident ( sym_x, raw_no) ) ;
1489
+ look ( & p, 9 , token:: CloseDelim ( Delimiter :: Brace ) ) ;
1490
+ look ( & p, 10 , token:: Ident ( kw:: Struct , raw_no) ) ;
1491
+ look ( & p, 11 , token:: Ident ( sym_S, raw_no) ) ;
1492
+ look ( & p, 12 , token:: Semi ) ;
1493
+ look ( & p, 13 , token:: CloseDelim ( Delimiter :: Brace ) ) ;
1493
1494
// Any lookahead past the end of the token stream returns `Eof`.
1494
- look ! ( p, 14 , token:: Eof ) ;
1495
- look ! ( p, 15 , token:: Eof ) ;
1496
- look ! ( p, 100 , token:: Eof ) ;
1495
+ look ( & p, 14 , token:: Eof ) ;
1496
+ look ( & p, 15 , token:: Eof ) ;
1497
+ look ( & p, 100 , token:: Eof ) ;
1497
1498
} ) ;
1498
1499
}
1499
1500
0 commit comments