Skip to content

Commit c193815

Browse files
committed
Remove NtPat.
XXX: tests/ui/macros/trace_faulty_macros.rs regresses because I haven't fixed `expected_expression_found` properly yet.
1 parent e651a19 commit c193815

File tree

19 files changed

+80
-74
lines changed

19 files changed

+80
-74
lines changed

compiler/rustc_ast/src/ast_traits.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ impl HasTokens for Nonterminal {
234234
Nonterminal::NtItem(item) => item.tokens(),
235235
Nonterminal::NtStmt(stmt) => stmt.tokens(),
236236
Nonterminal::NtExpr(expr) | Nonterminal::NtLiteral(expr) => expr.tokens(),
237-
Nonterminal::NtPat(pat) => pat.tokens(),
238237
Nonterminal::NtMeta(attr_item) => attr_item.tokens(),
239238
Nonterminal::NtPath(path) => path.tokens(),
240239
Nonterminal::NtBlock(block) => block.tokens(),
@@ -246,7 +245,6 @@ impl HasTokens for Nonterminal {
246245
Nonterminal::NtItem(item) => item.tokens_mut(),
247246
Nonterminal::NtStmt(stmt) => stmt.tokens_mut(),
248247
Nonterminal::NtExpr(expr) | Nonterminal::NtLiteral(expr) => expr.tokens_mut(),
249-
Nonterminal::NtPat(pat) => pat.tokens_mut(),
250248
Nonterminal::NtMeta(attr_item) => attr_item.tokens_mut(),
251249
Nonterminal::NtPath(path) => path.tokens_mut(),
252250
Nonterminal::NtBlock(block) => block.tokens_mut(),

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,6 @@ pub fn visit_nonterminal<T: MutVisitor>(nt: &mut token::Nonterminal, vis: &mut T
836836
vis.flat_map_stmt(stmt).expect_one("expected visitor to produce exactly one item")
837837
})
838838
}),
839-
token::NtPat(pat) => vis.visit_pat(pat),
840839
token::NtExpr(expr) => vis.visit_expr(expr),
841840
token::NtIdent(ident, _is_raw) => vis.visit_ident(ident),
842841
token::NtLifetime(ident) => vis.visit_ident(ident),

compiler/rustc_ast/src/token.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,6 @@ impl Token {
551551
| Lt | BinOp(Shl) // associated path
552552
| PathSep => true, // global path
553553
Interpolated(ref nt) => matches!(&nt.0, NtLiteral(..) |
554-
NtPat(..) |
555554
NtBlock(..) |
556555
NtPath(..)),
557556
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
@@ -928,7 +927,6 @@ pub enum Nonterminal {
928927
NtItem(P<ast::Item>),
929928
NtBlock(P<ast::Block>),
930929
NtStmt(P<ast::Stmt>),
931-
NtPat(P<ast::Pat>),
932930
NtExpr(P<ast::Expr>),
933931
NtIdent(Ident, IdentIsRaw),
934932
NtLifetime(Ident),
@@ -1022,7 +1020,6 @@ impl Nonterminal {
10221020
NtItem(item) => item.span,
10231021
NtBlock(block) => block.span,
10241022
NtStmt(stmt) => stmt.span,
1025-
NtPat(pat) => pat.span,
10261023
NtExpr(expr) | NtLiteral(expr) => expr.span,
10271024
NtIdent(ident, _) | NtLifetime(ident) => ident.span,
10281025
NtMeta(attr_item) => attr_item.span(),
@@ -1035,7 +1032,6 @@ impl Nonterminal {
10351032
NtItem(..) => "item",
10361033
NtBlock(..) => "block",
10371034
NtStmt(..) => "statement",
1038-
NtPat(..) => "pattern",
10391035
NtExpr(..) => "expression",
10401036
NtLiteral(..) => "literal",
10411037
NtIdent(..) => "identifier",
@@ -1068,7 +1064,6 @@ impl fmt::Debug for Nonterminal {
10681064
NtItem(..) => f.pad("NtItem(..)"),
10691065
NtBlock(..) => f.pad("NtBlock(..)"),
10701066
NtStmt(..) => f.pad("NtStmt(..)"),
1071-
NtPat(..) => f.pad("NtPat(..)"),
10721067
NtExpr(..) => f.pad("NtExpr(..)"),
10731068
NtIdent(..) => f.pad("NtIdent(..)"),
10741069
NtLiteral(..) => f.pad("NtLiteral(..)"),

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,6 @@ impl TokenStream {
480480
TokenStream::token_alone(token::Semi, stmt.span)
481481
}
482482
Nonterminal::NtStmt(stmt) => TokenStream::from_ast(stmt),
483-
Nonterminal::NtPat(pat) => TokenStream::from_ast(pat),
484483
Nonterminal::NtMeta(attr) => TokenStream::from_ast(attr),
485484
Nonterminal::NtPath(path) => TokenStream::from_ast(path),
486485
Nonterminal::NtExpr(expr) | Nonterminal::NtLiteral(expr) => TokenStream::from_ast(expr),

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,6 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
850850
token::NtItem(e) => self.item_to_string(e),
851851
token::NtBlock(e) => self.block_to_string(e),
852852
token::NtStmt(e) => self.stmt_to_string(e),
853-
token::NtPat(e) => self.pat_to_string(e),
854853
&token::NtIdent(e, is_raw) => IdentPrinter::for_ast_ident(e, is_raw.into()).to_string(),
855854
token::NtLifetime(e) => e.to_string(),
856855
token::NtLiteral(e) => self.expr_to_string(e),

compiler/rustc_expand/src/mbe/transcribe.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,13 @@ pub(super) fn transcribe<'a>(
266266
// without wrapping them into groups.
267267
maybe_use_metavar_location(cx, &stack, sp, tt, &mut marker)
268268
}
269+
MatchedSingle(ParseNtResult::PatParam(ref pat, inferred)) => mk_delimited(
270+
NonterminalKind::PatParam { inferred: *inferred },
271+
TokenStream::from_ast(pat),
272+
),
273+
MatchedSingle(ParseNtResult::PatWithOr(ref pat)) => {
274+
mk_delimited(NonterminalKind::PatWithOr, TokenStream::from_ast(pat))
275+
}
269276
MatchedSingle(ParseNtResult::Ty(ref ty)) => {
270277
mk_delimited(NonterminalKind::Ty, TokenStream::from_ast(ty))
271278
}

compiler/rustc_parse/src/errors.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,9 +1143,7 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for ExpectedSemi {
11431143
Some(TokenDescription::DocComment) => {
11441144
fluent::parse_expected_semi_found_doc_comment_str
11451145
}
1146-
Some(TokenDescription::MetaVar(_)) => {
1147-
fluent::parse_expected_semi_found_metavar_str
1148-
}
1146+
Some(TokenDescription::MetaVar(_)) => fluent::parse_expected_semi_found_metavar_str,
11491147
None => fluent::parse_expected_semi_found_str,
11501148
},
11511149
);

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ use parser::Recovered;
2626
use rustc_ast as ast;
2727
use rustc_ast::ptr::P;
2828
use rustc_ast::token::{self, Delimiter, Lit, LitKind, Token, TokenKind};
29-
use rustc_ast::tokenstream::AttrTokenTree;
3029
use rustc_ast::util::parser::AssocOp;
3130
use rustc_ast::{
3231
AngleBracketedArg, AngleBracketedArgs, AnonConst, AttrVec, BinOpKind, BindingAnnotation, Block,
33-
BlockCheckMode, Expr, ExprKind, GenericArg, Generics, HasTokens, Item, ItemKind, Param, Pat,
34-
PatKind, Path, PathSegment, QSelf, Ty, TyKind,
32+
BlockCheckMode, Expr, ExprKind, GenericArg, Generics, Item, ItemKind, Param, Pat, PatKind,
33+
Path, PathSegment, QSelf, Ty, TyKind,
3534
};
3635
use rustc_ast_pretty::pprust;
3736
use rustc_data_structures::fx::FxHashSet;
@@ -2363,15 +2362,14 @@ impl<'a> Parser<'a> {
23632362
}
23642363
err.span_label(span, "expected expression");
23652364

2365+
/* njn: temp disabled, which hurts tests/ui/macros/trace_faulty_macros.rs
2366+
23662367
// Walk the chain of macro expansions for the current token to point at how the original
23672368
// code was interpreted. This helps the user realize when a macro argument of one type is
23682369
// later reinterpreted as a different type, like `$x:expr` being reinterpreted as `$x:pat`
23692370
// in a subsequent macro invocation (#71039).
23702371
let mut tok = self.token.clone();
23712372
let mut labels = vec![];
2372-
if let token::OpenDelim(Delimiter::Invisible(_)) = &tok.kind {
2373-
panic!("njn: invis-delim?");
2374-
}
23752373
while let TokenKind::Interpolated(node) = &tok.kind {
23762374
let tokens = node.0.tokens();
23772375
labels.push(node.clone());
@@ -2381,9 +2379,6 @@ impl<'a> Parser<'a> {
23812379
&& let [AttrTokenTree::Token(token, _)] = &tokens[..]
23822380
{
23832381
tok = token.clone();
2384-
if let token::OpenDelim(Delimiter::Invisible(_)) = &tok.kind {
2385-
panic!("njn: invis-delim?");
2386-
}
23872382
} else {
23882383
break;
23892384
}
@@ -2421,6 +2416,7 @@ impl<'a> Parser<'a> {
24212416
tokens",
24222417
);
24232418
}
2419+
*/
24242420
err
24252421
}
24262422

compiler/rustc_parse/src/parser/item.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::maybe_whole;
1010
use ast::token::IdentIsRaw;
1111
use rustc_ast::ast::*;
1212
use rustc_ast::ptr::P;
13-
use rustc_ast::token::{self, Delimiter, TokenKind};
13+
use rustc_ast::token::{self, Delimiter, InvisibleOrigin, NonterminalKind, TokenKind};
1414
use rustc_ast::tokenstream::{DelimSpan, TokenStream, TokenTree};
1515
use rustc_ast::util::case::Case;
1616
use rustc_ast::{self as ast};
@@ -2838,9 +2838,10 @@ impl<'a> Parser<'a> {
28382838

28392839
fn is_named_param(&self) -> bool {
28402840
let offset = match &self.token.kind {
2841-
// njn: nothing to do, just handle NtPat later
2842-
token::Interpolated(nt) => match &nt.0 {
2843-
token::NtPat(..) => return self.look_ahead(1, |t| t == &token::Colon),
2841+
token::OpenDelim(Delimiter::Invisible(origin)) => match origin {
2842+
InvisibleOrigin::MetaVar(
2843+
NonterminalKind::PatParam { .. } | NonterminalKind::PatWithOr,
2844+
) => return self.check_noexpect_past_close_delim(&token::Colon),
28442845
_ => 0,
28452846
},
28462847
token::BinOp(token::And) | token::AndAnd => 1,

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,8 @@ pub enum FlatToken {
16791679
#[derive(Clone, Debug)]
16801680
pub enum ParseNtResult<NtType> {
16811681
Tt(TokenTree),
1682+
PatParam(P<ast::Pat>, /* inferred */ bool),
1683+
PatWithOr(P<ast::Pat>),
16821684
Ty(P<ast::Ty>),
16831685
Vis(P<ast::Visibility>),
16841686

@@ -1693,6 +1695,8 @@ impl<T> ParseNtResult<T> {
16931695
{
16941696
match self {
16951697
ParseNtResult::Tt(tt) => ParseNtResult::Tt(tt),
1698+
ParseNtResult::PatParam(x, inf) => ParseNtResult::PatParam(x, inf),
1699+
ParseNtResult::PatWithOr(x) => ParseNtResult::PatWithOr(x),
16961700
ParseNtResult::Ty(x) => ParseNtResult::Ty(x),
16971701
ParseNtResult::Vis(x) => ParseNtResult::Vis(x),
16981702
ParseNtResult::Nt(nt) => ParseNtResult::Nt(f(nt)),

0 commit comments

Comments
 (0)