Skip to content

Commit 4574033

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 f1a2ea3 commit 4574033

File tree

18 files changed

+75
-56
lines changed

18 files changed

+75
-56
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(),
@@ -245,7 +244,6 @@ impl HasTokens for Nonterminal {
245244
Nonterminal::NtItem(item) => item.tokens_mut(),
246245
Nonterminal::NtStmt(stmt) => stmt.tokens_mut(),
247246
Nonterminal::NtExpr(expr) | Nonterminal::NtLiteral(expr) => expr.tokens_mut(),
248-
Nonterminal::NtPat(pat) => pat.tokens_mut(),
249247
Nonterminal::NtMeta(attr_item) => attr_item.tokens_mut(),
250248
Nonterminal::NtPath(path) => path.tokens_mut(),
251249
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
@@ -835,7 +835,6 @@ fn visit_nonterminal<T: MutVisitor>(nt: &mut token::Nonterminal, vis: &mut T) {
835835
vis.flat_map_stmt(stmt).expect_one("expected visitor to produce exactly one item")
836836
})
837837
}),
838-
token::NtPat(pat) => vis.visit_pat(pat),
839838
token::NtExpr(expr) => vis.visit_expr(expr),
840839
token::NtLiteral(expr) => vis.visit_expr(expr),
841840
token::NtMeta(item) => {

compiler/rustc_ast/src/token.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,6 @@ impl Token {
561561
| Lt | BinOp(Shl) // associated path
562562
| PathSep => true, // global path
563563
Interpolated(ref nt) => matches!(&**nt, NtLiteral(..) |
564-
NtPat(..) |
565564
NtBlock(..) |
566565
NtPath(..)),
567566
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
@@ -922,7 +921,6 @@ pub enum Nonterminal {
922921
NtItem(P<ast::Item>),
923922
NtBlock(P<ast::Block>),
924923
NtStmt(P<ast::Stmt>),
925-
NtPat(P<ast::Pat>),
926924
NtExpr(P<ast::Expr>),
927925
NtLiteral(P<ast::Expr>),
928926
/// Stuff inside brackets for attributes
@@ -1014,7 +1012,6 @@ impl Nonterminal {
10141012
NtItem(item) => item.span,
10151013
NtBlock(block) => block.span,
10161014
NtStmt(stmt) => stmt.span,
1017-
NtPat(pat) => pat.span,
10181015
NtExpr(expr) | NtLiteral(expr) => expr.span,
10191016
NtMeta(attr_item) => attr_item.span(),
10201017
NtPath(path) => path.span,
@@ -1026,7 +1023,6 @@ impl Nonterminal {
10261023
NtItem(..) => "item",
10271024
NtBlock(..) => "block",
10281025
NtStmt(..) => "statement",
1029-
NtPat(..) => "pattern",
10301026
NtExpr(..) => "expression",
10311027
NtLiteral(..) => "literal",
10321028
NtMeta(..) => "attribute",
@@ -1051,7 +1047,6 @@ impl fmt::Debug for Nonterminal {
10511047
NtItem(..) => f.pad("NtItem(..)"),
10521048
NtBlock(..) => f.pad("NtBlock(..)"),
10531049
NtStmt(..) => f.pad("NtStmt(..)"),
1054-
NtPat(..) => f.pad("NtPat(..)"),
10551050
NtExpr(..) => f.pad("NtExpr(..)"),
10561051
NtLiteral(..) => f.pad("NtLiteral(..)"),
10571052
NtMeta(..) => f.pad("NtMeta(..)"),

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,6 @@ impl TokenStream {
473473
TokenStream::token_alone(token::Semi, stmt.span)
474474
}
475475
Nonterminal::NtStmt(stmt) => TokenStream::from_ast(stmt),
476-
Nonterminal::NtPat(pat) => TokenStream::from_ast(pat),
477476
Nonterminal::NtMeta(attr) => TokenStream::from_ast(attr),
478477
Nonterminal::NtPath(path) => TokenStream::from_ast(path),
479478
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
@@ -859,7 +859,6 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
859859
token::NtItem(e) => self.item_to_string(e),
860860
token::NtBlock(e) => self.block_to_string(e),
861861
token::NtStmt(e) => self.stmt_to_string(e),
862-
token::NtPat(e) => self.pat_to_string(e),
863862
token::NtLiteral(e) => self.expr_to_string(e),
864863
}
865864
}

compiler/rustc_expand/src/mbe/transcribe.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,13 @@ pub(super) fn transcribe<'a>(
283283
let kind = token::NtLifetime(*ident);
284284
TokenTree::token_alone(kind, sp)
285285
}
286+
MatchedSingle(ParseNtResult::PatParam(ref pat, inferred)) => mk_delimited(
287+
NonterminalKind::PatParam { inferred: *inferred },
288+
TokenStream::from_ast(pat),
289+
),
290+
MatchedSingle(ParseNtResult::PatWithOr(ref pat)) => {
291+
mk_delimited(NonterminalKind::PatWithOr, TokenStream::from_ast(pat))
292+
}
286293
MatchedSingle(ParseNtResult::Ty(ref ty)) => {
287294
mk_delimited(NonterminalKind::Ty, TokenStream::from_ast(ty))
288295
}

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ use ast::token::IdentIsRaw;
2525
use rustc_ast as ast;
2626
use rustc_ast::ptr::P;
2727
use rustc_ast::token::{self, Delimiter, Lit, LitKind, Token, TokenKind};
28-
use rustc_ast::tokenstream::AttrTokenTree;
2928
use rustc_ast::util::parser::AssocOp;
3029
use rustc_ast::{
3130
AngleBracketedArg, AngleBracketedArgs, AnonConst, AttrVec, BinOpKind, BindingMode, Block,
32-
BlockCheckMode, Expr, ExprKind, GenericArg, Generics, HasTokens, Item, ItemKind, Param, Pat,
33-
PatKind, Path, PathSegment, QSelf, Recovered, Ty, TyKind,
31+
BlockCheckMode, Expr, ExprKind, GenericArg, Generics, Item, ItemKind, Param, Pat, PatKind,
32+
Path, PathSegment, QSelf, Recovered, Ty, TyKind,
3433
};
3534
use rustc_ast_pretty::pprust;
3635
use rustc_data_structures::fx::FxHashSet;
@@ -2366,6 +2365,8 @@ impl<'a> Parser<'a> {
23662365
}
23672366
err.span_label(span, "expected expression");
23682367

2368+
/* njn: temp disabled, which hurts tests/ui/macros/trace_faulty_macros.rs
2369+
23692370
// Walk the chain of macro expansions for the current token to point at how the original
23702371
// code was interpreted. This helps the user realize when a macro argument of one type is
23712372
// later reinterpreted as a different type, like `$x:expr` being reinterpreted as `$x:pat`
@@ -2411,6 +2412,7 @@ impl<'a> Parser<'a> {
24112412
tokens",
24122413
);
24132414
}
2415+
*/
24142416
err
24152417
}
24162418

compiler/rustc_parse/src/parser/item.rs

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

28572857
fn is_named_param(&self) -> bool {
28582858
let offset = match &self.token.kind {
2859-
token::Interpolated(nt) => match &**nt {
2860-
token::NtPat(..) => return self.look_ahead(1, |t| t == &token::Colon),
2859+
token::OpenDelim(Delimiter::Invisible(origin)) => match origin {
2860+
InvisibleOrigin::MetaVar(
2861+
NonterminalKind::PatParam { .. } | NonterminalKind::PatWithOr,
2862+
) => return self.check_noexpect_past_close_delim(&token::Colon),
28612863
_ => 0,
28622864
},
28632865
token::BinOp(token::And) | token::AndAnd => 1,

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,8 @@ pub enum ParseNtResult {
17131713
Tt(TokenTree),
17141714
Ident(Ident, IdentIsRaw),
17151715
Lifetime(Ident),
1716+
PatParam(P<ast::Pat>, /* inferred */ bool),
1717+
PatWithOr(P<ast::Pat>),
17161718
Ty(P<ast::Ty>),
17171719
Vis(P<ast::Visibility>),
17181720

compiler/rustc_parse/src/parser/nonterminal.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ impl<'a> Parser<'a> {
4747
fn nt_may_be_ident(nt: &Nonterminal) -> bool {
4848
match nt {
4949
NtStmt(_)
50-
| NtPat(_)
5150
| NtExpr(_)
5251
| NtLiteral(_) // `true`, `false`
5352
| NtMeta(_)
@@ -83,7 +82,7 @@ impl<'a> Parser<'a> {
8382
token::NtLifetime(..) => true,
8483
token::Interpolated(nt) => match &**nt {
8584
NtBlock(_) | NtStmt(_) | NtExpr(_) | NtLiteral(_) => true,
86-
NtItem(_) | NtPat(_) | NtMeta(_) | NtPath(_) => false,
85+
NtItem(_) | NtMeta(_) | NtPath(_) => false,
8786
},
8887
token::OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(k))) => match k {
8988
NonterminalKind::Block
@@ -175,19 +174,22 @@ impl<'a> Parser<'a> {
175174
.create_err(UnexpectedNonterminal::Statement(self.token.span)));
176175
}
177176
},
178-
NonterminalKind::PatParam { .. } | NonterminalKind::PatWithOr => {
179-
NtPat(self.collect_tokens_no_attrs(|this| match kind {
180-
NonterminalKind::PatParam { .. } => this.parse_pat_no_top_alt(None, None),
181-
NonterminalKind::PatWithOr => this.parse_pat_allow_top_alt(
177+
NonterminalKind::PatParam { inferred } => {
178+
return Ok(ParseNtResult::PatParam(
179+
self.collect_tokens_no_attrs(|this| this.parse_pat_no_top_alt(None, None))?,
180+
inferred,
181+
));
182+
}
183+
NonterminalKind::PatWithOr => {
184+
return Ok(ParseNtResult::PatWithOr(self.collect_tokens_no_attrs(|this| {
185+
this.parse_pat_allow_top_alt(
182186
None,
183187
RecoverComma::No,
184188
RecoverColon::No,
185189
CommaRecoveryMode::EitherTupleOrPipe,
186-
),
187-
_ => unreachable!(),
188-
})?)
190+
)
191+
})?));
189192
}
190-
191193
NonterminalKind::Expr => NtExpr(self.parse_expr_force_collect()?),
192194
NonterminalKind::Literal => {
193195
// The `:literal` matcher does not support attributes

0 commit comments

Comments
 (0)