Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9a63a42

Browse files
committed
Remove aSpan fromTokenKind::Interpolated.
This span records the declaration of the metavariable in the LHS of the macro.It's used in a couple of error messages. Unfortunately, it gets in the way ofthe long-term goal of removing `TokenKind::Interpolated`. So this commitremoves it, which degrades a couple of (obscure) error messages but makesthings simpler and enables the next commit.
1 parent852a78e commit9a63a42

File tree

19 files changed

+62
-97
lines changed

19 files changed

+62
-97
lines changed

‎compiler/rustc_ast/src/attr/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ impl MetaItem {
345345
let span = span.with_hi(segments.last().unwrap().ident.span.hi());
346346
Path{ span, segments,tokens:None}
347347
}
348-
Some(TokenTree::Token(Token{kind: token::Interpolated(nt), ..}, _)) =>match&nt.0{
348+
Some(TokenTree::Token(Token{kind: token::Interpolated(nt), ..}, _)) =>match&**nt{
349349
token::Nonterminal::NtMeta(item) =>return item.meta(item.path.span),
350350
token::Nonterminal::NtPath(path) =>(**path).clone(),
351351
_ =>returnNone,

‎compiler/rustc_ast/src/mut_visit.rs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,8 +783,6 @@ pub fn visit_token<T: MutVisitor>(t: &mut Token, vis: &mut T) {
783783
}
784784
token::Interpolated(nt) =>{
785785
let nt =Lrc::make_mut(nt);
786-
let(nt, sp) =(&mut nt.0,&mut nt.1);
787-
vis.visit_span(sp);
788786
visit_nonterminal(nt, vis);
789787
}
790788
_ =>{}

‎compiler/rustc_ast/src/token.rs‎

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl Lit {
111111
Ident(name,IdentIsRaw::No)if name.is_bool_lit() =>Some(Lit::new(Bool, name,None)),
112112
Literal(token_lit) =>Some(token_lit),
113113
Interpolated(ref nt)
114-
ifletNtExpr(expr) |NtLiteral(expr) =&nt.0
114+
ifletNtExpr(expr) |NtLiteral(expr) =&**nt
115115
&&let ast::ExprKind::Lit(token_lit) = expr.kind =>
116116
{
117117
Some(token_lit)
@@ -333,7 +333,11 @@ pub enum TokenKind {
333333
/// - It prevents `Token` from implementing `Copy`.
334334
/// It adds complexity and likely slows things down. Please don't add new
335335
/// occurrences of this token kind!
336-
Interpolated(Lrc<(Nonterminal,Span)>),
336+
///
337+
/// The span in the surrounding `Token` is that of the metavariable in the
338+
/// macro's RHS. The span within the Nonterminal is that of the fragment
339+
/// passed to the macro at the call site.
340+
Interpolated(Lrc<Nonterminal>),
337341

338342
/// A doc comment token.
339343
/// `Symbol` is the doc comment's data excluding its "quotes" (`///`, `/**`, etc)
@@ -441,7 +445,7 @@ impl Token {
441445
/// if they keep spans or perform edition checks.
442446
pubfnuninterpolated_span(&self) ->Span{
443447
match&self.kind{
444-
Interpolated(nt) => nt.0.use_span(),
448+
Interpolated(nt) => nt.use_span(),
445449
_ =>self.span,
446450
}
447451
}
@@ -486,7 +490,7 @@ impl Token {
486490
PathSep |// global path
487491
Lifetime(..) |// labeled loop
488492
Pound =>true,// expression attributes
489-
Interpolated(ref nt) =>matches!(&nt.0,NtLiteral(..) |
493+
Interpolated(ref nt) =>matches!(&**nt,NtLiteral(..) |
490494
NtExpr(..) |
491495
NtBlock(..) |
492496
NtPath(..)),
@@ -510,7 +514,7 @@ impl Token {
510514
|DotDot |DotDotDot |DotDotEq// ranges
511515
|Lt |BinOp(Shl)// associated path
512516
|PathSep =>true,// global path
513-
Interpolated(ref nt) =>matches!(&nt.0,NtLiteral(..) |
517+
Interpolated(ref nt) =>matches!(&**nt,NtLiteral(..) |
514518
NtPat(..) |
515519
NtBlock(..) |
516520
NtPath(..)),
@@ -533,7 +537,7 @@ impl Token {
533537
Lifetime(..) |// lifetime bound in trait object
534538
Lt |BinOp(Shl) |// associated path
535539
PathSep =>true,// global path
536-
Interpolated(ref nt) =>matches!(&nt.0,NtTy(..) |NtPath(..)),
540+
Interpolated(ref nt) =>matches!(&**nt,NtTy(..) |NtPath(..)),
537541
// For anonymous structs or unions, which only appear in specific positions
538542
// (type of struct fields or union fields), we don't consider them as regular types
539543
_ =>false,
@@ -544,7 +548,7 @@ impl Token {
544548
pubfncan_begin_const_arg(&self) ->bool{
545549
matchself.kind{
546550
OpenDelim(Delimiter::Brace) =>true,
547-
Interpolated(ref nt) =>matches!(&nt.0,NtExpr(..) |NtBlock(..) |NtLiteral(..)),
551+
Interpolated(ref nt) =>matches!(&**nt,NtExpr(..) |NtBlock(..) |NtLiteral(..)),
548552
_ =>self.can_begin_literal_maybe_minus(),
549553
}
550554
}
@@ -589,7 +593,7 @@ impl Token {
589593
matchself.uninterpolate().kind{
590594
Literal(..) |BinOp(Minus) =>true,
591595
Ident(name,IdentIsRaw::No)if name.is_bool_lit() =>true,
592-
Interpolated(ref nt) =>match&nt.0{
596+
Interpolated(ref nt) =>match&**nt{
593597
NtLiteral(_) =>true,
594598
NtExpr(e) =>match&e.kind{
595599
ast::ExprKind::Lit(_) =>true,
@@ -610,7 +614,7 @@ impl Token {
610614
/// otherwise returns the original token.
611615
pubfnuninterpolate(&self) ->Cow<'_,Token>{
612616
match&self.kind{
613-
Interpolated(nt) =>match&nt.0{
617+
Interpolated(nt) =>match&**nt{
614618
NtIdent(ident, is_raw) =>{
615619
Cow::Owned(Token::new(Ident(ident.name,*is_raw), ident.span))
616620
}
@@ -627,7 +631,7 @@ impl Token {
627631
// We avoid using `Token::uninterpolate` here because it's slow.
628632
match&self.kind{
629633
&Ident(name, is_raw) =>Some((Ident::new(name,self.span), is_raw)),
630-
Interpolated(nt) =>match&nt.0{
634+
Interpolated(nt) =>match&**nt{
631635
NtIdent(ident, is_raw) =>Some((*ident,*is_raw)),
632636
_ =>None,
633637
},
@@ -641,7 +645,7 @@ impl Token {
641645
// We avoid using `Token::uninterpolate` here because it's slow.
642646
match&self.kind{
643647
&Lifetime(name) =>Some(Ident::new(name,self.span)),
644-
Interpolated(nt) =>match&nt.0{
648+
Interpolated(nt) =>match&**nt{
645649
NtLifetime(ident) =>Some(*ident),
646650
_ =>None,
647651
},
@@ -668,7 +672,7 @@ impl Token {
668672
/// Returns `true` if the token is an interpolated path.
669673
fnis_whole_path(&self) ->bool{
670674
ifletInterpolated(nt) =&self.kind
671-
&&letNtPath(..) =&nt.0
675+
&&letNtPath(..) =&**nt
672676
{
673677
returntrue;
674678
}
@@ -681,7 +685,7 @@ impl Token {
681685
/// (which happens while parsing the result of macro expansion)?
682686
pubfnis_whole_expr(&self) ->bool{
683687
ifletInterpolated(nt) =&self.kind
684-
&&letNtExpr(_) |NtLiteral(_) |NtPath(_) |NtBlock(_) =&nt.0
688+
&&letNtExpr(_) |NtLiteral(_) |NtPath(_) |NtBlock(_) =&**nt
685689
{
686690
returntrue;
687691
}
@@ -692,7 +696,7 @@ impl Token {
692696
/// Is the token an interpolated block (`$b:block`)?
693697
pubfnis_whole_block(&self) ->bool{
694698
ifletInterpolated(nt) =&self.kind
695-
&&letNtBlock(..) =&nt.0
699+
&&letNtBlock(..) =&**nt
696700
{
697701
returntrue;
698702
}
@@ -857,6 +861,7 @@ pub enum Nonterminal {
857861
NtPat(P<ast::Pat>),
858862
NtExpr(P<ast::Expr>),
859863
NtTy(P<ast::Ty>),
864+
/// The span is for the identifier argument passed to the macro.
860865
NtIdent(Ident,IdentIsRaw),
861866
NtLifetime(Ident),
862867
NtLiteral(P<ast::Expr>),

‎compiler/rustc_ast/src/tokenstream.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,14 +490,14 @@ impl TokenStream {
490490

491491
fnflatten_token(token:&Token,spacing:Spacing) ->TokenTree{
492492
match&token.kind{
493-
token::Interpolated(nt)iflet token::NtIdent(ident, is_raw) =nt.0 =>{
494-
TokenTree::Token(Token::new(token::Ident(ident.name, is_raw), ident.span), spacing)
493+
token::Interpolated(nt)iflet token::NtIdent(ident, is_raw) =&**nt =>{
494+
TokenTree::Token(Token::new(token::Ident(ident.name,*is_raw), ident.span), spacing)
495495
}
496496
token::Interpolated(nt) =>TokenTree::Delimited(
497497
DelimSpan::from_single(token.span),
498498
DelimSpacing::new(Spacing::JointHidden, spacing),
499499
Delimiter::Invisible,
500-
TokenStream::from_nonterminal_ast(&nt.0).flattened(),
500+
TokenStream::from_nonterminal_ast(&nt).flattened(),
501501
),
502502
_ =>TokenTree::Token(token.clone(), spacing),
503503
}

‎compiler/rustc_ast_pretty/src/pprust/state.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
926926
}
927927
token::Eof =>"<eof>".into(),
928928

929-
token::Interpolated(ref nt) =>self.nonterminal_to_string(&nt.0).into(),
929+
token::Interpolated(ref nt) =>self.nonterminal_to_string(&nt).into(),
930930
}
931931
}
932932

‎compiler/rustc_expand/src/mbe/diagnostics.rs‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ pub(super) fn failed_to_match_macro<'cx>(
7373
&&(matches!(expected_token.kind,TokenKind::Interpolated(_))
7474
||matches!(token.kind,TokenKind::Interpolated(_)))
7575
{
76-
ifletTokenKind::Interpolated(node) =&expected_token.kind{
77-
err.span_label(node.1,"");
78-
}
79-
ifletTokenKind::Interpolated(node) =&token.kind{
80-
err.span_label(node.1,"");
81-
}
8276
err.note("captured metavariables except for `:tt`, `:ident` and `:lifetime` cannot be compared to other tokens");
8377
err.note("see <https://doc.rust-lang.org/nightly/reference/macros-by-example.html#forwarding-a-matched-fragment> for more information");
8478

‎compiler/rustc_expand/src/mbe/macro_parser.rs‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,9 @@ pub(crate) use ParseResult::*;
7575

7676
usecrate::mbe::{macro_rules::Tracker,KleeneOp,TokenTree};
7777

78-
use rustc_ast::token::{self,DocComment,Nonterminal,NonterminalKind,Token};
78+
use rustc_ast::token::{self,DocComment,NonterminalKind,Token};
7979
use rustc_ast_pretty::pprust;
8080
use rustc_data_structures::fx::FxHashMap;
81-
use rustc_data_structures::sync::Lrc;
8281
use rustc_errors::ErrorGuaranteed;
8382
use rustc_lint_defs::pluralize;
8483
use rustc_parse::parser::{ParseNtResult,Parser};
@@ -392,7 +391,7 @@ pub(super) fn count_metavar_decls(matcher: &[TokenTree]) -> usize {
392391
#[derive(Debug,Clone)]
393392
pub(crate)enumNamedMatch{
394393
MatchedSeq(Vec<NamedMatch>),
395-
MatchedSingle(ParseNtResult<Lrc<(Nonterminal,Span)>>),
394+
MatchedSingle(ParseNtResult),
396395
}
397396

398397
/// Performs a token equality check, ignoring syntax context (that is, an unhygienic comparison)
@@ -686,11 +685,7 @@ impl TtParser {
686685
}
687686
Ok(nt) => nt,
688687
};
689-
mp.push_match(
690-
next_metavar,
691-
seq_depth,
692-
MatchedSingle(nt.map_nt(|nt|(Lrc::new((nt, span))))),
693-
);
688+
mp.push_match(next_metavar, seq_depth,MatchedSingle(nt));
694689
mp.idx +=1;
695690
}else{
696691
unreachable!()

‎compiler/rustc_expand/src/proc_macro.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl MultiItemModifier for DeriveProcMacro {
127127
Annotatable::Stmt(stmt) => token::NtStmt(stmt),
128128
_ =>unreachable!(),
129129
};
130-
TokenStream::token_alone(token::Interpolated(Lrc::new((nt, span))),DUMMY_SP)
130+
TokenStream::token_alone(token::Interpolated(Lrc::new(nt)),DUMMY_SP)
131131
}else{
132132
item.to_tokens()
133133
};

‎compiler/rustc_expand/src/proc_macro_server.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl FromInternal<(TokenStream, &mut Rustc<'_, '_>)> for Vec<TokenTree<TokenStre
259259
}));
260260
}
261261

262-
Interpolated(ref nt)ifletNtIdent(ident, is_raw) =&nt.0 =>{
262+
Interpolated(ref nt)ifletNtIdent(ident, is_raw) =&**nt =>{
263263
trees.push(TokenTree::Ident(Ident{
264264
sym: ident.name,
265265
is_raw:matches!(is_raw,IdentIsRaw::Yes),
@@ -268,14 +268,14 @@ impl FromInternal<(TokenStream, &mut Rustc<'_, '_>)> for Vec<TokenTree<TokenStre
268268
}
269269

270270
Interpolated(nt) =>{
271-
let stream =TokenStream::from_nonterminal_ast(&nt.0);
271+
let stream =TokenStream::from_nonterminal_ast(&nt);
272272
// A hack used to pass AST fragments to attribute and derive
273273
// macros as a single nonterminal token instead of a token
274274
// stream. Such token needs to be "unwrapped" and not
275275
// represented as a delimited group.
276276
// FIXME: It needs to be removed, but there are some
277277
// compatibility issues (see #73345).
278-
ifcrate::base::nt_pretty_printing_compatibility_hack(&nt.0, rustc.ecx.sess){
278+
ifcrate::base::nt_pretty_printing_compatibility_hack(&nt, rustc.ecx.sess){
279279
trees.extend(Self::from_internal((stream, rustc)));
280280
}else{
281281
trees.push(TokenTree::Group(Group{

‎compiler/rustc_parse/src/parser/attr.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ impl<'a> Parser<'a> {
363363
// We can't use `maybe_whole` here because it would bump in the `None`
364364
// case, which we don't want.
365365
iflet token::Interpolated(nt) =&self.token.kind
366-
&&let token::NtMeta(attr_item) =&nt.0
366+
&&let token::NtMeta(attr_item) =&**nt
367367
{
368368
match attr_item.meta(attr_item.path.span){
369369
Some(meta) =>{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp