@@ -7,7 +7,7 @@ use std::sync::Arc;
77
88use rustc_ast:: attr:: { AttributeExt , MarkedAttrs } ;
99use rustc_ast:: ptr:: P ;
10- use rustc_ast:: token:: Nonterminal ;
10+ use rustc_ast:: token:: MetaVarKind ;
1111use rustc_ast:: tokenstream:: TokenStream ;
1212use rustc_ast:: visit:: { AssocCtxt , Visitor } ;
1313use rustc_ast:: { self as ast, AttrVec , Attribute , HasAttrs , Item , NodeId , PatKind } ;
@@ -19,7 +19,7 @@ use rustc_feature::Features;
1919use rustc_hir as hir;
2020use rustc_lint_defs:: { BufferedEarlyLint , RegisteredTools } ;
2121use rustc_parse:: MACRO_ARGUMENTS ;
22- use rustc_parse:: parser:: Parser ;
22+ use rustc_parse:: parser:: { ForceCollect , Parser } ;
2323use rustc_session:: config:: CollapseMacroDebuginfo ;
2424use rustc_session:: parse:: ParseSess ;
2525use rustc_session:: { Limit , Session } ;
@@ -1405,13 +1405,13 @@ pub fn parse_macro_name_and_helper_attrs(
14051405/// If this item looks like a specific enums from `rental`, emit a fatal error.
14061406/// See #73345 and #83125 for more details.
14071407/// FIXME(#73933): Remove this eventually.
1408- fn pretty_printing_compatibility_hack ( item : & Item , sess : & Session ) {
1408+ fn pretty_printing_compatibility_hack ( item : & Item , psess : & ParseSess ) {
14091409 let name = item. ident . name ;
14101410 if name == sym:: ProceduralMasqueradeDummyType
14111411 && let ast:: ItemKind :: Enum ( enum_def, _) = & item. kind
14121412 && let [ variant] = & * enum_def. variants
14131413 && variant. ident . name == sym:: Input
1414- && let FileName :: Real ( real) = sess . source_map ( ) . span_to_filename ( item. ident . span )
1414+ && let FileName :: Real ( real) = psess . source_map ( ) . span_to_filename ( item. ident . span )
14151415 && let Some ( c) = real
14161416 . local_path ( )
14171417 . unwrap_or ( Path :: new ( "" ) )
@@ -1429,15 +1429,15 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &Session) {
14291429 } ;
14301430
14311431 if crate_matches {
1432- sess . dcx ( ) . emit_fatal ( errors:: ProcMacroBackCompat {
1432+ psess . dcx ( ) . emit_fatal ( errors:: ProcMacroBackCompat {
14331433 crate_name : "rental" . to_string ( ) ,
14341434 fixed_version : "0.5.6" . to_string ( ) ,
14351435 } ) ;
14361436 }
14371437 }
14381438}
14391439
1440- pub ( crate ) fn ann_pretty_printing_compatibility_hack ( ann : & Annotatable , sess : & Session ) {
1440+ pub ( crate ) fn ann_pretty_printing_compatibility_hack ( ann : & Annotatable , psess : & ParseSess ) {
14411441 let item = match ann {
14421442 Annotatable :: Item ( item) => item,
14431443 Annotatable :: Stmt ( stmt) => match & stmt. kind {
@@ -1446,17 +1446,36 @@ pub(crate) fn ann_pretty_printing_compatibility_hack(ann: &Annotatable, sess: &S
14461446 } ,
14471447 _ => return ,
14481448 } ;
1449- pretty_printing_compatibility_hack ( item, sess )
1449+ pretty_printing_compatibility_hack ( item, psess )
14501450}
14511451
1452- pub ( crate ) fn nt_pretty_printing_compatibility_hack ( nt : & Nonterminal , sess : & Session ) {
1453- let item = match nt {
1454- Nonterminal :: NtItem ( item) => item,
1455- Nonterminal :: NtStmt ( stmt) => match & stmt. kind {
1456- ast:: StmtKind :: Item ( item) => item,
1457- _ => return ,
1458- } ,
1452+ pub ( crate ) fn stream_pretty_printing_compatibility_hack (
1453+ kind : MetaVarKind ,
1454+ stream : & TokenStream ,
1455+ psess : & ParseSess ,
1456+ ) {
1457+ let item = match kind {
1458+ MetaVarKind :: Item => {
1459+ let mut parser = Parser :: new ( psess, stream. clone ( ) , None ) ;
1460+ // No need to collect tokens for this simple check.
1461+ parser
1462+ . parse_item ( ForceCollect :: No )
1463+ . expect ( "failed to reparse item" )
1464+ . expect ( "an actual item" )
1465+ }
1466+ MetaVarKind :: Stmt => {
1467+ let mut parser = Parser :: new ( psess, stream. clone ( ) , None ) ;
1468+ // No need to collect tokens for this simple check.
1469+ let stmt = parser
1470+ . parse_stmt ( ForceCollect :: No )
1471+ . expect ( "failed to reparse" )
1472+ . expect ( "an actual stmt" ) ;
1473+ match & stmt. kind {
1474+ ast:: StmtKind :: Item ( item) => item. clone ( ) ,
1475+ _ => return ,
1476+ }
1477+ }
14591478 _ => return ,
14601479 } ;
1461- pretty_printing_compatibility_hack ( item, sess )
1480+ pretty_printing_compatibility_hack ( & item, psess )
14621481}
0 commit comments