@@ -6,7 +6,7 @@ use std::rc::Rc;
6
6
7
7
use rustc_ast:: attr:: MarkedAttrs ;
8
8
use rustc_ast:: ptr:: P ;
9
- use rustc_ast:: token:: Nonterminal ;
9
+ use rustc_ast:: token:: MetaVarKind ;
10
10
use rustc_ast:: tokenstream:: TokenStream ;
11
11
use rustc_ast:: visit:: { AssocCtxt , Visitor } ;
12
12
use rustc_ast:: { self as ast, AttrVec , Attribute , HasAttrs , Item , NodeId , PatKind } ;
@@ -17,7 +17,7 @@ use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed, PResult};
17
17
use rustc_feature:: Features ;
18
18
use rustc_lint_defs:: { BufferedEarlyLint , RegisteredTools } ;
19
19
use rustc_parse:: MACRO_ARGUMENTS ;
20
- use rustc_parse:: parser:: Parser ;
20
+ use rustc_parse:: parser:: { ForceCollect , Parser } ;
21
21
use rustc_session:: config:: CollapseMacroDebuginfo ;
22
22
use rustc_session:: parse:: ParseSess ;
23
23
use rustc_session:: { Limit , Session } ;
@@ -1380,13 +1380,13 @@ pub fn parse_macro_name_and_helper_attrs(
1380
1380
/// If this item looks like a specific enums from `rental`, emit a fatal error.
1381
1381
/// See #73345 and #83125 for more details.
1382
1382
/// FIXME(#73933): Remove this eventually.
1383
- fn pretty_printing_compatibility_hack ( item : & Item , sess : & Session ) {
1383
+ fn pretty_printing_compatibility_hack ( item : & Item , psess : & ParseSess ) {
1384
1384
let name = item. ident . name ;
1385
1385
if name == sym:: ProceduralMasqueradeDummyType
1386
1386
&& let ast:: ItemKind :: Enum ( enum_def, _) = & item. kind
1387
1387
&& let [ variant] = & * enum_def. variants
1388
1388
&& variant. ident . name == sym:: Input
1389
- && let FileName :: Real ( real) = sess . source_map ( ) . span_to_filename ( item. ident . span )
1389
+ && let FileName :: Real ( real) = psess . source_map ( ) . span_to_filename ( item. ident . span )
1390
1390
&& let Some ( c) = real
1391
1391
. local_path ( )
1392
1392
. unwrap_or ( Path :: new ( "" ) )
@@ -1404,15 +1404,15 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &Session) {
1404
1404
} ;
1405
1405
1406
1406
if crate_matches {
1407
- sess . dcx ( ) . emit_fatal ( errors:: ProcMacroBackCompat {
1407
+ psess . dcx ( ) . emit_fatal ( errors:: ProcMacroBackCompat {
1408
1408
crate_name : "rental" . to_string ( ) ,
1409
1409
fixed_version : "0.5.6" . to_string ( ) ,
1410
1410
} ) ;
1411
1411
}
1412
1412
}
1413
1413
}
1414
1414
1415
- pub ( crate ) fn ann_pretty_printing_compatibility_hack ( ann : & Annotatable , sess : & Session ) {
1415
+ pub ( crate ) fn ann_pretty_printing_compatibility_hack ( ann : & Annotatable , psess : & ParseSess ) {
1416
1416
let item = match ann {
1417
1417
Annotatable :: Item ( item) => item,
1418
1418
Annotatable :: Stmt ( stmt) => match & stmt. kind {
@@ -1421,17 +1421,36 @@ pub(crate) fn ann_pretty_printing_compatibility_hack(ann: &Annotatable, sess: &S
1421
1421
} ,
1422
1422
_ => return ,
1423
1423
} ;
1424
- pretty_printing_compatibility_hack ( item, sess )
1424
+ pretty_printing_compatibility_hack ( item, psess )
1425
1425
}
1426
1426
1427
- pub ( crate ) fn nt_pretty_printing_compatibility_hack ( nt : & Nonterminal , sess : & Session ) {
1428
- let item = match nt {
1429
- Nonterminal :: NtItem ( item) => item,
1430
- Nonterminal :: NtStmt ( stmt) => match & stmt. kind {
1431
- ast:: StmtKind :: Item ( item) => item,
1432
- _ => return ,
1433
- } ,
1427
+ pub ( crate ) fn stream_pretty_printing_compatibility_hack (
1428
+ kind : MetaVarKind ,
1429
+ stream : & TokenStream ,
1430
+ psess : & ParseSess ,
1431
+ ) {
1432
+ let item = match kind {
1433
+ MetaVarKind :: Item => {
1434
+ let mut parser = Parser :: new ( psess, stream. clone ( ) , None ) ;
1435
+ // No need to collect tokens for this simple check.
1436
+ parser
1437
+ . parse_item ( ForceCollect :: No )
1438
+ . expect ( "failed to reparse item" )
1439
+ . expect ( "an actual item" )
1440
+ }
1441
+ MetaVarKind :: Stmt => {
1442
+ let mut parser = Parser :: new ( psess, stream. clone ( ) , None ) ;
1443
+ // No need to collect tokens for this simple check.
1444
+ let stmt = parser
1445
+ . parse_stmt ( ForceCollect :: No )
1446
+ . expect ( "failed to reparse" )
1447
+ . expect ( "an actual stmt" ) ;
1448
+ match & stmt. kind {
1449
+ ast:: StmtKind :: Item ( item) => item. clone ( ) ,
1450
+ _ => return ,
1451
+ }
1452
+ }
1434
1453
_ => return ,
1435
1454
} ;
1436
- pretty_printing_compatibility_hack ( item, sess )
1455
+ pretty_printing_compatibility_hack ( & item, psess )
1437
1456
}
0 commit comments