Skip to content

Commit d7ac9fd

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 6bb707a commit d7ac9fd

File tree

19 files changed

+79
-70
lines changed

19 files changed

+79
-70
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
@@ -547,7 +547,6 @@ impl Token {
547547
| Lt | BinOp(Shl) // associated path
548548
| PathSep => true, // global path
549549
Interpolated(ref nt) => matches!(&nt.0, NtLiteral(..) |
550-
NtPat(..) |
551550
NtBlock(..) |
552551
NtPath(..)),
553552
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
@@ -917,7 +916,6 @@ pub enum Nonterminal {
917916
NtItem(P<ast::Item>),
918917
NtBlock(P<ast::Block>),
919918
NtStmt(P<ast::Stmt>),
920-
NtPat(P<ast::Pat>),
921919
NtExpr(P<ast::Expr>),
922920
NtIdent(Ident, IdentIsRaw),
923921
NtLifetime(Ident),
@@ -1011,7 +1009,6 @@ impl Nonterminal {
10111009
NtItem(item) => item.span,
10121010
NtBlock(block) => block.span,
10131011
NtStmt(stmt) => stmt.span,
1014-
NtPat(pat) => pat.span,
10151012
NtExpr(expr) | NtLiteral(expr) => expr.span,
10161013
NtIdent(ident, _) | NtLifetime(ident) => ident.span,
10171014
NtMeta(attr_item) => attr_item.span(),
@@ -1024,7 +1021,6 @@ impl Nonterminal {
10241021
NtItem(..) => "item",
10251022
NtBlock(..) => "block",
10261023
NtStmt(..) => "statement",
1027-
NtPat(..) => "pattern",
10281024
NtExpr(..) => "expression",
10291025
NtLiteral(..) => "literal",
10301026
NtIdent(..) => "identifier",
@@ -1057,7 +1053,6 @@ impl fmt::Debug for Nonterminal {
10571053
NtItem(..) => f.pad("NtItem(..)"),
10581054
NtBlock(..) => f.pad("NtBlock(..)"),
10591055
NtStmt(..) => f.pad("NtStmt(..)"),
1060-
NtPat(..) => f.pad("NtPat(..)"),
10611056
NtExpr(..) => f.pad("NtExpr(..)"),
10621057
NtIdent(..) => f.pad("NtIdent(..)"),
10631058
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 & 3 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,8 +2838,10 @@ impl<'a> Parser<'a> {
28382838

28392839
fn is_named_param(&self) -> bool {
28402840
let offset = match &self.token.kind {
2841-
token::Interpolated(nt) => match &nt.0 {
2842-
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),
28432845
_ => 0,
28442846
},
28452847
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
@@ -1669,6 +1669,8 @@ pub enum FlatToken {
16691669
#[derive(Clone, Debug)]
16701670
pub enum ParseNtResult<NtType> {
16711671
Tt(TokenTree),
1672+
PatParam(P<ast::Pat>, /* inferred */ bool),
1673+
PatWithOr(P<ast::Pat>),
16721674
Ty(P<ast::Ty>),
16731675
Vis(P<ast::Visibility>),
16741676

@@ -1683,6 +1685,8 @@ impl<T> ParseNtResult<T> {
16831685
{
16841686
match self {
16851687
ParseNtResult::Tt(tt) => ParseNtResult::Tt(tt),
1688+
ParseNtResult::PatParam(x, inf) => ParseNtResult::PatParam(x, inf),
1689+
ParseNtResult::PatWithOr(x) => ParseNtResult::PatWithOr(x),
16861690
ParseNtResult::Ty(x) => ParseNtResult::Ty(x),
16871691
ParseNtResult::Vis(x) => ParseNtResult::Vis(x),
16881692
ParseNtResult::Nt(nt) => ParseNtResult::Nt(f(nt)),

0 commit comments

Comments
 (0)