-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[1/2] Implement macro meta-variable expressions #94368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bors
merged 1 commit into
rust-lang:master
from
c410-f3r:metaaaaaaaaaaaaaaaaaaaaaaaaaaa
Mar 11, 2022
+900
−44
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
use rustc_ast::token; | ||
use rustc_ast::tokenstream::{Cursor, TokenStream, TokenTree}; | ||
use rustc_ast::{LitIntType, LitKind}; | ||
use rustc_ast_pretty::pprust; | ||
use rustc_errors::{Applicability, PResult}; | ||
use rustc_session::parse::ParseSess; | ||
use rustc_span::symbol::Ident; | ||
use rustc_span::Span; | ||
|
||
/// A meta-variable expression, for expansions based on properties of meta-variables. | ||
#[derive(Debug, Clone, PartialEq, Encodable, Decodable)] | ||
crate enum MetaVarExpr { | ||
/// The number of repetitions of an identifier, optionally limited to a number | ||
/// of outer-most repetition depths. If the depth limit is `None` then the depth is unlimited. | ||
Count(Ident, Option<usize>), | ||
|
||
/// Ignore a meta-variable for repetition without expansion. | ||
Ignore(Ident), | ||
|
||
/// The index of the repetition at a particular depth, where 0 is the inner-most | ||
/// repetition. The `usize` is the depth. | ||
Index(usize), | ||
|
||
/// The length of the repetition at a particular depth, where 0 is the inner-most | ||
/// repetition. The `usize` is the depth. | ||
Length(usize), | ||
} | ||
|
||
impl MetaVarExpr { | ||
/// Attempt to parse a meta-variable expression from a token stream. | ||
crate fn parse<'sess>( | ||
input: &TokenStream, | ||
outer_span: Span, | ||
sess: &'sess ParseSess, | ||
) -> PResult<'sess, MetaVarExpr> { | ||
let mut tts = input.trees(); | ||
let ident = parse_ident(&mut tts, sess, outer_span)?; | ||
let Some(TokenTree::Delimited(_, token::Paren, args)) = tts.next() else { | ||
let msg = "meta-variable expression parameter must be wrapped in parentheses"; | ||
return Err(sess.span_diagnostic.struct_span_err(ident.span, msg)); | ||
}; | ||
check_trailing_token(&mut tts, sess)?; | ||
let mut iter = args.trees(); | ||
let rslt = match &*ident.as_str() { | ||
"count" => parse_count(&mut iter, sess, ident.span)?, | ||
"ignore" => MetaVarExpr::Ignore(parse_ident(&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)?), | ||
c410-f3r marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_ => { | ||
let err_msg = "unrecognized meta-variable expression"; | ||
let mut err = sess.span_diagnostic.struct_span_err(ident.span, err_msg); | ||
err.span_suggestion( | ||
ident.span, | ||
"supported expressions are count, ignore, index and length", | ||
String::new(), | ||
Applicability::MachineApplicable, | ||
); | ||
return Err(err); | ||
} | ||
}; | ||
check_trailing_token(&mut iter, sess)?; | ||
Ok(rslt) | ||
} | ||
|
||
crate fn ident(&self) -> Option<&Ident> { | ||
match self { | ||
MetaVarExpr::Count(ident, _) | MetaVarExpr::Ignore(ident) => Some(&ident), | ||
MetaVarExpr::Index(..) | MetaVarExpr::Length(..) => None, | ||
} | ||
} | ||
} | ||
|
||
// Checks if there are any remaining tokens. For example, `${ignore(ident ... a b c ...)}` | ||
fn check_trailing_token<'sess>(iter: &mut Cursor, sess: &'sess ParseSess) -> PResult<'sess, ()> { | ||
if let Some(tt) = iter.next() { | ||
let mut diag = sess.span_diagnostic.struct_span_err( | ||
tt.span(), | ||
&format!("unexpected token: {}", pprust::tt_to_string(&tt)), | ||
); | ||
diag.span_note(tt.span(), "meta-variable expression must not have trailing tokens"); | ||
Err(diag) | ||
} else { | ||
Ok(()) | ||
} | ||
} | ||
|
||
/// Parse a meta-variable `count` expression: `count(ident[, depth])` | ||
fn parse_count<'sess>( | ||
iter: &mut Cursor, | ||
sess: &'sess ParseSess, | ||
span: Span, | ||
) -> PResult<'sess, MetaVarExpr> { | ||
let ident = parse_ident(iter, sess, span)?; | ||
let depth = if try_eat_comma(iter) { Some(parse_depth(iter, sess, span)?) } else { None }; | ||
Ok(MetaVarExpr::Count(ident, depth)) | ||
} | ||
|
||
/// Parses the depth used by index(depth) and length(depth). | ||
fn parse_depth<'sess>( | ||
iter: &mut Cursor, | ||
sess: &'sess ParseSess, | ||
span: Span, | ||
) -> PResult<'sess, usize> { | ||
let Some(tt) = iter.next() else { return Ok(0) }; | ||
let TokenTree::Token(token::Token { | ||
kind: token::TokenKind::Literal(lit), .. | ||
}) = tt else { | ||
return Err(sess.span_diagnostic.struct_span_err( | ||
span, | ||
"meta-variable expression depth must be a literal" | ||
)); | ||
}; | ||
if let Ok(lit_kind) = LitKind::from_lit_token(lit) | ||
&& let LitKind::Int(n_u128, LitIntType::Unsuffixed) = lit_kind | ||
&& let Ok(n_usize) = usize::try_from(n_u128) | ||
{ | ||
Ok(n_usize) | ||
} | ||
else { | ||
let msg = "only unsuffixes integer literals are supported in meta-variable expressions"; | ||
Err(sess.span_diagnostic.struct_span_err(span, msg)) | ||
} | ||
} | ||
|
||
/// Parses an generic ident | ||
fn parse_ident<'sess>( | ||
iter: &mut Cursor, | ||
sess: &'sess ParseSess, | ||
span: Span, | ||
) -> PResult<'sess, Ident> { | ||
let err_fn = |msg| sess.span_diagnostic.struct_span_err(span, msg); | ||
if let Some(tt) = iter.next() && let TokenTree::Token(token) = tt { | ||
if let Some((elem, false)) = token.ident() { | ||
return Ok(elem); | ||
} | ||
let token_str = pprust::token_to_string(&token); | ||
let mut err = err_fn(&format!("expected identifier, found `{}`", &token_str)); | ||
err.span_suggestion( | ||
token.span, | ||
&format!("try removing `{}`", &token_str), | ||
String::new(), | ||
Applicability::MaybeIncorrect, | ||
); | ||
return Err(err); | ||
} | ||
Err(err_fn("expected identifier")) | ||
} | ||
|
||
/// Tries to move the iterator forward returning `true` if there is a comma. If not, then the | ||
/// iterator is not modified and the result is `false`. | ||
fn try_eat_comma(iter: &mut Cursor) -> bool { | ||
if let Some(TokenTree::Token(token::Token { kind: token::Comma, .. })) = iter.look_ahead(0) { | ||
let _ = iter.next(); | ||
return true; | ||
} | ||
false | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/test/ui/macros/rfc-3086-metavar-expr/dollar-dollar-has-correct-behavior.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// run-pass | ||
|
||
#![feature(macro_metavar_expr)] | ||
|
||
macro_rules! nested { | ||
( $a:ident ) => { | ||
macro_rules! $a { | ||
( $$( $b:ident ),* ) => { | ||
$$( | ||
macro_rules! $b { | ||
( $$$$( $c:ident ),* ) => { | ||
$$$$( | ||
fn $c() -> &'static str { stringify!($c) } | ||
),* | ||
}; | ||
} | ||
)* | ||
}; | ||
} | ||
}; | ||
} | ||
|
||
fn main() { | ||
nested!(a); | ||
a!(b); | ||
b!(c); | ||
assert_eq!(c(), "c"); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/test/ui/macros/rfc-3086-metavar-expr/feature-gate-macro_metavar_expr.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// run-pass | ||
|
||
#![feature(macro_metavar_expr)] | ||
|
||
macro_rules! ignore { | ||
( $( $i:ident ),* ) => {{ | ||
let array: [i32; 0] = [$( ${ignore(i)} )*]; | ||
array | ||
}}; | ||
} | ||
|
||
fn main() { | ||
assert_eq!(ignore!(a, b, c), []); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
macro_rules! count { | ||
( $( $e:stmt ),* ) => { | ||
${ count(e) } | ||
//~^ ERROR meta-variable expressions are unstable | ||
}; | ||
} | ||
|
||
fn main() { | ||
} |
12 changes: 12 additions & 0 deletions
12
src/test/ui/macros/rfc-3086-metavar-expr/required-feature.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0658]: meta-variable expressions are unstable | ||
--> $DIR/required-feature.rs:3:10 | ||
| | ||
LL | ${ count(e) } | ||
| ^^^^^^^^^^^^ | ||
| | ||
= 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 | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
148 changes: 148 additions & 0 deletions
148
src/test/ui/macros/rfc-3086-metavar-expr/syntax-errors.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
#![feature(macro_metavar_expr)] | ||
|
||
// `curly` = Right hand side curly brackets | ||
// `no_rhs_dollar` = No dollar sign at the right hand side meta variable "function" | ||
// `round` = Left hand side round brackets | ||
|
||
macro_rules! curly__no_rhs_dollar__round { | ||
( $( $i:ident ),* ) => { ${ count(i) } }; | ||
} | ||
|
||
macro_rules! curly__no_rhs_dollar__no_round { | ||
( $i:ident ) => { ${ count(i) } }; | ||
} | ||
|
||
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 { | ||
( $i:ident ) => { ${ count($i) } }; | ||
//~^ ERROR expected identifier, found `$` | ||
//~| ERROR expected expression, found `$` | ||
} | ||
|
||
macro_rules! no_curly__no_rhs_dollar__round { | ||
( $( $i:ident ),* ) => { count(i) }; | ||
//~^ ERROR cannot find function `count` in this scope | ||
//~| ERROR cannot find value `i` in this scope | ||
} | ||
|
||
macro_rules! no_curly__no_rhs_dollar__no_round { | ||
( $i:ident ) => { count(i) }; | ||
//~^ ERROR cannot find function `count` in this scope | ||
//~| ERROR cannot find value `i` in this scope | ||
} | ||
|
||
macro_rules! no_curly__rhs_dollar__round { | ||
( $( $i:ident ),* ) => { count($i) }; | ||
//~^ ERROR variable 'i' is still repeating at this depth | ||
} | ||
|
||
macro_rules! no_curly__rhs_dollar__no_round { | ||
( $i:ident ) => { count($i) }; | ||
//~^ ERROR cannot find function `count` in this scope | ||
} | ||
|
||
// Other scenarios | ||
|
||
macro_rules! dollar_dollar_in_the_lhs { | ||
( $$ $a:ident ) => { | ||
//~^ ERROR unexpected token: $ | ||
}; | ||
} | ||
|
||
macro_rules! extra_garbage_after_metavar { | ||
( $( $i:ident ),* ) => { | ||
${count() a b c} | ||
//~^ ERROR unexpected token: a | ||
//~| ERROR expected expression, found `$` | ||
${count(i a b c)} | ||
//~^ ERROR unexpected token: a | ||
${count(i, 1 a b c)} | ||
//~^ ERROR unexpected token: a | ||
${count(i) a b c} | ||
//~^ ERROR unexpected token: a | ||
|
||
${ignore(i) a b c} | ||
//~^ ERROR unexpected token: a | ||
${ignore(i a b c)} | ||
//~^ ERROR unexpected token: a | ||
|
||
${index() a b c} | ||
//~^ ERROR unexpected token: a | ||
${index(1 a b c)} | ||
//~^ ERROR unexpected token: a | ||
|
||
${index() a b c} | ||
//~^ ERROR unexpected token: a | ||
${index(1 a b c)} | ||
//~^ ERROR unexpected token: a | ||
}; | ||
} | ||
|
||
const IDX: usize = 1; | ||
macro_rules! metavar_depth_is_not_literal { | ||
( $( $i:ident ),* ) => { ${ index(IDX) } }; | ||
//~^ ERROR meta-variable expression depth must be a literal | ||
//~| ERROR expected expression, found `$` | ||
} | ||
|
||
macro_rules! metavar_in_the_lhs { | ||
( ${ length() } ) => { | ||
//~^ ERROR unexpected token: { | ||
//~| ERROR expected one of: `*`, `+`, or `?` | ||
}; | ||
} | ||
|
||
macro_rules! metavar_token_without_ident { | ||
( $( $i:ident ),* ) => { ${ ignore() } }; | ||
//~^ ERROR expected identifier | ||
//~| ERROR expected expression, found `$` | ||
} | ||
|
||
macro_rules! metavar_with_literal_suffix { | ||
( $( $i:ident ),* ) => { ${ index(1u32) } }; | ||
//~^ ERROR only unsuffixes integer literals are supported in meta-variable expressions | ||
//~| ERROR expected expression, found `$` | ||
} | ||
|
||
macro_rules! metavar_without_parens { | ||
( $( $i:ident ),* ) => { ${ count{i} } }; | ||
//~^ ERROR meta-variable expression parameter must be wrapped in parentheses | ||
//~| ERROR expected expression, found `$` | ||
} | ||
|
||
macro_rules! open_brackets_without_tokens { | ||
( $( $i:ident ),* ) => { ${ {} } }; | ||
//~^ ERROR expected expression, found `$` | ||
//~| ERROR expected identifier | ||
} | ||
|
||
macro_rules! unknown_metavar { | ||
( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } }; | ||
//~^ ERROR unrecognized meta-variable expression | ||
//~| ERROR expected expression | ||
} | ||
|
||
fn main() { | ||
curly__no_rhs_dollar__round!(a, b, c); | ||
curly__no_rhs_dollar__no_round!(a); | ||
curly__rhs_dollar__round!(a, b, c); | ||
curly__rhs_dollar__no_round!(a); | ||
no_curly__no_rhs_dollar__round!(a, b, c); | ||
no_curly__no_rhs_dollar__no_round!(a); | ||
no_curly__rhs_dollar__round!(a, b, c); | ||
no_curly__rhs_dollar__no_round!(a); | ||
//~^ ERROR cannot find value `a` in this scope | ||
|
||
extra_garbage_after_metavar!(a); | ||
unknown_metavar!(a); | ||
metavar_without_parens!(a); | ||
metavar_token_without_ident!(a); | ||
metavar_depth_is_not_literal!(a); | ||
metavar_with_literal_suffix!(a); | ||
open_brackets_without_tokens!(a) | ||
} |
367 changes: 367 additions & 0 deletions
367
src/test/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,367 @@ | ||
error: expected identifier, found `$` | ||
--> $DIR/syntax-errors.rs:16:33 | ||
| | ||
LL | ( $( $i:ident ),* ) => { ${ count($i) } }; | ||
| ^^^^^ - help: try removing `$` | ||
|
||
error: expected identifier, found `$` | ||
--> $DIR/syntax-errors.rs:22:26 | ||
| | ||
LL | ( $i:ident ) => { ${ count($i) } }; | ||
| ^^^^^ - help: try removing `$` | ||
|
||
error: unexpected token: $ | ||
--> $DIR/syntax-errors.rs:52:8 | ||
| | ||
LL | ( $$ $a:ident ) => { | ||
| ^ | ||
|
||
note: `$$` and meta-variable expressions are not allowed inside macro parameter definitions | ||
--> $DIR/syntax-errors.rs:52:8 | ||
| | ||
LL | ( $$ $a:ident ) => { | ||
| ^ | ||
|
||
error: unexpected token: a | ||
--> $DIR/syntax-errors.rs:59:19 | ||
| | ||
LL | ${count() a b c} | ||
| ^ | ||
| | ||
note: meta-variable expression must not have trailing tokens | ||
--> $DIR/syntax-errors.rs:59:19 | ||
| | ||
LL | ${count() a b c} | ||
| ^ | ||
|
||
error: unexpected token: a | ||
--> $DIR/syntax-errors.rs:62:19 | ||
| | ||
LL | ${count(i a b c)} | ||
| ^ | ||
| | ||
note: meta-variable expression must not have trailing tokens | ||
--> $DIR/syntax-errors.rs:62:19 | ||
| | ||
LL | ${count(i a b c)} | ||
| ^ | ||
|
||
error: unexpected token: a | ||
--> $DIR/syntax-errors.rs:64:22 | ||
| | ||
LL | ${count(i, 1 a b c)} | ||
| ^ | ||
| | ||
note: meta-variable expression must not have trailing tokens | ||
--> $DIR/syntax-errors.rs:64:22 | ||
| | ||
LL | ${count(i, 1 a b c)} | ||
| ^ | ||
|
||
error: unexpected token: a | ||
--> $DIR/syntax-errors.rs:66:20 | ||
| | ||
LL | ${count(i) a b c} | ||
| ^ | ||
| | ||
note: meta-variable expression must not have trailing tokens | ||
--> $DIR/syntax-errors.rs:66:20 | ||
| | ||
LL | ${count(i) a b c} | ||
| ^ | ||
|
||
error: unexpected token: a | ||
--> $DIR/syntax-errors.rs:69:21 | ||
| | ||
LL | ${ignore(i) a b c} | ||
| ^ | ||
| | ||
note: meta-variable expression must not have trailing tokens | ||
--> $DIR/syntax-errors.rs:69:21 | ||
| | ||
LL | ${ignore(i) a b c} | ||
| ^ | ||
|
||
error: unexpected token: a | ||
--> $DIR/syntax-errors.rs:71:20 | ||
| | ||
LL | ${ignore(i a b c)} | ||
| ^ | ||
| | ||
note: meta-variable expression must not have trailing tokens | ||
--> $DIR/syntax-errors.rs:71:20 | ||
| | ||
LL | ${ignore(i a b c)} | ||
| ^ | ||
|
||
error: unexpected token: a | ||
--> $DIR/syntax-errors.rs:74:19 | ||
| | ||
LL | ${index() a b c} | ||
| ^ | ||
| | ||
note: meta-variable expression must not have trailing tokens | ||
--> $DIR/syntax-errors.rs:74:19 | ||
| | ||
LL | ${index() a b c} | ||
| ^ | ||
|
||
error: unexpected token: a | ||
--> $DIR/syntax-errors.rs:76:19 | ||
| | ||
LL | ${index(1 a b c)} | ||
| ^ | ||
| | ||
note: meta-variable expression must not have trailing tokens | ||
--> $DIR/syntax-errors.rs:76:19 | ||
| | ||
LL | ${index(1 a b c)} | ||
| ^ | ||
|
||
error: unexpected token: a | ||
--> $DIR/syntax-errors.rs:79:19 | ||
| | ||
LL | ${index() a b c} | ||
| ^ | ||
| | ||
note: meta-variable expression must not have trailing tokens | ||
--> $DIR/syntax-errors.rs:79:19 | ||
| | ||
LL | ${index() a b c} | ||
| ^ | ||
|
||
error: unexpected token: a | ||
--> $DIR/syntax-errors.rs:81:19 | ||
| | ||
LL | ${index(1 a b c)} | ||
| ^ | ||
| | ||
note: meta-variable expression must not have trailing tokens | ||
--> $DIR/syntax-errors.rs:81:19 | ||
| | ||
LL | ${index(1 a b c)} | ||
| ^ | ||
|
||
error: meta-variable expression depth must be a literal | ||
--> $DIR/syntax-errors.rs:88:33 | ||
| | ||
LL | ( $( $i:ident ),* ) => { ${ index(IDX) } }; | ||
| ^^^^^ | ||
|
||
error: unexpected token: { | ||
--> $DIR/syntax-errors.rs:94:8 | ||
| | ||
LL | ( ${ length() } ) => { | ||
| ^^^^^^^^^^^^ | ||
|
||
note: `$$` and meta-variable expressions are not allowed inside macro parameter definitions | ||
--> $DIR/syntax-errors.rs:94:8 | ||
| | ||
LL | ( ${ length() } ) => { | ||
| ^^^^^^^^^^^^ | ||
|
||
error: expected one of: `*`, `+`, or `?` | ||
--> $DIR/syntax-errors.rs:94:8 | ||
| | ||
LL | ( ${ length() } ) => { | ||
| ^^^^^^^^^^^^ | ||
|
||
error: expected identifier | ||
--> $DIR/syntax-errors.rs:101:33 | ||
| | ||
LL | ( $( $i:ident ),* ) => { ${ ignore() } }; | ||
| ^^^^^^ | ||
|
||
error: only unsuffixes integer literals are supported in meta-variable expressions | ||
--> $DIR/syntax-errors.rs:107:33 | ||
| | ||
LL | ( $( $i:ident ),* ) => { ${ index(1u32) } }; | ||
| ^^^^^ | ||
|
||
error: meta-variable expression parameter must be wrapped in parentheses | ||
--> $DIR/syntax-errors.rs:113:33 | ||
| | ||
LL | ( $( $i:ident ),* ) => { ${ count{i} } }; | ||
| ^^^^^ | ||
|
||
error: expected identifier | ||
--> $DIR/syntax-errors.rs:119:31 | ||
| | ||
LL | ( $( $i:ident ),* ) => { ${ {} } }; | ||
| ^^^^^^ | ||
|
||
error: unrecognized meta-variable expression | ||
--> $DIR/syntax-errors.rs:125:33 | ||
| | ||
LL | ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } }; | ||
| ^^^^^^^^^^^^^^ help: supported expressions are count, ignore, index and length | ||
|
||
error: expected expression, found `$` | ||
--> $DIR/syntax-errors.rs:16:30 | ||
| | ||
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:22:23 | ||
| | ||
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 | ||
--> $DIR/syntax-errors.rs:40:36 | ||
| | ||
LL | ( $( $i:ident ),* ) => { count($i) }; | ||
| ^^ | ||
|
||
error: expected expression, found `$` | ||
--> $DIR/syntax-errors.rs:59:9 | ||
| | ||
LL | ${count() a b c} | ||
| ^ expected expression | ||
... | ||
LL | extra_garbage_after_metavar!(a); | ||
| ------------------------------- in this macro invocation | ||
| | ||
= 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 `$` | ||
--> $DIR/syntax-errors.rs:125:30 | ||
| | ||
LL | ( $( $i:ident ),* ) => { ${ aaaaaaaaaaaaaa(i) } }; | ||
| ^ expected expression | ||
... | ||
LL | unknown_metavar!(a); | ||
| ------------------- in this macro invocation | ||
| | ||
= note: this error originates in the macro `unknown_metavar` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: expected expression, found `$` | ||
--> $DIR/syntax-errors.rs:113:30 | ||
| | ||
LL | ( $( $i:ident ),* ) => { ${ count{i} } }; | ||
| ^ expected expression | ||
... | ||
LL | metavar_without_parens!(a); | ||
| -------------------------- in this macro invocation | ||
| | ||
= 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 `$` | ||
--> $DIR/syntax-errors.rs:101:30 | ||
| | ||
LL | ( $( $i:ident ),* ) => { ${ ignore() } }; | ||
| ^ expected expression | ||
... | ||
LL | metavar_token_without_ident!(a); | ||
| ------------------------------- in this macro invocation | ||
| | ||
= 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 `$` | ||
--> $DIR/syntax-errors.rs:88:30 | ||
| | ||
LL | ( $( $i:ident ),* ) => { ${ index(IDX) } }; | ||
| ^ expected expression | ||
... | ||
LL | metavar_depth_is_not_literal!(a); | ||
| -------------------------------- in this macro invocation | ||
| | ||
= 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 `$` | ||
--> $DIR/syntax-errors.rs:107:30 | ||
| | ||
LL | ( $( $i:ident ),* ) => { ${ index(1u32) } }; | ||
| ^ expected expression | ||
... | ||
LL | metavar_with_literal_suffix!(a); | ||
| ------------------------------- in this macro invocation | ||
| | ||
= 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 `$` | ||
--> $DIR/syntax-errors.rs:119:30 | ||
| | ||
LL | ( $( $i:ident ),* ) => { ${ {} } }; | ||
| ^ expected expression | ||
... | ||
LL | open_brackets_without_tokens!(a) | ||
| -------------------------------- in this macro invocation | ||
| | ||
= note: this error originates in the macro `open_brackets_without_tokens` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0425]: cannot find function `count` in this scope | ||
--> $DIR/syntax-errors.rs:28:30 | ||
| | ||
LL | ( $( $i:ident ),* ) => { count(i) }; | ||
| ^^^^^ not found in this scope | ||
... | ||
LL | no_curly__no_rhs_dollar__round!(a, b, c); | ||
| ---------------------------------------- in this macro invocation | ||
| | ||
= 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 | ||
--> $DIR/syntax-errors.rs:28:36 | ||
| | ||
LL | ( $( $i:ident ),* ) => { count(i) }; | ||
| ^ not found in this scope | ||
... | ||
LL | no_curly__no_rhs_dollar__round!(a, b, c); | ||
| ---------------------------------------- in this macro invocation | ||
| | ||
= 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 | ||
--> $DIR/syntax-errors.rs:34:23 | ||
| | ||
LL | ( $i:ident ) => { count(i) }; | ||
| ^^^^^ not found in this scope | ||
... | ||
LL | no_curly__no_rhs_dollar__no_round!(a); | ||
| ------------------------------------- in this macro invocation | ||
| | ||
= 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 `i` in this scope | ||
--> $DIR/syntax-errors.rs:34:29 | ||
| | ||
LL | ( $i:ident ) => { count(i) }; | ||
| ^ not found in this scope | ||
... | ||
LL | no_curly__no_rhs_dollar__no_round!(a); | ||
| ------------------------------------- in this macro invocation | ||
| | ||
= 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 | ||
--> $DIR/syntax-errors.rs:45:23 | ||
| | ||
LL | ( $i:ident ) => { count($i) }; | ||
| ^^^^^ not found in this scope | ||
... | ||
LL | no_curly__rhs_dollar__no_round!(a); | ||
| ---------------------------------- in this macro invocation | ||
| | ||
= 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[E0425]: cannot find value `a` in this scope | ||
--> $DIR/syntax-errors.rs:138:37 | ||
| | ||
LL | no_curly__rhs_dollar__no_round!(a); | ||
| ^ not found in this scope | ||
|
||
error: aborting due to 37 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0425`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.