Attempt to try to resolve blocking concerns

This commit is contained in:
Caio 2023-12-01 21:19:22 -03:00
parent 64d7e0d0b6
commit 0278505691
16 changed files with 715 additions and 281 deletions

View File

@ -81,6 +81,7 @@
/// E::A, /// E::A,
/// } /// }
/// ``` /// ```
#[cfg(bootstrap)]
#[macro_export] #[macro_export]
macro_rules! impl_tag { macro_rules! impl_tag {
( (
@ -140,5 +141,148 @@ macro_rules! impl_tag {
}; };
} }
/// Implements [`Tag`] for a given type.
///
/// You can use `impl_tag` on structs and enums.
/// You need to specify the type and all its possible values,
/// which can only be paths with optional fields.
///
/// [`Tag`]: crate::tagged_ptr::Tag
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(macro_metavar_expr)]
/// use rustc_data_structures::{impl_tag, tagged_ptr::Tag};
///
/// #[derive(Copy, Clone, PartialEq, Debug)]
/// enum SomeTag {
/// A,
/// B,
/// X { v: bool },
/// Y(bool, bool),
/// }
///
/// impl_tag! {
/// // The type for which the `Tag` will be implemented
/// impl Tag for SomeTag;
/// // You need to specify all possible tag values:
/// SomeTag::A, // 0
/// SomeTag::B, // 1
/// // For variants with fields, you need to specify the fields:
/// SomeTag::X { v: true }, // 2
/// SomeTag::X { v: false }, // 3
/// // For tuple variants use named syntax:
/// SomeTag::Y { 0: true, 1: true }, // 4
/// SomeTag::Y { 0: false, 1: true }, // 5
/// SomeTag::Y { 0: true, 1: false }, // 6
/// SomeTag::Y { 0: false, 1: false }, // 7
/// }
///
/// // Tag values are assigned in order:
/// assert_eq!(SomeTag::A.into_usize(), 0);
/// assert_eq!(SomeTag::X { v: false }.into_usize(), 3);
/// assert_eq!(SomeTag::Y(false, true).into_usize(), 5);
///
/// assert_eq!(unsafe { SomeTag::from_usize(1) }, SomeTag::B);
/// assert_eq!(unsafe { SomeTag::from_usize(2) }, SomeTag::X { v: true });
/// assert_eq!(unsafe { SomeTag::from_usize(7) }, SomeTag::Y(false, false));
/// ```
///
/// Structs are supported:
///
/// ```
/// #![feature(macro_metavar_expr)]
/// # use rustc_data_structures::impl_tag;
/// #[derive(Copy, Clone)]
/// struct Flags { a: bool, b: bool }
///
/// impl_tag! {
/// impl Tag for Flags;
/// Flags { a: true, b: true },
/// Flags { a: false, b: true },
/// Flags { a: true, b: false },
/// Flags { a: false, b: false },
/// }
/// ```
///
/// Not specifying all values results in a compile error:
///
/// ```compile_fail,E0004
/// #![feature(macro_metavar_expr)]
/// # use rustc_data_structures::impl_tag;
/// #[derive(Copy, Clone)]
/// enum E {
/// A,
/// B,
/// }
///
/// impl_tag! {
/// impl Tag for E;
/// E::A,
/// }
/// ```
#[cfg(not(bootstrap))]
#[macro_export]
macro_rules! impl_tag {
(
impl Tag for $Self:ty;
$(
$($path:ident)::* $( { $( $fields:tt )* })?,
)*
) => {
// Safety:
// `bits_for_tags` is called on the same `${index()}`-es as
// `into_usize` returns, thus `BITS` constant is correct.
unsafe impl $crate::tagged_ptr::Tag for $Self {
const BITS: u32 = $crate::tagged_ptr::bits_for_tags(&[
$(
${index()},
$( ${ignore($path)} )*
)*
]);
#[inline]
fn into_usize(self) -> usize {
// This forbids use of repeating patterns (`Enum::V`&`Enum::V`, etc)
// (or at least it should, see <https://github.com/rust-lang/rust/issues/110613>)
#[forbid(unreachable_patterns)]
match self {
// `match` is doing heavy lifting here, by requiring exhaustiveness
$(
$($path)::* $( { $( $fields )* } )? => ${index()},
)*
}
}
#[inline]
unsafe fn from_usize(tag: usize) -> Self {
match tag {
$(
${index()} => $($path)::* $( { $( $fields )* } )?,
)*
// Safety:
// `into_usize` only returns `${index()}` of the same
// repetition as we are filtering above, thus if this is
// reached, the safety contract of this function was
// already breached.
_ => unsafe {
debug_assert!(
false,
"invalid tag: {tag}\
(this is a bug in the caller of `from_usize`)"
);
std::hint::unreachable_unchecked()
},
}
}
}
};
}
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;

View File

@ -41,6 +41,7 @@ use std::path::PathBuf;
use std::rc::Rc; use std::rc::Rc;
use std::{iter, mem}; use std::{iter, mem};
#[cfg(bootstrap)]
macro_rules! ast_fragments { macro_rules! ast_fragments {
( (
$($Kind:ident($AstTy:ty) { $($Kind:ident($AstTy:ty) {
@ -165,6 +166,131 @@ macro_rules! ast_fragments {
} }
} }
#[cfg(not(bootstrap))]
macro_rules! ast_fragments {
(
$($Kind:ident($AstTy:ty) {
$kind_name:expr;
$(one fn $mut_visit_ast:ident; fn $visit_ast:ident;)?
$(many fn $flat_map_ast_elt:ident; fn $visit_ast_elt:ident($($args:tt)*);)?
fn $make_ast:ident;
})*
) => {
/// A fragment of AST that can be produced by a single macro expansion.
/// Can also serve as an input and intermediate result for macro expansion operations.
pub enum AstFragment {
OptExpr(Option<P<ast::Expr>>),
MethodReceiverExpr(P<ast::Expr>),
$($Kind($AstTy),)*
}
/// "Discriminant" of an AST fragment.
#[derive(Copy, Clone, PartialEq, Eq)]
pub enum AstFragmentKind {
OptExpr,
MethodReceiverExpr,
$($Kind,)*
}
impl AstFragmentKind {
pub fn name(self) -> &'static str {
match self {
AstFragmentKind::OptExpr => "expression",
AstFragmentKind::MethodReceiverExpr => "expression",
$(AstFragmentKind::$Kind => $kind_name,)*
}
}
fn make_from<'a>(self, result: Box<dyn MacResult + 'a>) -> Option<AstFragment> {
match self {
AstFragmentKind::OptExpr =>
result.make_expr().map(Some).map(AstFragment::OptExpr),
AstFragmentKind::MethodReceiverExpr =>
result.make_expr().map(AstFragment::MethodReceiverExpr),
$(AstFragmentKind::$Kind => result.$make_ast().map(AstFragment::$Kind),)*
}
}
}
impl AstFragment {
pub fn add_placeholders(&mut self, placeholders: &[NodeId]) {
if placeholders.is_empty() {
return;
}
match self {
$($(AstFragment::$Kind(ast) => ast.extend(placeholders.iter().flat_map(|id| {
${ignore($flat_map_ast_elt)}
placeholder(AstFragmentKind::$Kind, *id, None).$make_ast()
})),)?)*
_ => panic!("unexpected AST fragment kind")
}
}
pub fn make_opt_expr(self) -> Option<P<ast::Expr>> {
match self {
AstFragment::OptExpr(expr) => expr,
_ => panic!("AstFragment::make_* called on the wrong kind of fragment"),
}
}
pub fn make_method_receiver_expr(self) -> P<ast::Expr> {
match self {
AstFragment::MethodReceiverExpr(expr) => expr,
_ => panic!("AstFragment::make_* called on the wrong kind of fragment"),
}
}
$(pub fn $make_ast(self) -> $AstTy {
match self {
AstFragment::$Kind(ast) => ast,
_ => panic!("AstFragment::make_* called on the wrong kind of fragment"),
}
})*
fn make_ast<T: InvocationCollectorNode>(self) -> T::OutputTy {
T::fragment_to_output(self)
}
pub fn mut_visit_with<F: MutVisitor>(&mut self, vis: &mut F) {
match self {
AstFragment::OptExpr(opt_expr) => {
visit_clobber(opt_expr, |opt_expr| {
if let Some(expr) = opt_expr {
vis.filter_map_expr(expr)
} else {
None
}
});
}
AstFragment::MethodReceiverExpr(expr) => vis.visit_method_receiver_expr(expr),
$($(AstFragment::$Kind(ast) => vis.$mut_visit_ast(ast),)?)*
$($(AstFragment::$Kind(ast) =>
ast.flat_map_in_place(|ast| vis.$flat_map_ast_elt(ast)),)?)*
}
}
pub fn visit_with<'a, V: Visitor<'a>>(&'a self, visitor: &mut V) {
match self {
AstFragment::OptExpr(Some(expr)) => visitor.visit_expr(expr),
AstFragment::OptExpr(None) => {}
AstFragment::MethodReceiverExpr(expr) => visitor.visit_method_receiver_expr(expr),
$($(AstFragment::$Kind(ast) => visitor.$visit_ast(ast),)?)*
$($(AstFragment::$Kind(ast) => for ast_elt in &ast[..] {
visitor.$visit_ast_elt(ast_elt, $($args)*);
})?)*
}
}
}
impl<'a> MacResult for crate::mbe::macro_rules::ParserAnyMacro<'a> {
$(fn $make_ast(self: Box<crate::mbe::macro_rules::ParserAnyMacro<'a>>)
-> Option<$AstTy> {
Some(self.make(AstFragmentKind::$Kind).$make_ast())
})*
}
}
}
ast_fragments! { ast_fragments! {
Expr(P<ast::Expr>) { "expression"; one fn visit_expr; fn visit_expr; fn make_expr; } Expr(P<ast::Expr>) { "expression"; one fn visit_expr; fn visit_expr; fn make_expr; }
Pat(P<ast::Pat>) { "pattern"; one fn visit_pat; fn visit_pat; fn make_pat; } Pat(P<ast::Pat>) { "pattern"; one fn visit_pat; fn visit_pat; fn make_pat; }

View File

@ -10,9 +10,8 @@ use rustc_span::Span;
/// A meta-variable expression, for expansions based on properties of meta-variables. /// A meta-variable expression, for expansions based on properties of meta-variables.
#[derive(Debug, Clone, PartialEq, Encodable, Decodable)] #[derive(Debug, Clone, PartialEq, Encodable, Decodable)]
pub(crate) enum MetaVarExpr { pub(crate) enum MetaVarExpr {
/// The number of repetitions of an identifier, optionally limited to a number /// The number of repetitions of an identifier.
/// of outer-most repetition depths. If the depth limit is `None` then the depth is unlimited. Count(Ident, usize),
Count(Ident, Option<usize>),
/// Ignore a meta-variable for repetition without expansion. /// Ignore a meta-variable for repetition without expansion.
Ignore(Ident), Ignore(Ident),
@ -43,7 +42,10 @@ impl MetaVarExpr {
let mut iter = args.trees(); let mut iter = args.trees();
let rslt = match ident.as_str() { let rslt = match ident.as_str() {
"count" => parse_count(&mut iter, sess, ident.span)?, "count" => parse_count(&mut iter, sess, ident.span)?,
"ignore" => MetaVarExpr::Ignore(parse_ident(&mut iter, sess, ident.span)?), "ignore" => {
eat_dollar(&mut iter, sess, ident.span)?;
MetaVarExpr::Ignore(parse_ident(&mut iter, sess, ident.span)?)
}
"index" => MetaVarExpr::Index(parse_depth(&mut iter, sess, ident.span)?), "index" => MetaVarExpr::Index(parse_depth(&mut iter, sess, ident.span)?),
"length" => MetaVarExpr::Length(parse_depth(&mut iter, sess, ident.span)?), "length" => MetaVarExpr::Length(parse_depth(&mut iter, sess, ident.span)?),
_ => { _ => {
@ -92,6 +94,7 @@ fn parse_count<'sess>(
sess: &'sess ParseSess, sess: &'sess ParseSess,
span: Span, span: Span,
) -> PResult<'sess, MetaVarExpr> { ) -> PResult<'sess, MetaVarExpr> {
eat_dollar(iter, sess, span)?;
let ident = parse_ident(iter, sess, span)?; let ident = parse_ident(iter, sess, span)?;
let depth = if try_eat_comma(iter) { let depth = if try_eat_comma(iter) {
if iter.look_ahead(0).is_none() { if iter.look_ahead(0).is_none() {
@ -100,9 +103,9 @@ fn parse_count<'sess>(
"`count` followed by a comma must have an associated index indicating its depth", "`count` followed by a comma must have an associated index indicating its depth",
)); ));
} }
Some(parse_depth(iter, sess, span)?) parse_depth(iter, sess, span)?
} else { } else {
None 0
}; };
Ok(MetaVarExpr::Count(ident, depth)) Ok(MetaVarExpr::Count(ident, depth))
} }
@ -166,3 +169,20 @@ fn try_eat_comma(iter: &mut RefTokenTreeCursor<'_>) -> bool {
} }
false false
} }
/// Expects that the next item is a dollar sign.
fn eat_dollar<'sess>(
iter: &mut RefTokenTreeCursor<'_>,
sess: &'sess ParseSess,
span: Span,
) -> PResult<'sess, ()> {
if let Some(TokenTree::Token(token::Token { kind: token::Dollar, .. }, _)) = iter.look_ahead(0)
{
let _ = iter.next();
return Ok(());
}
Err(sess.span_diagnostic.struct_span_err(
span,
"meta-variables within meta-variable expressions must be referenced using a dollar sign",
))
}

View File

@ -422,7 +422,7 @@ fn lockstep_iter_size(
/// declared inside a single repetition and the index `1` implies two nested repetitions. /// declared inside a single repetition and the index `1` implies two nested repetitions.
fn count_repetitions<'a>( fn count_repetitions<'a>(
cx: &ExtCtxt<'a>, cx: &ExtCtxt<'a>,
depth_opt: Option<usize>, depth_user: usize,
mut matched: &NamedMatch, mut matched: &NamedMatch,
repeats: &[(usize, usize)], repeats: &[(usize, usize)],
sp: &DelimSpan, sp: &DelimSpan,
@ -431,37 +431,45 @@ fn count_repetitions<'a>(
// (or at the top-level of `matched` if no depth is given). // (or at the top-level of `matched` if no depth is given).
fn count<'a>( fn count<'a>(
cx: &ExtCtxt<'a>, cx: &ExtCtxt<'a>,
declared_lhs_depth: usize, depth_curr: usize,
depth_opt: Option<usize>, depth_max: usize,
matched: &NamedMatch, matched: &NamedMatch,
sp: &DelimSpan, sp: &DelimSpan,
) -> PResult<'a, usize> { ) -> PResult<'a, usize> {
match matched { match matched {
MatchedTokenTree(_) | MatchedNonterminal(_) => { MatchedTokenTree(_) | MatchedNonterminal(_) => Ok(1),
if declared_lhs_depth == 0 {
return Err(cx.create_err(CountRepetitionMisplaced { span: sp.entire() }));
}
match depth_opt {
None => Ok(1),
Some(_) => Err(out_of_bounds_err(cx, declared_lhs_depth, sp.entire(), "count")),
}
}
MatchedSeq(named_matches) => { MatchedSeq(named_matches) => {
let new_declared_lhs_depth = declared_lhs_depth + 1; if depth_curr == depth_max {
match depth_opt { Ok(named_matches.len())
None => named_matches } else {
named_matches
.iter() .iter()
.map(|elem| count(cx, new_declared_lhs_depth, None, elem, sp)) .map(|elem| count(cx, depth_curr + 1, depth_max, elem, sp))
.sum(), .sum()
Some(0) => Ok(named_matches.len()),
Some(depth) => named_matches
.iter()
.map(|elem| count(cx, new_declared_lhs_depth, Some(depth - 1), elem, sp))
.sum(),
} }
} }
} }
} }
/// Maximum depth
fn depth(counter: usize, matched: &NamedMatch) -> usize {
match matched {
MatchedTokenTree(_) | MatchedNonterminal(_) => counter,
MatchedSeq(named_matches) => {
let rslt = counter + 1;
if let Some(elem) = named_matches.first() { depth(rslt, elem) } else { rslt }
}
}
}
let depth_max = depth(0, matched)
.checked_sub(1)
.and_then(|el| el.checked_sub(repeats.len()))
.unwrap_or_default();
if depth_user > depth_max {
return Err(out_of_bounds_err(cx, depth_max + 1, sp.entire(), "count"));
}
// `repeats` records all of the nested levels at which we are currently // `repeats` records all of the nested levels at which we are currently
// matching meta-variables. The meta-var-expr `count($x)` only counts // matching meta-variables. The meta-var-expr `count($x)` only counts
// matches that occur in this "subtree" of the `NamedMatch` where we // matches that occur in this "subtree" of the `NamedMatch` where we
@ -473,7 +481,12 @@ fn count_repetitions<'a>(
matched = &ads[idx]; matched = &ads[idx];
} }
} }
count(cx, 0, depth_opt, matched, sp)
if let MatchedTokenTree(_) | MatchedNonterminal(_) = matched {
return Err(cx.create_err(CountRepetitionMisplaced { span: sp.entire() }));
}
count(cx, depth_user, depth_max, matched, sp)
} }
/// Returns a `NamedMatch` item declared on the LHS given an arbitrary [Ident] /// Returns a `NamedMatch` item declared on the LHS given an arbitrary [Ident]
@ -505,7 +518,7 @@ fn out_of_bounds_err<'a>(
) )
} else { } else {
format!( format!(
"depth parameter on meta-variable expression `{ty}` \ "depth parameter of meta-variable expression `{ty}` \
must be less than {max}" must be less than {max}"
) )
}; };
@ -527,9 +540,9 @@ fn transcribe_metavar_expr<'a>(
span span
}; };
match *expr { match *expr {
MetaVarExpr::Count(original_ident, depth_opt) => { MetaVarExpr::Count(original_ident, depth) => {
let matched = matched_from_ident(cx, original_ident, interp)?; let matched = matched_from_ident(cx, original_ident, interp)?;
let count = count_repetitions(cx, depth_opt, matched, repeats, sp)?; let count = count_repetitions(cx, depth, matched, repeats, sp)?;
let tt = TokenTree::token_alone( let tt = TokenTree::token_alone(
TokenKind::lit(token::Integer, sym::integer(count), None), TokenKind::lit(token::Integer, sym::integer(count), None),
visited_span(), visited_span(),

View File

@ -8,6 +8,7 @@ use crate::marker::{StructuralEq, StructuralPartialEq};
// //
// Also provides implementations for tuples with lesser arity. For example, tuple_impls!(A B C) // Also provides implementations for tuples with lesser arity. For example, tuple_impls!(A B C)
// will implement everything for (A, B, C), (A, B) and (A,). // will implement everything for (A, B, C), (A, B) and (A,).
#[cfg(bootstrap)]
macro_rules! tuple_impls { macro_rules! tuple_impls {
// Stopping criteria (1-ary tuple) // Stopping criteria (1-ary tuple)
($T:ident) => { ($T:ident) => {
@ -145,6 +146,148 @@ macro_rules! tuple_impls {
} }
} }
// Recursive macro for implementing n-ary tuple functions and operations
//
// Also provides implementations for tuples with lesser arity. For example, tuple_impls!(A B C)
// will implement everything for (A, B, C), (A, B) and (A,).
#[cfg(not(bootstrap))]
macro_rules! tuple_impls {
// Stopping criteria (1-ary tuple)
($T:ident) => {
tuple_impls!(@impl $T);
};
// Running criteria (n-ary tuple, with n >= 2)
($T:ident $( $U:ident )+) => {
tuple_impls!($( $U )+);
tuple_impls!(@impl $T $( $U )+);
};
// "Private" internal implementation
(@impl $( $T:ident )+) => {
maybe_tuple_doc! {
$($T)+ @
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T: PartialEq),+> PartialEq for ($($T,)+)
where
last_type!($($T,)+): ?Sized
{
#[inline]
fn eq(&self, other: &($($T,)+)) -> bool {
$( ${ignore($T)} self.${index()} == other.${index()} )&&+
}
#[inline]
fn ne(&self, other: &($($T,)+)) -> bool {
$( ${ignore($T)} self.${index()} != other.${index()} )||+
}
}
}
maybe_tuple_doc! {
$($T)+ @
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T: Eq),+> Eq for ($($T,)+)
where
last_type!($($T,)+): ?Sized
{}
}
maybe_tuple_doc! {
$($T)+ @
#[unstable(feature = "structural_match", issue = "31434")]
impl<$($T: ConstParamTy),+> ConstParamTy for ($($T,)+)
{}
}
maybe_tuple_doc! {
$($T)+ @
#[unstable(feature = "structural_match", issue = "31434")]
impl<$($T),+> StructuralPartialEq for ($($T,)+)
{}
}
maybe_tuple_doc! {
$($T)+ @
#[unstable(feature = "structural_match", issue = "31434")]
impl<$($T),+> StructuralEq for ($($T,)+)
{}
}
maybe_tuple_doc! {
$($T)+ @
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T: PartialOrd),+> PartialOrd for ($($T,)+)
where
last_type!($($T,)+): ?Sized
{
#[inline]
fn partial_cmp(&self, other: &($($T,)+)) -> Option<Ordering> {
lexical_partial_cmp!($( ${ignore($T)} self.${index()}, other.${index()} ),+)
}
#[inline]
fn lt(&self, other: &($($T,)+)) -> bool {
lexical_ord!(lt, Less, $( ${ignore($T)} self.${index()}, other.${index()} ),+)
}
#[inline]
fn le(&self, other: &($($T,)+)) -> bool {
lexical_ord!(le, Less, $( ${ignore($T)} self.${index()}, other.${index()} ),+)
}
#[inline]
fn ge(&self, other: &($($T,)+)) -> bool {
lexical_ord!(ge, Greater, $( ${ignore($T)} self.${index()}, other.${index()} ),+)
}
#[inline]
fn gt(&self, other: &($($T,)+)) -> bool {
lexical_ord!(gt, Greater, $( ${ignore($T)} self.${index()}, other.${index()} ),+)
}
}
}
maybe_tuple_doc! {
$($T)+ @
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T: Ord),+> Ord for ($($T,)+)
where
last_type!($($T,)+): ?Sized
{
#[inline]
fn cmp(&self, other: &($($T,)+)) -> Ordering {
lexical_cmp!($( ${ignore($T)} self.${index()}, other.${index()} ),+)
}
}
}
maybe_tuple_doc! {
$($T)+ @
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($T: Default),+> Default for ($($T,)+) {
#[inline]
fn default() -> ($($T,)+) {
($({ let x: $T = Default::default(); x},)+)
}
}
}
#[stable(feature = "array_tuple_conv", since = "1.71.0")]
impl<T> From<[T; ${count($T)}]> for ($(${ignore($T)} T,)+) {
#[inline]
#[allow(non_snake_case)]
fn from(array: [T; ${count($T)}]) -> Self {
let [$($T,)+] = array;
($($T,)+)
}
}
#[stable(feature = "array_tuple_conv", since = "1.71.0")]
impl<T> From<($(${ignore($T)} T,)+)> for [T; ${count($T)}] {
#[inline]
#[allow(non_snake_case)]
fn from(tuple: ($(${ignore($T)} T,)+)) -> Self {
let ($($T,)+) = tuple;
[$($T,)+]
}
}
}
}
// If this is a unary tuple, it adds a doc comment. // If this is a unary tuple, it adds a doc comment.
// Otherwise, it hides the docs entirely. // Otherwise, it hides the docs entirely.
macro_rules! maybe_tuple_doc { macro_rules! maybe_tuple_doc {

View File

@ -10,11 +10,11 @@ fn main() {
$( $(
// inner-most repetition // inner-most repetition
$( $(
${ignore(l)} ${index()}, ${length()}, ${ignore($l)} ${index()}, ${length()},
)* )*
${count(l)}, ${index()}, ${length()}, ${count($l)}, ${index()}, ${length()},
)* )*
${count(l)}, ${count($l)},
] ]
}; };
} }
@ -72,30 +72,30 @@ fn main() {
&[ &[
$( $( $( $( $( $(
&[ &[
${ignore(i)} ${count(i, 0)}, ${ignore($i)} ${count($i, 0)},
][..], ][..],
)* )* )* )* )* )*
$( $( $( $(
&[ &[
${ignore(i)} ${count(i, 0)}, ${ignore($i)} ${count($i, 0)},
${ignore(i)} ${count(i, 1)}, ${ignore($i)} ${count($i, 1)},
][..], ][..],
)* )* )* )*
$( $(
&[ &[
${ignore(i)} ${count(i, 0)}, ${ignore($i)} ${count($i, 0)},
${ignore(i)} ${count(i, 1)}, ${ignore($i)} ${count($i, 1)},
${ignore(i)} ${count(i, 2)}, ${ignore($i)} ${count($i, 2)},
][..], ][..],
)* )*
&[ &[
${count(i, 0)}, ${count($i, 0)},
${count(i, 1)}, ${count($i, 1)},
${count(i, 2)}, ${count($i, 2)},
${count(i, 3)}, ${count($i, 3)},
][..] ][..]
][..] ][..]
} }
@ -133,23 +133,23 @@ fn main() {
&[7][..], &[7][..],
// (a b c) (d e f) // (a b c) (d e f)
&[2, 6][..], &[6, 2][..],
// (g h) (i j k l m) // (g h) (i j k l m)
&[2, 7][..], &[7, 2][..],
// (n) // (n)
&[1, 1][..], &[1, 1][..],
// (o) (p q) (r s) // (o) (p q) (r s)
&[3, 5][..], &[5, 3][..],
// (t u v w x y z) // (t u v w x y z)
&[1, 7][..], &[7, 1][..],
// [ (a b c) (d e f) ] // [ (a b c) (d e f) ]
// [ (g h) (i j k l m) ] // [ (g h) (i j k l m) ]
// [ (n) ] // [ (n) ]
&[3, 5, 14][..], &[14, 5, 3][..],
// [ (o) (p q) (r s) ] // [ (o) (p q) (r s) ]
// [ (t u v w x y z) ] // [ (t u v w x y z) ]
&[2, 4, 12][..], &[12, 4, 2][..],
// { // {
// [ (a b c) (d e f) ] // [ (a b c) (d e f) ]
@ -160,7 +160,7 @@ fn main() {
// [ (o) (p q) (r s) ] // [ (o) (p q) (r s) ]
// [ (t u v w x y z) ] // [ (t u v w x y z) ]
// } // }
&[2, 5, 9, 26][..] &[26, 9, 5, 2][..]
][..] ][..]
); );
@ -170,31 +170,31 @@ fn main() {
&[ &[
$( $( $( $( $( $( $( $(
&[ &[
${ignore(i)} ${length(3)}, ${ignore($i)} ${length(3)},
${ignore(i)} ${length(2)}, ${ignore($i)} ${length(2)},
${ignore(i)} ${length(1)}, ${ignore($i)} ${length(1)},
${ignore(i)} ${length(0)}, ${ignore($i)} ${length(0)},
][..], ][..],
)* )* )* )* )* )* )* )*
$( $( $( $( $( $(
&[ &[
${ignore(i)} ${length(2)}, ${ignore($i)} ${length(2)},
${ignore(i)} ${length(1)}, ${ignore($i)} ${length(1)},
${ignore(i)} ${length(0)}, ${ignore($i)} ${length(0)},
][..], ][..],
)* )* )* )* )* )*
$( $( $( $(
&[ &[
${ignore(i)} ${length(1)}, ${ignore($i)} ${length(1)},
${ignore(i)} ${length(0)}, ${ignore($i)} ${length(0)},
][..], ][..],
)* )* )* )*
$( $(
&[ &[
${ignore(i)} ${length(0)}, ${ignore($i)} ${length(0)},
][..], ][..],
)* )*
][..] ][..]

View File

@ -5,14 +5,14 @@
/// Count the number of idents in a macro repetition. /// Count the number of idents in a macro repetition.
macro_rules! count_idents { macro_rules! count_idents {
( $( $i:ident ),* ) => { ( $( $i:ident ),* ) => {
${count(i)} ${count($i)}
}; };
} }
/// Count the number of idents in a 2-dimensional macro repetition. /// Count the number of idents in a 2-dimensional macro repetition.
macro_rules! count_idents_2 { macro_rules! count_idents_2 {
( $( [ $( $i:ident ),* ] ),* ) => { ( $( [ $( $i:ident ),* ] ),* ) => {
${count(i)} ${count($i)}
}; };
} }
@ -21,17 +21,17 @@ macro_rules! count_depth_limits {
( $( { $( [ $( $outer:ident : ( $( $inner:ident )* ) )* ] )* } )* ) => { ( $( { $( [ $( $outer:ident : ( $( $inner:ident )* ) )* ] )* } )* ) => {
( (
( (
${count(inner)}, ${count($inner)},
${count(inner, 0)}, ${count($inner, 0)},
${count(inner, 1)}, ${count($inner, 1)},
${count(inner, 2)}, ${count($inner, 2)},
${count(inner, 3)}, ${count($inner, 3)},
), ),
( (
${count(outer)}, ${count($outer)},
${count(outer, 0)}, ${count($outer, 0)},
${count(outer, 1)}, ${count($outer, 1)},
${count(outer, 2)}, ${count($outer, 2)},
), ),
) )
}; };
@ -43,7 +43,7 @@ macro_rules! count_depth_limits {
/// repetition binding. /// repetition binding.
macro_rules! enumerate_literals { macro_rules! enumerate_literals {
( $( ($l:stmt) ),* ) => { ( $( ($l:stmt) ),* ) => {
[$( ${ignore(l)} (${index()}, ${length()}) ),*] [$( ${ignore($l)} (${index()}, ${length()}) ),*]
}; };
} }
@ -77,7 +77,7 @@ macro_rules! make_count_adders {
$( $(
macro_rules! $i { macro_rules! $i {
( $$( $$j:ident ),* ) => { ( $$( $$j:ident ),* ) => {
$b + $${count(j)} $b + $${count($j)}
}; };
} }
)* )*
@ -122,7 +122,7 @@ fn main() {
[ T: (t u v w x y z) ] [ T: (t u v w x y z) ]
} }
}, },
((26, 2, 5, 9, 26), (9, 2, 5, 9)) ((26, 26, 9, 5, 2), (9, 9, 5, 2))
); );
assert_eq!(enumerate_literals![("foo"), ("bar")], [(0, 2), (1, 2)]); assert_eq!(enumerate_literals![("foo"), ("bar")], [(0, 2), (1, 2)]);
assert_eq!( assert_eq!(

View File

@ -1,7 +1,7 @@
#![feature(macro_metavar_expr)] #![feature(macro_metavar_expr)]
macro_rules! foo { macro_rules! foo {
( $( $($t:ident),* );* ) => { ${count(t,)} } ( $( $($t:ident),* );* ) => { ${count($t,)} }
//~^ ERROR `count` followed by a comma must have an associated //~^ ERROR `count` followed by a comma must have an associated
//~| ERROR expected expression, found `$` //~| ERROR expected expression, found `$`
} }

View File

@ -1,13 +1,13 @@
error: `count` followed by a comma must have an associated index indicating its depth error: `count` followed by a comma must have an associated index indicating its depth
--> $DIR/issue-111904.rs:4:37 --> $DIR/issue-111904.rs:4:37
| |
LL | ( $( $($t:ident),* );* ) => { ${count(t,)} } LL | ( $( $($t:ident),* );* ) => { ${count($t,)} }
| ^^^^^ | ^^^^^
error: expected expression, found `$` error: expected expression, found `$`
--> $DIR/issue-111904.rs:4:35 --> $DIR/issue-111904.rs:4:35
| |
LL | ( $( $($t:ident),* );* ) => { ${count(t,)} } LL | ( $( $($t:ident),* );* ) => { ${count($t,)} }
| ^ expected expression | ^ expected expression
... ...
LL | foo!(a, a; b, b); LL | foo!(a, a; b, b);

View File

@ -13,17 +13,17 @@ macro_rules! example {
( $( [ $( ( $( $x:ident )* ) )* ] )* ) => { ( $( [ $( ( $( $x:ident )* ) )* ] )* ) => {
Example { Example {
_indexes: &[], _indexes: &[],
_counts: &[${count(x, 0)}, ${count(x, 1)}, ${count(x, 2)}], _counts: &[${count($x, 0)}, ${count($x, 1)}, ${count($x, 2)}],
_nested: vec![ _nested: vec![
$( $(
Example { Example {
_indexes: &[(${index()}, ${length()})], _indexes: &[(${index()}, ${length()})],
_counts: &[${count(x, 0)}, ${count(x, 1)}], _counts: &[${count($x, 0)}, ${count($x, 1)}],
_nested: vec![ _nested: vec![
$( $(
Example { Example {
_indexes: &[(${index(1)}, ${length(1)}), (${index()}, ${length()})], _indexes: &[(${index(1)}, ${length(1)}), (${index()}, ${length()})],
_counts: &[${count(x)}], _counts: &[${count($x)}],
_nested: vec![ _nested: vec![
$( $(
Example { Example {
@ -34,7 +34,7 @@ macro_rules! example {
], ],
_counts: &[], _counts: &[],
_nested: vec![], _nested: vec![],
${ignore(x)} ${ignore($x)}
} }
),* ),*
] ]
@ -49,9 +49,9 @@ macro_rules! example {
} }
static EXPECTED: &str = concat!( static EXPECTED: &str = concat!(
"Example { _indexes: [], _counts: [2, 4, 13], _nested: [", "Example { _indexes: [], _counts: [13, 4, 2], _nested: [",
concat!( concat!(
"Example { _indexes: [(0, 2)], _counts: [3, 10], _nested: [", "Example { _indexes: [(0, 2)], _counts: [10, 3], _nested: [",
concat!( concat!(
"Example { _indexes: [(0, 2), (0, 3)], _counts: [4], _nested: [", "Example { _indexes: [(0, 2), (0, 3)], _counts: [4], _nested: [",
concat!( concat!(
@ -77,7 +77,7 @@ static EXPECTED: &str = concat!(
"] }", "] }",
), ),
"] }, ", "] }, ",
"Example { _indexes: [(1, 2)], _counts: [1, 3], _nested: [", "Example { _indexes: [(1, 2)], _counts: [3, 1], _nested: [",
concat!( concat!(
"Example { _indexes: [(1, 2), (0, 1)], _counts: [3], _nested: [", "Example { _indexes: [(1, 2), (0, 1)], _counts: [3], _nested: [",
concat!( concat!(

View File

@ -3,9 +3,9 @@
macro_rules! a { macro_rules! a {
( $( { $( [ $( ( $( $foo:ident )* ) )* ] )* } )* ) => { ( $( { $( [ $( ( $( $foo:ident )* ) )* ] )* } )* ) => {
( (
${count(foo, 0)}, ${count($foo, 0)},
${count(foo, 10)}, ${count($foo, 10)},
//~^ ERROR depth parameter on meta-variable expression `count` must be less than 4 //~^ ERROR depth parameter of meta-variable expression `count` must be less than 4
) )
}; };
} }
@ -14,10 +14,10 @@ macro_rules! b {
( $( { $( [ $( $foo:ident )* ] )* } )* ) => { ( $( { $( [ $( $foo:ident )* ] )* } )* ) => {
( (
$( $( $( $( $( $(
${ignore(foo)} ${ignore($foo)}
${index(0)}, ${index(0)},
${index(10)}, ${index(10)},
//~^ ERROR depth parameter on meta-variable expression `index` must be less than 3 //~^ ERROR depth parameter of meta-variable expression `index` must be less than 3
)* )* )* )* )* )*
) )
}; };
@ -27,10 +27,10 @@ macro_rules! c {
( $( { $( $foo:ident )* } )* ) => { ( $( { $( $foo:ident )* } )* ) => {
( (
$( $( $( $(
${ignore(foo)} ${ignore($foo)}
${length(0)} ${length(0)}
${length(10)} ${length(10)}
//~^ ERROR depth parameter on meta-variable expression `length` must be less than 2 //~^ ERROR depth parameter of meta-variable expression `length` must be less than 2
)* )* )* )*
) )
}; };

View File

@ -1,16 +1,16 @@
error: depth parameter on meta-variable expression `count` must be less than 4 error: depth parameter of meta-variable expression `count` must be less than 4
--> $DIR/out-of-bounds-arguments.rs:7:14 --> $DIR/out-of-bounds-arguments.rs:7:14
| |
LL | ${count(foo, 10)}, LL | ${count($foo, 10)},
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^
error: depth parameter on meta-variable expression `index` must be less than 3 error: depth parameter of meta-variable expression `index` must be less than 3
--> $DIR/out-of-bounds-arguments.rs:19:18 --> $DIR/out-of-bounds-arguments.rs:19:18
| |
LL | ${index(10)}, LL | ${index(10)},
| ^^^^^^^^^^^ | ^^^^^^^^^^^
error: depth parameter on meta-variable expression `length` must be less than 2 error: depth parameter of meta-variable expression `length` must be less than 2
--> $DIR/out-of-bounds-arguments.rs:32:18 --> $DIR/out-of-bounds-arguments.rs:32:18
| |
LL | ${length(10)} LL | ${length(10)}

View File

@ -1,6 +1,6 @@
macro_rules! count { macro_rules! count {
( $( $e:stmt ),* ) => { ( $( $e:stmt ),* ) => {
${ count(e) } ${ count($e) }
//~^ ERROR meta-variable expressions are unstable //~^ ERROR meta-variable expressions are unstable
}; };
} }
@ -19,7 +19,7 @@ macro_rules! dollar_dollar {
macro_rules! index { macro_rules! index {
( $( $e:stmt ),* ) => { ( $( $e:stmt ),* ) => {
$( ${ignore(e)} ${index()} )* $( ${ignore($e)} ${index()} )*
//~^ ERROR meta-variable expressions are unstable //~^ ERROR meta-variable expressions are unstable
//~| ERROR meta-variable expressions are unstable //~| ERROR meta-variable expressions are unstable
}; };
@ -27,14 +27,14 @@ macro_rules! index {
macro_rules! ignore { macro_rules! ignore {
( $( $i:stmt ),* ) => {{ ( $( $i:stmt ),* ) => {{
0 $( + 1 ${ignore(i)} )* 0 $( + 1 ${ignore($i)} )*
//~^ ERROR meta-variable expressions are unstable //~^ ERROR meta-variable expressions are unstable
}}; }};
} }
macro_rules! length { macro_rules! length {
( $( $e:stmt ),* ) => { ( $( $e:stmt ),* ) => {
$( ${ignore(e)} ${length()} )* $( ${ignore($e)} ${length()} )*
//~^ ERROR meta-variable expressions are unstable //~^ ERROR meta-variable expressions are unstable
//~| ERROR meta-variable expressions are unstable //~| ERROR meta-variable expressions are unstable
}; };

View File

@ -1,8 +1,8 @@
error[E0658]: meta-variable expressions are unstable error[E0658]: meta-variable expressions are unstable
--> $DIR/required-feature.rs:3:10 --> $DIR/required-feature.rs:3:10
| |
LL | ${ count(e) } LL | ${ count($e) }
| ^^^^^^^^^^^^ | ^^^^^^^^^^^^^
| |
= note: see issue #83527 <https://github.com/rust-lang/rust/issues/83527> for more information = note: see issue #83527 <https://github.com/rust-lang/rust/issues/83527> for more information
= help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable
@ -46,16 +46,16 @@ LL | ( $$( $$any:tt )* ) => { $$( $$any )* };
error[E0658]: meta-variable expressions are unstable error[E0658]: meta-variable expressions are unstable
--> $DIR/required-feature.rs:22:13 --> $DIR/required-feature.rs:22:13
| |
LL | $( ${ignore(e)} ${index()} )* LL | $( ${ignore($e)} ${index()} )*
| ^^^^^^^^^^^ | ^^^^^^^^^^^^
| |
= note: see issue #83527 <https://github.com/rust-lang/rust/issues/83527> for more information = note: see issue #83527 <https://github.com/rust-lang/rust/issues/83527> for more information
= help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable
error[E0658]: meta-variable expressions are unstable error[E0658]: meta-variable expressions are unstable
--> $DIR/required-feature.rs:22:26 --> $DIR/required-feature.rs:22:27
| |
LL | $( ${ignore(e)} ${index()} )* LL | $( ${ignore($e)} ${index()} )*
| ^^^^^^^^^ | ^^^^^^^^^
| |
= note: see issue #83527 <https://github.com/rust-lang/rust/issues/83527> for more information = note: see issue #83527 <https://github.com/rust-lang/rust/issues/83527> for more information
@ -64,8 +64,8 @@ LL | $( ${ignore(e)} ${index()} )*
error[E0658]: meta-variable expressions are unstable error[E0658]: meta-variable expressions are unstable
--> $DIR/required-feature.rs:30:19 --> $DIR/required-feature.rs:30:19
| |
LL | 0 $( + 1 ${ignore(i)} )* LL | 0 $( + 1 ${ignore($i)} )*
| ^^^^^^^^^^^ | ^^^^^^^^^^^^
| |
= note: see issue #83527 <https://github.com/rust-lang/rust/issues/83527> for more information = note: see issue #83527 <https://github.com/rust-lang/rust/issues/83527> for more information
= help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable
@ -73,16 +73,16 @@ LL | 0 $( + 1 ${ignore(i)} )*
error[E0658]: meta-variable expressions are unstable error[E0658]: meta-variable expressions are unstable
--> $DIR/required-feature.rs:37:13 --> $DIR/required-feature.rs:37:13
| |
LL | $( ${ignore(e)} ${length()} )* LL | $( ${ignore($e)} ${length()} )*
| ^^^^^^^^^^^ | ^^^^^^^^^^^^
| |
= note: see issue #83527 <https://github.com/rust-lang/rust/issues/83527> for more information = note: see issue #83527 <https://github.com/rust-lang/rust/issues/83527> for more information
= help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable = help: add `#![feature(macro_metavar_expr)]` to the crate attributes to enable
error[E0658]: meta-variable expressions are unstable error[E0658]: meta-variable expressions are unstable
--> $DIR/required-feature.rs:37:26 --> $DIR/required-feature.rs:37:27
| |
LL | $( ${ignore(e)} ${length()} )* LL | $( ${ignore($e)} ${length()} )*
| ^^^^^^^^^^ | ^^^^^^^^^^
| |
= note: see issue #83527 <https://github.com/rust-lang/rust/issues/83527> for more information = note: see issue #83527 <https://github.com/rust-lang/rust/issues/83527> for more information

View File

@ -5,24 +5,17 @@
// `round` = Left hand side round brackets // `round` = Left hand side round brackets
macro_rules! curly__no_rhs_dollar__round { macro_rules! curly__no_rhs_dollar__round {
( $( $i:ident ),* ) => { ${ count(i) } }; ( $( $i:ident ),* ) => { ${ count($i) } };
} }
macro_rules! curly__no_rhs_dollar__no_round { macro_rules! curly__no_rhs_dollar__no_round {
( $i:ident ) => { ${ count(i) } }; ( $i:ident ) => { ${ count($i) } };
//~^ ERROR `count` can not be placed inside the inner-most repetition //~^ ERROR `count` can not be placed inside the inner-most repetition
} }
macro_rules! curly__rhs_dollar__round {
( $( $i:ident ),* ) => { ${ count($i) } };
//~^ ERROR expected identifier, found `$`
//~| ERROR expected expression, found `$`
}
macro_rules! curly__rhs_dollar__no_round { macro_rules! curly__rhs_dollar__no_round {
( $i:ident ) => { ${ count($i) } }; ( $i:ident ) => { ${ count($i) } };
//~^ ERROR expected identifier, found `$` //~^ ERROR `count` can not be placed inside the inner-most repetition
//~| ERROR expected expression, found `$`
} }
macro_rules! no_curly__no_rhs_dollar__round { macro_rules! no_curly__no_rhs_dollar__round {
@ -60,16 +53,16 @@ macro_rules! extra_garbage_after_metavar {
${count() a b c} ${count() a b c}
//~^ ERROR unexpected token: a //~^ ERROR unexpected token: a
//~| ERROR expected expression, found `$` //~| ERROR expected expression, found `$`
${count(i a b c)} ${count($i a b c)}
//~^ ERROR unexpected token: a //~^ ERROR unexpected token: a
${count(i, 1 a b c)} ${count($i, 1 a b c)}
//~^ ERROR unexpected token: a //~^ ERROR unexpected token: a
${count(i) a b c} ${count($i) a b c}
//~^ ERROR unexpected token: a //~^ ERROR unexpected token: a
${ignore(i) a b c} ${ignore($i) a b c}
//~^ ERROR unexpected token: a //~^ ERROR unexpected token: a
${ignore(i a b c)} ${ignore($i a b c)}
//~^ ERROR unexpected token: a //~^ ERROR unexpected token: a
${index() a b c} ${index() a b c}
@ -100,8 +93,8 @@ macro_rules! metavar_in_the_lhs {
macro_rules! metavar_token_without_ident { macro_rules! metavar_token_without_ident {
( $( $i:ident ),* ) => { ${ ignore() } }; ( $( $i:ident ),* ) => { ${ ignore() } };
//~^ ERROR expected identifier //~^ ERROR meta-variable expressions must be referenced using a dollar sign
//~| ERROR expected expression, found `$` //~| ERROR expected expression
} }
macro_rules! metavar_with_literal_suffix { macro_rules! metavar_with_literal_suffix {
@ -125,14 +118,16 @@ macro_rules! open_brackets_without_tokens {
macro_rules! unknown_count_ident { macro_rules! unknown_count_ident {
( $( $i:ident )* ) => { ( $( $i:ident )* ) => {
${count(foo)} ${count(foo)}
//~^ ERROR variable `foo` is not recognized in meta-variable expression //~^ ERROR meta-variable expressions must be referenced using a dollar sign
//~| ERROR expected expression
}; };
} }
macro_rules! unknown_ignore_ident { macro_rules! unknown_ignore_ident {
( $( $i:ident )* ) => { ( $( $i:ident )* ) => {
${ignore(bar)} ${ignore(bar)}
//~^ ERROR variable `bar` is not recognized in meta-variable expression //~^ ERROR meta-variable expressions must be referenced using a dollar sign
//~| ERROR expected expression
}; };
} }
@ -145,7 +140,6 @@ macro_rules! unknown_metavar {
fn main() { fn main() {
curly__no_rhs_dollar__round!(a, b, c); curly__no_rhs_dollar__round!(a, b, c);
curly__no_rhs_dollar__no_round!(a); curly__no_rhs_dollar__no_round!(a);
curly__rhs_dollar__round!(a, b, c);
curly__rhs_dollar__no_round!(a); curly__rhs_dollar__no_round!(a);
no_curly__no_rhs_dollar__round!(a, b, c); no_curly__no_rhs_dollar__round!(a, b, c);
no_curly__no_rhs_dollar__no_round!(a); no_curly__no_rhs_dollar__no_round!(a);

View File

@ -1,197 +1,197 @@
error: expected identifier, found `$`
--> $DIR/syntax-errors.rs:17:33
|
LL | ( $( $i:ident ),* ) => { ${ count($i) } };
| ^^^^^ - help: try removing `$`
error: expected identifier, found `$`
--> $DIR/syntax-errors.rs:23:26
|
LL | ( $i:ident ) => { ${ count($i) } };
| ^^^^^ - help: try removing `$`
error: unexpected token: $ error: unexpected token: $
--> $DIR/syntax-errors.rs:53:8 --> $DIR/syntax-errors.rs:46:8
| |
LL | ( $$ $a:ident ) => { LL | ( $$ $a:ident ) => {
| ^ | ^
note: `$$` and meta-variable expressions are not allowed inside macro parameter definitions note: `$$` and meta-variable expressions are not allowed inside macro parameter definitions
--> $DIR/syntax-errors.rs:53:8 --> $DIR/syntax-errors.rs:46:8
| |
LL | ( $$ $a:ident ) => { LL | ( $$ $a:ident ) => {
| ^ | ^
error: unexpected token: a error: unexpected token: a
--> $DIR/syntax-errors.rs:60:19 --> $DIR/syntax-errors.rs:53:19
| |
LL | ${count() a b c} LL | ${count() a b c}
| ^ | ^
| |
note: meta-variable expression must not have trailing tokens note: meta-variable expression must not have trailing tokens
--> $DIR/syntax-errors.rs:60:19 --> $DIR/syntax-errors.rs:53:19
| |
LL | ${count() a b c} LL | ${count() a b c}
| ^ | ^
error: unexpected token: a error: unexpected token: a
--> $DIR/syntax-errors.rs:63:19 --> $DIR/syntax-errors.rs:56:20
| |
LL | ${count(i a b c)} LL | ${count($i a b c)}
| ^ | ^
| |
note: meta-variable expression must not have trailing tokens note: meta-variable expression must not have trailing tokens
--> $DIR/syntax-errors.rs:63:19 --> $DIR/syntax-errors.rs:56:20
| |
LL | ${count(i a b c)} LL | ${count($i a b c)}
| ^ | ^
error: unexpected token: a error: unexpected token: a
--> $DIR/syntax-errors.rs:65:22 --> $DIR/syntax-errors.rs:58:23
| |
LL | ${count(i, 1 a b c)} LL | ${count($i, 1 a b c)}
| ^ | ^
| |
note: meta-variable expression must not have trailing tokens note: meta-variable expression must not have trailing tokens
--> $DIR/syntax-errors.rs:65:22 --> $DIR/syntax-errors.rs:58:23
| |
LL | ${count(i, 1 a b c)} LL | ${count($i, 1 a b c)}
| ^ | ^
error: unexpected token: a error: unexpected token: a
--> $DIR/syntax-errors.rs:67:20 --> $DIR/syntax-errors.rs:60:21
| |
LL | ${count(i) a b c} LL | ${count($i) a b c}
| ^ | ^
| |
note: meta-variable expression must not have trailing tokens note: meta-variable expression must not have trailing tokens
--> $DIR/syntax-errors.rs:67:20 --> $DIR/syntax-errors.rs:60:21
| |
LL | ${count(i) a b c} LL | ${count($i) a b c}
| ^ | ^
error: unexpected token: a error: unexpected token: a
--> $DIR/syntax-errors.rs:70:21 --> $DIR/syntax-errors.rs:63:22
| |
LL | ${ignore(i) a b c} LL | ${ignore($i) a b c}
| ^ | ^
| |
note: meta-variable expression must not have trailing tokens note: meta-variable expression must not have trailing tokens
--> $DIR/syntax-errors.rs:70:21 --> $DIR/syntax-errors.rs:63:22
| |
LL | ${ignore(i) a b c} LL | ${ignore($i) a b c}
| ^ | ^
error: unexpected token: a error: unexpected token: a
--> $DIR/syntax-errors.rs:72:20 --> $DIR/syntax-errors.rs:65:21
| |
LL | ${ignore(i a b c)} LL | ${ignore($i a b c)}
| ^ | ^
| |
note: meta-variable expression must not have trailing tokens note: meta-variable expression must not have trailing tokens
--> $DIR/syntax-errors.rs:72:20 --> $DIR/syntax-errors.rs:65:21
| |
LL | ${ignore(i a b c)} LL | ${ignore($i a b c)}
| ^
error: unexpected token: a
--> $DIR/syntax-errors.rs:68:19
|
LL | ${index() a b c}
| ^
|
note: meta-variable expression must not have trailing tokens
--> $DIR/syntax-errors.rs:68:19
|
LL | ${index() a b c}
| ^
error: unexpected token: a
--> $DIR/syntax-errors.rs:70:19
|
LL | ${index(1 a b c)}
| ^
|
note: meta-variable expression must not have trailing tokens
--> $DIR/syntax-errors.rs:70:19
|
LL | ${index(1 a b c)}
| ^
error: unexpected token: a
--> $DIR/syntax-errors.rs:73:19
|
LL | ${index() a b c}
| ^
|
note: meta-variable expression must not have trailing tokens
--> $DIR/syntax-errors.rs:73:19
|
LL | ${index() a b c}
| ^ | ^
error: unexpected token: a error: unexpected token: a
--> $DIR/syntax-errors.rs:75:19 --> $DIR/syntax-errors.rs:75:19
| |
LL | ${index() a b c} LL | ${index(1 a b c)}
| ^ | ^
| |
note: meta-variable expression must not have trailing tokens note: meta-variable expression must not have trailing tokens
--> $DIR/syntax-errors.rs:75:19 --> $DIR/syntax-errors.rs:75:19
| |
LL | ${index() a b c}
| ^
error: unexpected token: a
--> $DIR/syntax-errors.rs:77:19
|
LL | ${index(1 a b c)}
| ^
|
note: meta-variable expression must not have trailing tokens
--> $DIR/syntax-errors.rs:77:19
|
LL | ${index(1 a b c)}
| ^
error: unexpected token: a
--> $DIR/syntax-errors.rs:80:19
|
LL | ${index() a b c}
| ^
|
note: meta-variable expression must not have trailing tokens
--> $DIR/syntax-errors.rs:80:19
|
LL | ${index() a b c}
| ^
error: unexpected token: a
--> $DIR/syntax-errors.rs:82:19
|
LL | ${index(1 a b c)}
| ^
|
note: meta-variable expression must not have trailing tokens
--> $DIR/syntax-errors.rs:82:19
|
LL | ${index(1 a b c)} LL | ${index(1 a b c)}
| ^ | ^
error: meta-variable expression depth must be a literal error: meta-variable expression depth must be a literal
--> $DIR/syntax-errors.rs:89:33 --> $DIR/syntax-errors.rs:82:33
| |
LL | ( $( $i:ident ),* ) => { ${ index(IDX) } }; LL | ( $( $i:ident ),* ) => { ${ index(IDX) } };
| ^^^^^ | ^^^^^
error: unexpected token: { error: unexpected token: {
--> $DIR/syntax-errors.rs:95:8 --> $DIR/syntax-errors.rs:88:8
| |
LL | ( ${ length() } ) => { LL | ( ${ length() } ) => {
| ^^^^^^^^^^^^ | ^^^^^^^^^^^^
note: `$$` and meta-variable expressions are not allowed inside macro parameter definitions note: `$$` and meta-variable expressions are not allowed inside macro parameter definitions
--> $DIR/syntax-errors.rs:95:8 --> $DIR/syntax-errors.rs:88:8
| |
LL | ( ${ length() } ) => { LL | ( ${ length() } ) => {
| ^^^^^^^^^^^^ | ^^^^^^^^^^^^
error: expected one of: `*`, `+`, or `?` error: expected one of: `*`, `+`, or `?`
--> $DIR/syntax-errors.rs:95:8 --> $DIR/syntax-errors.rs:88:8
| |
LL | ( ${ length() } ) => { LL | ( ${ length() } ) => {
| ^^^^^^^^^^^^ | ^^^^^^^^^^^^
error: expected identifier error: meta-variables within meta-variable expressions must be referenced using a dollar sign
--> $DIR/syntax-errors.rs:102:33 --> $DIR/syntax-errors.rs:95:33
| |
LL | ( $( $i:ident ),* ) => { ${ ignore() } }; LL | ( $( $i:ident ),* ) => { ${ ignore() } };
| ^^^^^^ | ^^^^^^
error: only unsuffixes integer literals are supported in meta-variable expressions error: only unsuffixes integer literals are supported in meta-variable expressions
--> $DIR/syntax-errors.rs:108:33 --> $DIR/syntax-errors.rs:101:33
| |
LL | ( $( $i:ident ),* ) => { ${ index(1u32) } }; LL | ( $( $i:ident ),* ) => { ${ index(1u32) } };
| ^^^^^ | ^^^^^
error: meta-variable expression parameter must be wrapped in parentheses error: meta-variable expression parameter must be wrapped in parentheses
--> $DIR/syntax-errors.rs:114:33 --> $DIR/syntax-errors.rs:107:33
| |
LL | ( $( $i:ident ),* ) => { ${ count{i} } }; LL | ( $( $i:ident ),* ) => { ${ count{i} } };
| ^^^^^ | ^^^^^
error: expected identifier error: expected identifier
--> $DIR/syntax-errors.rs:120:31 --> $DIR/syntax-errors.rs:113:31
| |
LL | ( $( $i:ident ),* ) => { ${ {} } }; LL | ( $( $i:ident ),* ) => { ${ {} } };
| ^^^^^^ | ^^^^^^
error: meta-variables within meta-variable expressions must be referenced using a dollar sign
--> $DIR/syntax-errors.rs:120:11
|
LL | ${count(foo)}
| ^^^^^
error: meta-variables within meta-variable expressions must be referenced using a dollar sign
--> $DIR/syntax-errors.rs:128:11
|
LL | ${ignore(bar)}
| ^^^^^^
error: unrecognized meta-variable expression error: unrecognized meta-variable expression
--> $DIR/syntax-errors.rs:140:33 --> $DIR/syntax-errors.rs:135:33
| |
LL | ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } }; LL | ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } };
| ^^^^^^^^^^^^^^ help: supported expressions are count, ignore, index and length | ^^^^^^^^^^^^^^ help: supported expressions are count, ignore, index and length
@ -199,39 +199,23 @@ LL | ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } };
error: `count` can not be placed inside the inner-most repetition error: `count` can not be placed inside the inner-most repetition
--> $DIR/syntax-errors.rs:12:24 --> $DIR/syntax-errors.rs:12:24
| |
LL | ( $i:ident ) => { ${ count(i) } }; LL | ( $i:ident ) => { ${ count($i) } };
| ^^^^^^^^^^^^ | ^^^^^^^^^^^^^
error: expected expression, found `$` error: `count` can not be placed inside the inner-most repetition
--> $DIR/syntax-errors.rs:17:30 --> $DIR/syntax-errors.rs:17:24
|
LL | ( $( $i:ident ),* ) => { ${ count($i) } };
| ^ expected expression
...
LL | curly__rhs_dollar__round!(a, b, c);
| ---------------------------------- in this macro invocation
|
= note: this error originates in the macro `curly__rhs_dollar__round` (in Nightly builds, run with -Z macro-backtrace for more info)
error: expected expression, found `$`
--> $DIR/syntax-errors.rs:23:23
| |
LL | ( $i:ident ) => { ${ count($i) } }; LL | ( $i:ident ) => { ${ count($i) } };
| ^ expected expression | ^^^^^^^^^^^^^
...
LL | curly__rhs_dollar__no_round!(a);
| ------------------------------- in this macro invocation
|
= note: this error originates in the macro `curly__rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info)
error: variable 'i' is still repeating at this depth error: variable 'i' is still repeating at this depth
--> $DIR/syntax-errors.rs:41:36 --> $DIR/syntax-errors.rs:34:36
| |
LL | ( $( $i:ident ),* ) => { count($i) }; LL | ( $( $i:ident ),* ) => { count($i) };
| ^^ | ^^
error: expected expression, found `$` error: expected expression, found `$`
--> $DIR/syntax-errors.rs:60:9 --> $DIR/syntax-errors.rs:53:9
| |
LL | ${count() a b c} LL | ${count() a b c}
| ^ expected expression | ^ expected expression
@ -242,7 +226,7 @@ LL | extra_garbage_after_metavar!(a);
= note: this error originates in the macro `extra_garbage_after_metavar` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `extra_garbage_after_metavar` (in Nightly builds, run with -Z macro-backtrace for more info)
error: expected expression, found `$` error: expected expression, found `$`
--> $DIR/syntax-errors.rs:89:30 --> $DIR/syntax-errors.rs:82:30
| |
LL | ( $( $i:ident ),* ) => { ${ index(IDX) } }; LL | ( $( $i:ident ),* ) => { ${ index(IDX) } };
| ^ expected expression | ^ expected expression
@ -253,7 +237,7 @@ LL | metavar_depth_is_not_literal!(a);
= note: this error originates in the macro `metavar_depth_is_not_literal` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `metavar_depth_is_not_literal` (in Nightly builds, run with -Z macro-backtrace for more info)
error: expected expression, found `$` error: expected expression, found `$`
--> $DIR/syntax-errors.rs:102:30 --> $DIR/syntax-errors.rs:95:30
| |
LL | ( $( $i:ident ),* ) => { ${ ignore() } }; LL | ( $( $i:ident ),* ) => { ${ ignore() } };
| ^ expected expression | ^ expected expression
@ -264,7 +248,7 @@ LL | metavar_token_without_ident!(a);
= note: this error originates in the macro `metavar_token_without_ident` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `metavar_token_without_ident` (in Nightly builds, run with -Z macro-backtrace for more info)
error: expected expression, found `$` error: expected expression, found `$`
--> $DIR/syntax-errors.rs:108:30 --> $DIR/syntax-errors.rs:101:30
| |
LL | ( $( $i:ident ),* ) => { ${ index(1u32) } }; LL | ( $( $i:ident ),* ) => { ${ index(1u32) } };
| ^ expected expression | ^ expected expression
@ -275,7 +259,7 @@ LL | metavar_with_literal_suffix!(a);
= note: this error originates in the macro `metavar_with_literal_suffix` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `metavar_with_literal_suffix` (in Nightly builds, run with -Z macro-backtrace for more info)
error: expected expression, found `$` error: expected expression, found `$`
--> $DIR/syntax-errors.rs:114:30 --> $DIR/syntax-errors.rs:107:30
| |
LL | ( $( $i:ident ),* ) => { ${ count{i} } }; LL | ( $( $i:ident ),* ) => { ${ count{i} } };
| ^ expected expression | ^ expected expression
@ -286,7 +270,7 @@ LL | metavar_without_parens!(a);
= note: this error originates in the macro `metavar_without_parens` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `metavar_without_parens` (in Nightly builds, run with -Z macro-backtrace for more info)
error: expected expression, found `$` error: expected expression, found `$`
--> $DIR/syntax-errors.rs:120:30 --> $DIR/syntax-errors.rs:113:30
| |
LL | ( $( $i:ident ),* ) => { ${ {} } }; LL | ( $( $i:ident ),* ) => { ${ {} } };
| ^ expected expression | ^ expected expression
@ -296,20 +280,30 @@ LL | open_brackets_without_tokens!(a);
| |
= note: this error originates in the macro `open_brackets_without_tokens` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `open_brackets_without_tokens` (in Nightly builds, run with -Z macro-backtrace for more info)
error: variable `foo` is not recognized in meta-variable expression error: expected expression, found `$`
--> $DIR/syntax-errors.rs:127:17 --> $DIR/syntax-errors.rs:120:9
| |
LL | ${count(foo)} LL | ${count(foo)}
| ^^^ | ^ expected expression
...
error: variable `bar` is not recognized in meta-variable expression LL | unknown_count_ident!(a);
--> $DIR/syntax-errors.rs:134:18 | ----------------------- in this macro invocation
| |
LL | ${ignore(bar)} = note: this error originates in the macro `unknown_count_ident` (in Nightly builds, run with -Z macro-backtrace for more info)
| ^^^
error: expected expression, found `$` error: expected expression, found `$`
--> $DIR/syntax-errors.rs:140:30 --> $DIR/syntax-errors.rs:128:9
|
LL | ${ignore(bar)}
| ^ expected expression
...
LL | unknown_ignore_ident!(a);
| ------------------------ in this macro invocation
|
= note: this error originates in the macro `unknown_ignore_ident` (in Nightly builds, run with -Z macro-backtrace for more info)
error: expected expression, found `$`
--> $DIR/syntax-errors.rs:135:30
| |
LL | ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } }; LL | ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } };
| ^ expected expression | ^ expected expression
@ -320,7 +314,7 @@ LL | unknown_metavar!(a);
= note: this error originates in the macro `unknown_metavar` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `unknown_metavar` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0425]: cannot find value `i` in this scope error[E0425]: cannot find value `i` in this scope
--> $DIR/syntax-errors.rs:29:36 --> $DIR/syntax-errors.rs:22:36
| |
LL | ( $( $i:ident ),* ) => { count(i) }; LL | ( $( $i:ident ),* ) => { count(i) };
| ^ not found in this scope | ^ not found in this scope
@ -331,7 +325,7 @@ LL | no_curly__no_rhs_dollar__round!(a, b, c);
= note: this error originates in the macro `no_curly__no_rhs_dollar__round` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `no_curly__no_rhs_dollar__round` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0425]: cannot find value `i` in this scope error[E0425]: cannot find value `i` in this scope
--> $DIR/syntax-errors.rs:35:29 --> $DIR/syntax-errors.rs:28:29
| |
LL | ( $i:ident ) => { count(i) }; LL | ( $i:ident ) => { count(i) };
| ^ not found in this scope | ^ not found in this scope
@ -342,13 +336,13 @@ LL | no_curly__no_rhs_dollar__no_round!(a);
= note: this error originates in the macro `no_curly__no_rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `no_curly__no_rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0425]: cannot find value `a` in this scope error[E0425]: cannot find value `a` in this scope
--> $DIR/syntax-errors.rs:153:37 --> $DIR/syntax-errors.rs:147:37
| |
LL | no_curly__rhs_dollar__no_round!(a); LL | no_curly__rhs_dollar__no_round!(a);
| ^ not found in this scope | ^ not found in this scope
error[E0425]: cannot find function `count` in this scope error[E0425]: cannot find function `count` in this scope
--> $DIR/syntax-errors.rs:29:30 --> $DIR/syntax-errors.rs:22:30
| |
LL | ( $( $i:ident ),* ) => { count(i) }; LL | ( $( $i:ident ),* ) => { count(i) };
| ^^^^^ not found in this scope | ^^^^^ not found in this scope
@ -359,7 +353,7 @@ LL | no_curly__no_rhs_dollar__round!(a, b, c);
= note: this error originates in the macro `no_curly__no_rhs_dollar__round` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `no_curly__no_rhs_dollar__round` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0425]: cannot find function `count` in this scope error[E0425]: cannot find function `count` in this scope
--> $DIR/syntax-errors.rs:35:23 --> $DIR/syntax-errors.rs:28:23
| |
LL | ( $i:ident ) => { count(i) }; LL | ( $i:ident ) => { count(i) };
| ^^^^^ not found in this scope | ^^^^^ not found in this scope
@ -370,7 +364,7 @@ LL | no_curly__no_rhs_dollar__no_round!(a);
= note: this error originates in the macro `no_curly__no_rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `no_curly__no_rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0425]: cannot find function `count` in this scope error[E0425]: cannot find function `count` in this scope
--> $DIR/syntax-errors.rs:46:23 --> $DIR/syntax-errors.rs:39:23
| |
LL | ( $i:ident ) => { count($i) }; LL | ( $i:ident ) => { count($i) };
| ^^^^^ not found in this scope | ^^^^^ not found in this scope
@ -380,6 +374,6 @@ LL | no_curly__rhs_dollar__no_round!(a);
| |
= note: this error originates in the macro `no_curly__rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `no_curly__rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 40 previous errors error: aborting due to 39 previous errors
For more information about this error, try `rustc --explain E0425`. For more information about this error, try `rustc --explain E0425`.