|
1 | | -use std::borrow::Cow; |
2 | | - |
3 | 1 | use crate::base::{DummyResult, ExtCtxt, MacResult}; |
4 | 2 | use crate::expand::{parse_ast_fragment, AstFragmentKind}; |
5 | 3 | use crate::mbe::{ |
6 | 4 | macro_parser::{MatcherLoc, NamedParseResult, ParseResult::*, TtParser}, |
7 | 5 | macro_rules::{try_match_macro, Tracker}, |
8 | 6 | }; |
9 | | -use rustc_ast::token::{self, Token}; |
| 7 | +use rustc_ast::token::{self, Token, TokenKind}; |
10 | 8 | use rustc_ast::tokenstream::TokenStream; |
11 | 9 | use rustc_ast_pretty::pprust; |
12 | 10 | use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, DiagnosticMessage}; |
13 | 11 | use rustc_parse::parser::{Parser, Recovery}; |
14 | 12 | use rustc_span::source_map::SourceMap; |
15 | 13 | use rustc_span::symbol::Ident; |
16 | 14 | use rustc_span::Span; |
| 15 | +use std::borrow::Cow; |
17 | 16 |
|
18 | 17 | use super::macro_rules::{parser_from_cx, NoopTracker}; |
19 | 18 |
|
@@ -63,6 +62,13 @@ pub(super) fn failed_to_match_macro<'cx>( |
63 | 62 | err.note(format!("while trying to match {remaining_matcher}")); |
64 | 63 | } |
65 | 64 |
|
| 65 | + if let MatcherLoc::Token { token: expected_token } = &remaining_matcher |
| 66 | + && (matches!(expected_token.kind, TokenKind::Interpolated(_)) |
| 67 | + || matches!(token.kind, TokenKind::Interpolated(_))) |
| 68 | + { |
| 69 | + err.note("captured metavariables except for `$tt`, `$ident` and `$lifetime` cannot be compared to other tokens"); |
| 70 | + } |
| 71 | + |
66 | 72 | // Check whether there's a missing comma in this macro call, like `println!("{}" a);` |
67 | 73 | if let Some((arg, comma_span)) = arg.add_comma() { |
68 | 74 | for lhs in lhses { |
|
0 commit comments