@@ -5,7 +5,7 @@ use crate::module::DirOwnership;
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:: NonterminalKind ;
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,8 @@ 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 , MACRO_ARGUMENTS } ;
18
+ use rustc_parse:: parser:: { ParseNtResult , Parser } ;
19
+ use rustc_parse:: MACRO_ARGUMENTS ;
19
20
use rustc_session:: config:: CollapseMacroDebuginfo ;
20
21
use rustc_session:: { parse:: ParseSess , Limit , Session } ;
21
22
use rustc_span:: def_id:: { CrateNum , DefId , LocalDefId } ;
@@ -1377,13 +1378,13 @@ pub fn parse_macro_name_and_helper_attrs(
1377
1378
/// If this item looks like a specific enums from `rental`, emit a fatal error.
1378
1379
/// See #73345 and #83125 for more details.
1379
1380
/// FIXME(#73933): Remove this eventually.
1380
- fn pretty_printing_compatibility_hack ( item : & Item , sess : & Session ) {
1381
+ fn pretty_printing_compatibility_hack ( item : & Item , psess : & ParseSess ) {
1381
1382
let name = item. ident . name ;
1382
1383
if name == sym:: ProceduralMasqueradeDummyType
1383
1384
&& let ast:: ItemKind :: Enum ( enum_def, _) = & item. kind
1384
1385
&& let [ variant] = & * enum_def. variants
1385
1386
&& variant. ident . name == sym:: Input
1386
- && let FileName :: Real ( real) = sess . source_map ( ) . span_to_filename ( item. ident . span )
1387
+ && let FileName :: Real ( real) = psess . source_map ( ) . span_to_filename ( item. ident . span )
1387
1388
&& let Some ( c) = real
1388
1389
. local_path ( )
1389
1390
. unwrap_or ( Path :: new ( "" ) )
@@ -1403,15 +1404,15 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &Session) {
1403
1404
if crate_matches {
1404
1405
// FIXME: make this translatable
1405
1406
#[ allow( rustc:: untranslatable_diagnostic) ]
1406
- sess . dcx ( ) . emit_fatal ( errors:: ProcMacroBackCompat {
1407
+ psess . dcx ( ) . emit_fatal ( errors:: ProcMacroBackCompat {
1407
1408
crate_name : "rental" . to_string ( ) ,
1408
1409
fixed_version : "0.5.6" . to_string ( ) ,
1409
1410
} ) ;
1410
1411
}
1411
1412
}
1412
1413
}
1413
1414
1414
- 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 ) {
1415
1416
let item = match ann {
1416
1417
Annotatable :: Item ( item) => item,
1417
1418
Annotatable :: Stmt ( stmt) => match & stmt. kind {
@@ -1420,17 +1421,34 @@ pub(crate) fn ann_pretty_printing_compatibility_hack(ann: &Annotatable, sess: &S
1420
1421
} ,
1421
1422
_ => return ,
1422
1423
} ;
1423
- pretty_printing_compatibility_hack ( item, sess )
1424
+ pretty_printing_compatibility_hack ( item, psess )
1424
1425
}
1425
1426
1426
- pub ( crate ) fn nt_pretty_printing_compatibility_hack ( nt : & Nonterminal , sess : & Session ) {
1427
- let item = match nt {
1428
- Nonterminal :: NtItem ( item) => item,
1429
- Nonterminal :: NtStmt ( stmt) => match & stmt. kind {
1430
- ast:: StmtKind :: Item ( item) => item,
1431
- _ => return ,
1432
- } ,
1427
+ pub ( crate ) fn stream_pretty_printing_compatibility_hack (
1428
+ kind : NonterminalKind ,
1429
+ stream : & TokenStream ,
1430
+ psess : & ParseSess ,
1431
+ ) {
1432
+ let item = match kind {
1433
+ NonterminalKind :: Item => {
1434
+ let mut parser = Parser :: new ( psess, stream. clone ( ) , None ) ;
1435
+ let Ok ( ParseNtResult :: Item ( item) ) = parser. parse_nonterminal ( kind) else {
1436
+ panic ! ( "failed to reparse" ) ;
1437
+ } ;
1438
+ item
1439
+ }
1440
+ NonterminalKind :: Stmt => {
1441
+ // njn: reparsing and then checking for StmtKind::Item sucks, hmm
1442
+ let mut parser = Parser :: new ( psess, stream. clone ( ) , None ) ;
1443
+ let Ok ( ParseNtResult :: Stmt ( stmt) ) = parser. parse_nonterminal ( kind) else {
1444
+ panic ! ( "failed to reparse" ) ;
1445
+ } ;
1446
+ match & stmt. kind {
1447
+ ast:: StmtKind :: Item ( item) => item. clone ( ) ,
1448
+ _ => return ,
1449
+ }
1450
+ }
1433
1451
_ => return ,
1434
1452
} ;
1435
- pretty_printing_compatibility_hack ( item, sess )
1453
+ pretty_printing_compatibility_hack ( & item, psess )
1436
1454
}
0 commit comments