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