1
Fork 0

Rollup merge of #134161 - nnethercote:overhaul-token-cursors, r=spastorino

Overhaul token cursors

Some nice cleanups here.

r? `````@davidtwco`````
This commit is contained in:
许杰友 Jieyou Xu (Joe) 2024-12-18 22:56:53 +08:00 committed by GitHub
commit 477f222b02
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 199 additions and 210 deletions

View file

@ -18,7 +18,7 @@ pub(crate) fn expand_concat_idents<'cx>(
}
let mut res_str = String::new();
for (i, e) in tts.trees().enumerate() {
for (i, e) in tts.iter().enumerate() {
if i & 1 == 1 {
match e {
TokenTree::Token(Token { kind: token::Comma, .. }, _) => {}

View file

@ -9,9 +9,9 @@ pub(crate) fn expand_trace_macros(
sp: Span,
tt: TokenStream,
) -> MacroExpanderResult<'static> {
let mut cursor = tt.trees();
let mut iter = tt.iter();
let mut err = false;
let value = match &cursor.next() {
let value = match iter.next() {
Some(TokenTree::Token(token, _)) if token.is_keyword(kw::True) => true,
Some(TokenTree::Token(token, _)) if token.is_keyword(kw::False) => false,
_ => {
@ -19,7 +19,7 @@ pub(crate) fn expand_trace_macros(
false
}
};
err |= cursor.next().is_some();
err |= iter.next().is_some();
if err {
cx.dcx().emit_err(errors::TraceMacros { span: sp });
} else {