Auto merge of #138083 - nnethercote:rm-NtItem-NtStmt, r=petrochenkov · rust-lang/rust@aaa2d47 (original) (raw)

`@@ -7,7 +7,7 @@ use std::sync::Arc;

`

7

7

``

8

8

`use rustc_ast::attr::{AttributeExt, MarkedAttrs};

`

9

9

`use rustc_ast::ptr::P;

`

10

``

`-

use rustc_ast::token::Nonterminal;

`

``

10

`+

use rustc_ast::token::MetaVarKind;

`

11

11

`use rustc_ast::tokenstream::TokenStream;

`

12

12

`use rustc_ast::visit::{AssocCtxt, Visitor};

`

13

13

`use rustc_ast::{self as ast, AttrVec, Attribute, HasAttrs, Item, NodeId, PatKind};

`

`@@ -19,7 +19,7 @@ use rustc_feature::Features;

`

19

19

`use rustc_hir as hir;

`

20

20

`use rustc_lint_defs::{BufferedEarlyLint, RegisteredTools};

`

21

21

`use rustc_parse::MACRO_ARGUMENTS;

`

22

``

`-

use rustc_parse::parser::Parser;

`

``

22

`+

use rustc_parse::parser::{ForceCollect, Parser};

`

23

23

`use rustc_session::config::CollapseMacroDebuginfo;

`

24

24

`use rustc_session::parse::ParseSess;

`

25

25

`use rustc_session::{Limit, Session};

`

`@@ -1405,13 +1405,13 @@ pub fn parse_macro_name_and_helper_attrs(

`

1405

1405

`` /// If this item looks like a specific enums from rental, emit a fatal error.

``

1406

1406

`/// See #73345 and #83125 for more details.

`

1407

1407

`/// 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) {

`

1409

1409

`let name = item.ident.name;

`

1410

1410

`if name == sym::ProceduralMasqueradeDummyType

`

1411

1411

` && let ast::ItemKind::Enum(enum_def, _) = &item.kind

`

1412

1412

` && let [variant] = &*enum_def.variants

`

1413

1413

` && 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)

`

1415

1415

` && let Some(c) = real

`

1416

1416

`.local_path()

`

1417

1417

`.unwrap_or(Path::new(""))

`

`@@ -1429,15 +1429,15 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &Session) {

`

1429

1429

`};

`

1430

1430

``

1431

1431

`if crate_matches {

`

1432

``

`-

sess.dcx().emit_fatal(errors::ProcMacroBackCompat {

`

``

1432

`+

psess.dcx().emit_fatal(errors::ProcMacroBackCompat {

`

1433

1433

`crate_name: "rental".to_string(),

`

1434

1434

`fixed_version: "0.5.6".to_string(),

`

1435

1435

`});

`

1436

1436

`}

`

1437

1437

`}

`

1438

1438

`}

`

1439

1439

``

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) {

`

1441

1441

`let item = match ann {

`

1442

1442

`Annotatable::Item(item) => item,

`

1443

1443

`Annotatable::Stmt(stmt) => match &stmt.kind {

`

`@@ -1446,17 +1446,36 @@ pub(crate) fn ann_pretty_printing_compatibility_hack(ann: &Annotatable, sess: &S

`

1446

1446

`},

`

1447

1447

` _ => return,

`

1448

1448

`};

`

1449

``

`-

pretty_printing_compatibility_hack(item, sess)

`

``

1449

`+

pretty_printing_compatibility_hack(item, psess)

`

1450

1450

`}

`

1451

1451

``

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

`+

}

`

1459

1478

` _ => return,

`

1460

1479

`};

`

1461

``

`-

pretty_printing_compatibility_hack(item, sess)

`

``

1480

`+

pretty_printing_compatibility_hack(&item, psess)

`

1462

1481

`}

`