Auto merge of #137517 - nnethercote:rm-NtPat-NtItem-NtStmt, r= · rust-lang/rust@e6d1e42 (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};

`

`@@ -18,7 +18,7 @@ use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed, PResult};

`

18

18

`use rustc_feature::Features;

`

19

19

`use rustc_lint_defs::{BufferedEarlyLint, RegisteredTools};

`

20

20

`use rustc_parse::MACRO_ARGUMENTS;

`

21

``

`-

use rustc_parse::parser::Parser;

`

``

21

`+

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

`

22

22

`use rustc_session::config::CollapseMacroDebuginfo;

`

23

23

`use rustc_session::parse::ParseSess;

`

24

24

`use rustc_session::{Limit, Session};

`

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

`

1382

1382

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

``

1383

1383

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

`

1384

1384

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

`

1386

1386

`let name = item.ident.name;

`

1387

1387

`if name == sym::ProceduralMasqueradeDummyType

`

1388

1388

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

`

1389

1389

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

`

1390

1390

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

`

1392

1392

` && let Some(c) = real

`

1393

1393

`.local_path()

`

1394

1394

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

`

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

`

1406

1406

`};

`

1407

1407

``

1408

1408

`if crate_matches {

`

1409

``

`-

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

`

``

1409

`+

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

`

1410

1410

`crate_name: "rental".to_string(),

`

1411

1411

`fixed_version: "0.5.6".to_string(),

`

1412

1412

`});

`

1413

1413

`}

`

1414

1414

`}

`

1415

1415

`}

`

1416

1416

``

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

`

1418

1418

`let item = match ann {

`

1419

1419

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

`

1420

1420

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

`

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

`

1423

1423

`},

`

1424

1424

` _ => return,

`

1425

1425

`};

`

1426

``

`-

pretty_printing_compatibility_hack(item, sess)

`

``

1426

`+

pretty_printing_compatibility_hack(item, psess)

`

1427

1427

`}

`

1428

1428

``

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

`+

}

`

1436

1455

` _ => return,

`

1437

1456

`};

`

1438

``

`-

pretty_printing_compatibility_hack(item, sess)

`

``

1457

`+

pretty_printing_compatibility_hack(&item, psess)

`

1439

1458

`}

`