Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/mbe/src/expander/transcriber.rs')
-rw-r--r--crates/mbe/src/expander/transcriber.rs40
1 files changed, 20 insertions, 20 deletions
diff --git a/crates/mbe/src/expander/transcriber.rs b/crates/mbe/src/expander/transcriber.rs
index a0fd4550ba..e8e7928c26 100644
--- a/crates/mbe/src/expander/transcriber.rs
+++ b/crates/mbe/src/expander/transcriber.rs
@@ -3,6 +3,7 @@
use intern::{Symbol, sym};
use span::{Edition, Span};
+use stdx::itertools::Itertools;
use tt::{Delimiter, TopSubtreeBuilder, iter::TtElement};
use super::TokensOrigin;
@@ -221,10 +222,10 @@ fn expand_subtree(
let index =
ctx.nesting.get(ctx.nesting.len() - 1 - depth).map_or(0, |nest| nest.idx);
builder.push(tt::Leaf::Literal(tt::Literal {
- symbol: Symbol::integer(index),
+ text_and_suffix: Symbol::integer(index),
span: ctx.call_site,
kind: tt::LitKind::Integer,
- suffix: None,
+ suffix_len: 0,
}));
}
Op::Len { depth } => {
@@ -233,10 +234,10 @@ fn expand_subtree(
0
});
builder.push(tt::Leaf::Literal(tt::Literal {
- symbol: Symbol::integer(length),
+ text_and_suffix: Symbol::integer(length),
span: ctx.call_site,
kind: tt::LitKind::Integer,
- suffix: None,
+ suffix_len: 0,
}));
}
Op::Count { name, depth } => {
@@ -277,9 +278,9 @@ fn expand_subtree(
let res = count(binding, 0, depth.unwrap_or(0));
builder.push(tt::Leaf::Literal(tt::Literal {
- symbol: Symbol::integer(res),
+ text_and_suffix: Symbol::integer(res),
span: ctx.call_site,
- suffix: None,
+ suffix_len: 0,
kind: tt::LitKind::Integer,
}));
}
@@ -293,7 +294,7 @@ fn expand_subtree(
ConcatMetaVarExprElem::Literal(lit) => {
// FIXME: This isn't really correct wrt. escaping, but that's what rustc does and anyway
// escaping is used most of the times for characters that are invalid in identifiers.
- concatenated.push_str(lit.symbol.as_str())
+ concatenated.push_str(lit.text())
}
ConcatMetaVarExprElem::Var(var) => {
// Handling of repetitions in `${concat}` isn't fleshed out in rustc, so we currently
@@ -324,13 +325,11 @@ fn expand_subtree(
}
_ => (None, None),
};
- let value = match values {
+ let value = match &values {
(Some(TtElement::Leaf(tt::Leaf::Ident(ident))), None) => {
ident.sym.as_str()
}
- (Some(TtElement::Leaf(tt::Leaf::Literal(lit))), None) => {
- lit.symbol.as_str()
- }
+ (Some(TtElement::Leaf(tt::Leaf::Literal(lit))), None) => lit.text(),
_ => {
if err.is_none() {
err = Some(ExpandError::binding_error(
@@ -412,15 +411,15 @@ fn expand_var(
// Check if this is a simple negative literal (MINUS + LITERAL)
// that should not be wrapped in parentheses
let is_negative_literal = matches!(
- sub.flat_tokens(),
- [
- tt::TokenTree::Leaf(tt::Leaf::Punct(tt::Punct { char: '-', .. })),
- tt::TokenTree::Leaf(tt::Leaf::Literal(_))
- ]
+ sub.iter().collect_array(),
+ Some([
+ tt::TtElement::Leaf(tt::Leaf::Punct(tt::Punct { char: '-', .. })),
+ tt::TtElement::Leaf(tt::Leaf::Literal(_))
+ ])
);
let wrap_in_parens = !is_negative_literal
- && !matches!(sub.flat_tokens(), [tt::TokenTree::Leaf(_)])
+ && !matches!(sub.iter().collect_array(), Some([tt::TtElement::Leaf(_)]))
&& sub.try_into_subtree().is_none_or(|it| {
it.top_subtree().delimiter.kind == tt::DelimiterKind::Invisible
});
@@ -560,8 +559,8 @@ fn fix_up_and_push_path_tt(
// argument list and thus needs `::` between it and `FnOnce`. However in
// today's Rust this type of path *semantically* cannot appear as a
// top-level expression-context path, so we can safely ignore it.
- if let [tt::TokenTree::Leaf(tt::Leaf::Punct(tt::Punct { char: '<', .. }))] =
- tt.flat_tokens()
+ if let Some([tt::TtElement::Leaf(tt::Leaf::Punct(tt::Punct { char: '<', .. }))]) =
+ tt.iter().collect_array()
{
builder.extend([
tt::Leaf::Punct(tt::Punct {
@@ -577,7 +576,8 @@ fn fix_up_and_push_path_tt(
]);
}
}
- prev_was_ident = matches!(tt.flat_tokens(), [tt::TokenTree::Leaf(tt::Leaf::Ident(_))]);
+ prev_was_ident =
+ matches!(tt.iter().collect_array(), Some([tt::TtElement::Leaf(tt::Leaf::Ident(_))]));
builder.extend_with_tt(tt);
}
}