@@ -5,7 +5,7 @@ use std::rc::Rc;
55
66use rustc_ast:: attr:: MarkedAttrs ;
77use rustc_ast:: ptr:: P ;
8- use rustc_ast:: token:: Nonterminal ;
8+ use rustc_ast:: token:: MetaVarKind ;
99use rustc_ast:: tokenstream:: TokenStream ;
1010use rustc_ast:: visit:: { AssocCtxt , Visitor } ;
1111use rustc_ast:: { self as ast, AttrVec , Attribute , HasAttrs , Item , NodeId , PatKind } ;
@@ -15,7 +15,7 @@ use rustc_data_structures::sync::{self, Lrc};
1515use rustc_errors:: { DiagCtxtHandle , ErrorGuaranteed , PResult } ;
1616use rustc_feature:: Features ;
1717use rustc_lint_defs:: { BufferedEarlyLint , RegisteredTools } ;
18- use rustc_parse:: parser:: Parser ;
18+ use rustc_parse:: parser:: { ForceCollect , Parser } ;
1919use rustc_parse:: MACRO_ARGUMENTS ;
2020use rustc_session:: config:: CollapseMacroDebuginfo ;
2121use rustc_session:: parse:: ParseSess ;
@@ -1374,13 +1374,13 @@ pub fn parse_macro_name_and_helper_attrs(
13741374/// If this item looks like a specific enums from `rental`, emit a fatal error.
13751375/// See #73345 and #83125 for more details.
13761376/// 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 ) {
13781378 let name = item. ident . name ;
13791379 if name == sym:: ProceduralMasqueradeDummyType
13801380 && let ast:: ItemKind :: Enum ( enum_def, _) = & item. kind
13811381 && let [ variant] = & * enum_def. variants
13821382 && 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 )
13841384 && let Some ( c) = real
13851385 . local_path ( )
13861386 . unwrap_or ( Path :: new ( "" ) )
@@ -1398,15 +1398,15 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &Session) {
13981398 } ;
13991399
14001400 if crate_matches {
1401- sess . dcx ( ) . emit_fatal ( errors:: ProcMacroBackCompat {
1401+ psess . dcx ( ) . emit_fatal ( errors:: ProcMacroBackCompat {
14021402 crate_name : "rental" . to_string ( ) ,
14031403 fixed_version : "0.5.6" . to_string ( ) ,
14041404 } ) ;
14051405 }
14061406 }
14071407}
14081408
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 ) {
14101410 let item = match ann {
14111411 Annotatable :: Item ( item) => item,
14121412 Annotatable :: Stmt ( stmt) => match & stmt. kind {
@@ -1415,17 +1415,36 @@ pub(crate) fn ann_pretty_printing_compatibility_hack(ann: &Annotatable, sess: &S
14151415 } ,
14161416 _ => return ,
14171417 } ;
1418- pretty_printing_compatibility_hack ( item, sess )
1418+ pretty_printing_compatibility_hack ( item, psess )
14191419}
14201420
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+ }
14281447 _ => return ,
14291448 } ;
1430- pretty_printing_compatibility_hack ( item, sess )
1449+ pretty_printing_compatibility_hack ( & item, psess )
14311450}
0 commit comments