Skip to content

Commit 4b0008c

Browse files
committed
tweaks
1 parent f42e054 commit 4b0008c

File tree

4 files changed

+14
-18
lines changed

4 files changed

+14
-18
lines changed

compiler/rustc_expand/src/mbe/diagnostics.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ pub(super) fn failed_to_match_macro<'cx>(
6767
&& (matches!(expected_token.kind, TokenKind::Interpolated(_))
6868
|| matches!(token.kind, TokenKind::Interpolated(_)))
6969
{
70+
if let TokenKind::Interpolated(node) = &expected_token.kind {
71+
err.span_label(node.def_span(), "");
72+
}
73+
if let TokenKind::Interpolated(node) = &token.kind {
74+
err.span_label(node.def_span(), "");
75+
}
7076
err.note("captured metavariables except for `:tt`, `:ident` and `:lifetime` cannot be compared to other tokens");
7177
err.note("see <https://doc.rust-lang.org/nightly/reference/macros-by-example.html#forwarding-a-matched-fragment> for more information");
7278

compiler/rustc_expand/src/mbe/macro_parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ pub(crate) enum NamedMatch {
397397
MatchedTokenTree(rustc_ast::tokenstream::TokenTree),
398398

399399
// A metavar match of any type other than `tt`.
400-
MatchedNonterminal(Lrc<Nonterminal>, Span),
400+
MatchedNonterminal(Lrc<Nonterminal>),
401401
}
402402

403403
/// Performs a token equality check, ignoring syntax context (that is, an unhygienic comparison)
@@ -694,7 +694,7 @@ impl TtParser {
694694
Ok(nt) => nt,
695695
};
696696
let m = match nt {
697-
ParseNtResult::Nt(nt) => MatchedNonterminal(Lrc::new(nt), span),
697+
ParseNtResult::Nt(nt) => MatchedNonterminal(Lrc::new(nt)),
698698
ParseNtResult::Tt(tt) => MatchedTokenTree(tt),
699699
};
700700
mp.push_match(next_metavar, seq_depth, m);

compiler/rustc_expand/src/mbe/transcribe.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -225,23 +225,11 @@ pub(super) fn transcribe<'a>(
225225
// without wrapping them into groups.
226226
result.push(tt.clone());
227227
}
228-
MatchedNonterminal(nt, span) => {
229-
info!(?span, ?nt, "nt, span: {:?} {:?}", nt.use_span(), nt.def_span());
228+
MatchedNonterminal(nt) => {
230229
// Other variables are emitted into the output stream as groups with
231230
// `Delimiter::Invisible` to maintain parsing priorities.
232231
// `Interpolated` is currently used for such groups in rustc parser.
233232
marker.visit_span(&mut sp);
234-
// let mut data = span.expn_data();
235-
// let mut span = *span;
236-
// marker.visit_span(&mut span);
237-
// data.call_site = span;
238-
// // let mut span = *span;
239-
// // span = span.apply_mark(marker.0.to_expn_id(), marker.1);
240-
// // marker.visit_span(&mut span);
241-
// let expn_id = LocalExpnId::fresh(
242-
// data,
243-
// self.create_stable_hashing_context(),
244-
// );
245233
result
246234
.push(TokenTree::token_alone(token::Interpolated(nt.clone()), sp));
247235
}
@@ -313,7 +301,7 @@ fn lookup_cur_matched<'a>(
313301
interpolations.get(&ident).map(|mut matched| {
314302
for &(idx, _) in repeats {
315303
match matched {
316-
MatchedTokenTree(_) | MatchedNonterminal(_, _) => break,
304+
MatchedTokenTree(_) | MatchedNonterminal(_) => break,
317305
MatchedSeq(ads) => matched = ads.get(idx).unwrap(),
318306
}
319307
}
@@ -403,7 +391,7 @@ fn lockstep_iter_size(
403391
let name = MacroRulesNormalizedIdent::new(*name);
404392
match lookup_cur_matched(name, interpolations, repeats) {
405393
Some(matched) => match matched {
406-
MatchedTokenTree(_) | MatchedNonterminal(_, _) => {
394+
MatchedTokenTree(_) | MatchedNonterminal(_) => {
407395
LockstepIterSize::Unconstrained
408396
}
409397
MatchedSeq(ads) => LockstepIterSize::Constraint(ads.len(), name),
@@ -454,7 +442,7 @@ fn count_repetitions<'a>(
454442
sp: &DelimSpan,
455443
) -> PResult<'a, usize> {
456444
match matched {
457-
MatchedTokenTree(_) | MatchedNonterminal(_, _) => {
445+
MatchedTokenTree(_) | MatchedNonterminal(_) => {
458446
if declared_lhs_depth == 0 {
459447
return Err(cx.create_err(CountRepetitionMisplaced { span: sp.entire() }));
460448
}

tests/ui/macros/nonterminal-matching.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
error: no rules expected the token `enum E {}`
22
--> $DIR/nonterminal-matching.rs:19:10
33
|
4+
LL | macro complex_nonterminal($nt_item: item) {
5+
| --------------
46
LL | macro n(a $nt_item b) {
57
| --------------------- when calling this macro
68
...

0 commit comments

Comments
 (0)