@@ -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 } ;
@@ -18,7 +18,7 @@ use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed, PResult};
1818use rustc_feature:: Features ;
1919use rustc_lint_defs:: { BufferedEarlyLint , RegisteredTools } ;
2020use rustc_parse:: MACRO_ARGUMENTS ;
21- use rustc_parse:: parser:: Parser ;
21+ use rustc_parse:: parser:: { ForceCollect , Parser } ;
2222use rustc_session:: config:: CollapseMacroDebuginfo ;
2323use rustc_session:: parse:: ParseSess ;
2424use rustc_session:: { Limit , Session } ;
@@ -1382,13 +1382,13 @@ pub fn parse_macro_name_and_helper_attrs(
13821382/// If this item looks like a specific enums from `rental`, emit a fatal error.
13831383/// See #73345 and #83125 for more details.
13841384/// FIXME(#73933): Remove this eventually.
1385- fn pretty_printing_compatibility_hack ( item : & Item , sess : & Session ) {
1385+ fn pretty_printing_compatibility_hack ( item : & Item , psess : & ParseSess ) {
13861386 let name = item. ident . name ;
13871387 if name == sym:: ProceduralMasqueradeDummyType
13881388 && let ast:: ItemKind :: Enum ( enum_def, _) = & item. kind
13891389 && let [ variant] = & * enum_def. variants
13901390 && variant. ident . name == sym:: Input
1391- && let FileName :: Real ( real) = sess . source_map ( ) . span_to_filename ( item. ident . span )
1391+ && let FileName :: Real ( real) = psess . source_map ( ) . span_to_filename ( item. ident . span )
13921392 && let Some ( c) = real
13931393 . local_path ( )
13941394 . unwrap_or ( Path :: new ( "" ) )
@@ -1406,15 +1406,15 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &Session) {
14061406 } ;
14071407
14081408 if crate_matches {
1409- sess . dcx ( ) . emit_fatal ( errors:: ProcMacroBackCompat {
1409+ psess . dcx ( ) . emit_fatal ( errors:: ProcMacroBackCompat {
14101410 crate_name : "rental" . to_string ( ) ,
14111411 fixed_version : "0.5.6" . to_string ( ) ,
14121412 } ) ;
14131413 }
14141414 }
14151415}
14161416
1417- pub ( crate ) fn ann_pretty_printing_compatibility_hack ( ann : & Annotatable , sess : & Session ) {
1417+ pub ( crate ) fn ann_pretty_printing_compatibility_hack ( ann : & Annotatable , psess : & ParseSess ) {
14181418 let item = match ann {
14191419 Annotatable :: Item ( item) => item,
14201420 Annotatable :: Stmt ( stmt) => match & stmt. kind {
@@ -1423,17 +1423,36 @@ pub(crate) fn ann_pretty_printing_compatibility_hack(ann: &Annotatable, sess: &S
14231423 } ,
14241424 _ => return ,
14251425 } ;
1426- pretty_printing_compatibility_hack ( item, sess )
1426+ pretty_printing_compatibility_hack ( item, psess )
14271427}
14281428
1429- pub ( crate ) fn nt_pretty_printing_compatibility_hack ( nt : & Nonterminal , sess : & Session ) {
1430- let item = match nt {
1431- Nonterminal :: NtItem ( item) => item,
1432- Nonterminal :: NtStmt ( stmt) => match & stmt. kind {
1433- ast:: StmtKind :: Item ( item) => item,
1434- _ => return ,
1435- } ,
1429+ pub ( crate ) fn stream_pretty_printing_compatibility_hack (
1430+ kind : MetaVarKind ,
1431+ stream : & TokenStream ,
1432+ psess : & ParseSess ,
1433+ ) {
1434+ let item = match kind {
1435+ MetaVarKind :: Item => {
1436+ let mut parser = Parser :: new ( psess, stream. clone ( ) , None ) ;
1437+ // No need to collect tokens for this simple check.
1438+ parser
1439+ . parse_item ( ForceCollect :: No )
1440+ . expect ( "failed to reparse item" )
1441+ . expect ( "an actual item" )
1442+ }
1443+ MetaVarKind :: Stmt => {
1444+ let mut parser = Parser :: new ( psess, stream. clone ( ) , None ) ;
1445+ // No need to collect tokens for this simple check.
1446+ let stmt = parser
1447+ . parse_stmt ( ForceCollect :: No )
1448+ . expect ( "failed to reparse" )
1449+ . expect ( "an actual stmt" ) ;
1450+ match & stmt. kind {
1451+ ast:: StmtKind :: Item ( item) => item. clone ( ) ,
1452+ _ => return ,
1453+ }
1454+ }
14361455 _ => return ,
14371456 } ;
1438- pretty_printing_compatibility_hack ( item, sess )
1457+ pretty_printing_compatibility_hack ( & item, psess )
14391458}
0 commit comments