Auto merge of #132629 - nnethercote:124141-preliminaries, r=petrochenkov
#124141 preliminaries Preliminary changes required to start removing `Nonterminal` (https://github.com/rust-lang/rust/pull/124141). r? `@petrochenkov`
This commit is contained in:
commit
717f5df2c3
16 changed files with 306 additions and 68 deletions
|
@ -1,6 +1,6 @@
|
|||
use std::borrow::Cow;
|
||||
|
||||
use rustc_ast::token::{self, Token, TokenKind};
|
||||
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_errors::{Applicability, Diag, DiagCtxtHandle, DiagMessage};
|
||||
use rustc_macros::Subdiagnostic;
|
||||
|
@ -68,7 +68,9 @@ pub(super) fn failed_to_match_macro(
|
|||
|
||||
if let MatcherLoc::Token { token: expected_token } = &remaining_matcher
|
||||
&& (matches!(expected_token.kind, TokenKind::Interpolated(_))
|
||||
|| matches!(token.kind, TokenKind::Interpolated(_)))
|
||||
|| matches!(token.kind, TokenKind::Interpolated(_))
|
||||
|| matches!(expected_token.kind, TokenKind::OpenDelim(Delimiter::Invisible(_)))
|
||||
|| matches!(token.kind, TokenKind::OpenDelim(Delimiter::Invisible(_))))
|
||||
{
|
||||
err.note("captured metavariables except for `:tt`, `:ident` and `:lifetime` cannot be compared to other tokens");
|
||||
err.note("see <https://doc.rust-lang.org/nightly/reference/macros-by-example.html#forwarding-a-matched-fragment> for more information");
|
||||
|
|
|
@ -693,7 +693,7 @@ fn has_compile_error_macro(rhs: &mbe::TokenTree) -> bool {
|
|||
&& let mbe::TokenTree::Token(bang) = bang
|
||||
&& let TokenKind::Not = bang.kind
|
||||
&& let mbe::TokenTree::Delimited(.., del) = args
|
||||
&& del.delim != Delimiter::Invisible
|
||||
&& !del.delim.skip()
|
||||
{
|
||||
true
|
||||
} else {
|
||||
|
|
|
@ -165,11 +165,12 @@ fn parse_tree<'a>(
|
|||
// during parsing.
|
||||
let mut next = outer_trees.next();
|
||||
let mut trees: Box<dyn Iterator<Item = &tokenstream::TokenTree>>;
|
||||
if let Some(tokenstream::TokenTree::Delimited(.., Delimiter::Invisible, tts)) = next {
|
||||
trees = Box::new(tts.trees());
|
||||
next = trees.next();
|
||||
} else {
|
||||
trees = Box::new(outer_trees);
|
||||
match next {
|
||||
Some(tokenstream::TokenTree::Delimited(.., delim, tts)) if delim.skip() => {
|
||||
trees = Box::new(tts.trees());
|
||||
next = trees.next();
|
||||
}
|
||||
_ => trees = Box::new(outer_trees),
|
||||
}
|
||||
|
||||
match next {
|
||||
|
|
|
@ -38,7 +38,7 @@ impl FromInternal<token::Delimiter> for Delimiter {
|
|||
token::Delimiter::Parenthesis => Delimiter::Parenthesis,
|
||||
token::Delimiter::Brace => Delimiter::Brace,
|
||||
token::Delimiter::Bracket => Delimiter::Bracket,
|
||||
token::Delimiter::Invisible => Delimiter::None,
|
||||
token::Delimiter::Invisible(_) => Delimiter::None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ impl ToInternal<token::Delimiter> for Delimiter {
|
|||
Delimiter::Parenthesis => token::Delimiter::Parenthesis,
|
||||
Delimiter::Brace => token::Delimiter::Brace,
|
||||
Delimiter::Bracket => token::Delimiter::Bracket,
|
||||
Delimiter::None => token::Delimiter::Invisible,
|
||||
Delimiter::None => token::Delimiter::Invisible(token::InvisibleOrigin::ProcMacro),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue