Skip to content

Commit aa7d45d

Browse files
committed
Remove Parser::missing_fragment_specifier.
1 parent c2afaba commit aa7d45d

File tree

5 files changed

+27
-62
lines changed

5 files changed

+27
-62
lines changed

compiler/rustc_expand/src/mbe/macro_check.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ use rustc_ast::token::{DelimToken, Token, TokenKind};
110110
use rustc_ast::{NodeId, DUMMY_NODE_ID};
111111
use rustc_data_structures::fx::FxHashMap;
112112
use rustc_errors::MultiSpan;
113-
use rustc_session::lint::builtin::META_VARIABLE_MISUSE;
113+
use rustc_session::lint::builtin::{META_VARIABLE_MISUSE, MISSING_FRAGMENT_SPECIFIER};
114114
use rustc_session::parse::ParseSess;
115115
use rustc_span::symbol::kw;
116116
use rustc_span::{symbol::MacroRulesNormalizedIdent, Span};
@@ -261,7 +261,16 @@ fn check_binders(
261261
}
262262
}
263263
// Similarly, this can only happen when checking a toplevel macro.
264-
TokenTree::MetaVarDecl(span, name, _kind) => {
264+
TokenTree::MetaVarDecl(span, name, kind) => {
265+
if kind.is_none() {
266+
sess.buffer_lint(
267+
MISSING_FRAGMENT_SPECIFIER,
268+
span,
269+
node_id,
270+
&format!("missing fragment specifier"),
271+
);
272+
*valid = false;
273+
}
265274
if !macros.is_empty() {
266275
sess.span_diagnostic.span_bug(span, "unexpected MetaVarDecl in nested lhs");
267276
}

compiler/rustc_expand/src/mbe/macro_parser.rs

+15-37
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub(super) enum MatcherLoc {
131131
MetaVarDecl {
132132
span: Span,
133133
bind: Ident,
134-
kind: Option<NonterminalKind>,
134+
kind: NonterminalKind,
135135
next_metavar: usize,
136136
seq_depth: usize,
137137
},
@@ -189,7 +189,7 @@ pub(super) fn compute_locs(sess: &ParseSess, matcher: &[TokenTree]) -> Vec<Match
189189
locs.push(MatcherLoc::MetaVarDecl {
190190
span,
191191
bind,
192-
kind,
192+
kind: kind.unwrap(), // presence was checked for earlier
193193
next_metavar: *next_metavar,
194194
seq_depth,
195195
});
@@ -409,7 +409,6 @@ impl TtParser {
409409
/// track of through the mps generated.
410410
fn parse_tt_inner(
411411
&mut self,
412-
sess: &ParseSess,
413412
matcher: &[MatcherLoc],
414413
token: &Token,
415414
) -> Option<NamedParseResult> {
@@ -508,20 +507,12 @@ impl TtParser {
508507
mp.idx = idx_first;
509508
self.cur_mps.push(mp);
510509
}
511-
&MatcherLoc::MetaVarDecl { span, kind, .. } => {
510+
&MatcherLoc::MetaVarDecl { kind, .. } => {
512511
// Built-in nonterminals never start with these tokens, so we can eliminate
513512
// them from consideration. We use the span of the metavariable declaration
514513
// to determine any edition-specific matching behavior for non-terminals.
515-
if let Some(kind) = kind {
516-
if Parser::nonterminal_may_begin_with(kind, token) {
517-
self.bb_mps.push(mp);
518-
}
519-
} else {
520-
// Both this check and the one in `nameize` are necessary, surprisingly.
521-
if sess.missing_fragment_specifiers.borrow_mut().remove(&span).is_some() {
522-
// E.g. `$e` instead of `$e:expr`.
523-
return Some(Error(span, "missing fragment specifier".to_string()));
524-
}
514+
if Parser::nonterminal_may_begin_with(kind, token) {
515+
self.bb_mps.push(mp);
525516
}
526517
}
527518
MatcherLoc::Eof => {
@@ -547,7 +538,7 @@ impl TtParser {
547538
// Need to take ownership of the matches from within the `Lrc`.
548539
Lrc::make_mut(&mut eof_mp.matches);
549540
let matches = Lrc::try_unwrap(eof_mp.matches).unwrap().into_iter();
550-
self.nameize(sess, matcher, matches)
541+
self.nameize(matcher, matches)
551542
}
552543
EofMatcherPositions::Multiple => {
553544
Error(token.span, "ambiguity: multiple successful parses".to_string())
@@ -585,7 +576,7 @@ impl TtParser {
585576

586577
// Process `cur_mps` until either we have finished the input or we need to get some
587578
// parsing from the black-box parser done.
588-
if let Some(res) = self.parse_tt_inner(&parser.sess, matcher, &parser.token) {
579+
if let Some(res) = self.parse_tt_inner(matcher, &parser.token) {
589580
return res;
590581
}
591582

@@ -615,11 +606,7 @@ impl TtParser {
615606
let mut mp = self.bb_mps.pop().unwrap();
616607
let loc = &matcher[mp.idx];
617608
if let &MatcherLoc::MetaVarDecl {
618-
span,
619-
kind: Some(kind),
620-
next_metavar,
621-
seq_depth,
622-
..
609+
span, kind, next_metavar, seq_depth, ..
623610
} = loc
624611
{
625612
// We use the span of the metavariable declaration to determine any
@@ -668,7 +655,7 @@ impl TtParser {
668655
.bb_mps
669656
.iter()
670657
.map(|mp| match &matcher[mp.idx] {
671-
MatcherLoc::MetaVarDecl { bind, kind: Some(kind), .. } => {
658+
MatcherLoc::MetaVarDecl { bind, kind, .. } => {
672659
format!("{} ('{}')", kind, bind)
673660
}
674661
_ => unreachable!(),
@@ -692,29 +679,20 @@ impl TtParser {
692679

693680
fn nameize<I: Iterator<Item = NamedMatch>>(
694681
&self,
695-
sess: &ParseSess,
696682
matcher: &[MatcherLoc],
697683
mut res: I,
698684
) -> NamedParseResult {
699685
// Make that each metavar has _exactly one_ binding. If so, insert the binding into the
700686
// `NamedParseResult`. Otherwise, it's an error.
701687
let mut ret_val = FxHashMap::default();
702688
for loc in matcher {
703-
if let &MatcherLoc::MetaVarDecl { span, bind, kind, .. } = loc {
704-
if kind.is_some() {
705-
match ret_val.entry(MacroRulesNormalizedIdent::new(bind)) {
706-
Vacant(spot) => spot.insert(res.next().unwrap()),
707-
Occupied(..) => {
708-
return Error(span, format!("duplicated bind name: {}", bind));
709-
}
710-
};
711-
} else {
712-
// Both this check and the one in `parse_tt_inner` are necessary, surprisingly.
713-
if sess.missing_fragment_specifiers.borrow_mut().remove(&span).is_some() {
714-
// E.g. `$e` instead of `$e:expr`.
715-
return Error(span, "missing fragment specifier".to_string());
689+
if let &MatcherLoc::MetaVarDecl { span, bind, .. } = loc {
690+
match ret_val.entry(MacroRulesNormalizedIdent::new(bind)) {
691+
Vacant(spot) => spot.insert(res.next().unwrap()),
692+
Occupied(..) => {
693+
return Error(span, format!("duplicated bind name: {}", bind));
716694
}
717-
}
695+
};
718696
}
719697
}
720698
Success(ret_val)

compiler/rustc_expand/src/mbe/quoted.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::mbe::{Delimited, KleeneOp, KleeneToken, MetaVarExpr, SequenceRepetiti
33

44
use rustc_ast::token::{self, Token};
55
use rustc_ast::tokenstream;
6-
use rustc_ast::{NodeId, DUMMY_NODE_ID};
6+
use rustc_ast::NodeId;
77
use rustc_ast_pretty::pprust;
88
use rustc_feature::Features;
99
use rustc_session::parse::{feature_err, ParseSess};
@@ -102,10 +102,6 @@ pub(super) fn parse(
102102
}
103103
tree => tree.as_ref().map_or(start_sp, tokenstream::TokenTree::span),
104104
};
105-
if node_id != DUMMY_NODE_ID {
106-
// Macros loaded from other crates have dummy node ids.
107-
sess.missing_fragment_specifiers.borrow_mut().insert(span, node_id);
108-
}
109105
result.push(TokenTree::MetaVarDecl(span, ident, None));
110106
}
111107

compiler/rustc_interface/src/passes.rs

-16
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use rustc_resolve::{Resolver, ResolverArenas};
3030
use rustc_serialize::json;
3131
use rustc_session::config::{CrateType, Input, OutputFilenames, OutputType};
3232
use rustc_session::cstore::{MetadataLoader, MetadataLoaderDyn};
33-
use rustc_session::lint;
3433
use rustc_session::output::{filename_for_input, filename_for_metadata};
3534
use rustc_session::search_paths::PathKind;
3635
use rustc_session::{Limit, Session};
@@ -349,23 +348,8 @@ pub fn configure_and_expand(
349348
ecx.check_unused_macros();
350349
});
351350

352-
let mut missing_fragment_specifiers: Vec<_> = ecx
353-
.sess
354-
.parse_sess
355-
.missing_fragment_specifiers
356-
.borrow()
357-
.iter()
358-
.map(|(span, node_id)| (*span, *node_id))
359-
.collect();
360-
missing_fragment_specifiers.sort_unstable_by_key(|(span, _)| *span);
361-
362351
let recursion_limit_hit = ecx.reduced_recursion_limit.is_some();
363352

364-
for (span, node_id) in missing_fragment_specifiers {
365-
let lint = lint::builtin::MISSING_FRAGMENT_SPECIFIER;
366-
let msg = "missing fragment specifier";
367-
resolver.lint_buffer().buffer_lint(lint, node_id, span, msg);
368-
}
369353
if cfg!(windows) {
370354
env::set_var("PATH", &old_path);
371355
}

compiler/rustc_session/src/parse.rs

-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ pub struct ParseSess {
140140
pub config: CrateConfig,
141141
pub check_config: CrateCheckConfig,
142142
pub edition: Edition,
143-
pub missing_fragment_specifiers: Lock<FxHashMap<Span, NodeId>>,
144143
/// Places where raw identifiers were used. This is used to avoid complaining about idents
145144
/// clashing with keywords in new editions.
146145
pub raw_identifier_spans: Lock<Vec<Span>>,
@@ -195,7 +194,6 @@ impl ParseSess {
195194
config: FxHashSet::default(),
196195
check_config: CrateCheckConfig::default(),
197196
edition: ExpnId::root().expn_data().edition,
198-
missing_fragment_specifiers: Default::default(),
199197
raw_identifier_spans: Lock::new(Vec::new()),
200198
bad_unicode_identifiers: Lock::new(Default::default()),
201199
source_map,

0 commit comments

Comments
 (0)