Skip to content

Commit

Permalink
fix tests after s/${length()}/${len()}/
Browse files Browse the repository at this point in the history
  • Loading branch information
workingjubilee committed May 10, 2024
1 parent fa5964f commit 6e74155
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 140 deletions.
4 changes: 2 additions & 2 deletions tests/ui/macros/meta-variable-depth-outside-repeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

macro_rules! metavar {
( $i:expr ) => {
${length(0)}
//~^ ERROR meta-variable expression `length` with depth parameter must be called inside of a macro repetition
${len(0)}
//~^ ERROR meta-variable expression `len` with depth parameter must be called inside of a macro repetition
};
}

Expand Down
6 changes: 3 additions & 3 deletions tests/ui/macros/meta-variable-depth-outside-repeat.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: meta-variable expression `length` with depth parameter must be called inside of a macro repetition
error: meta-variable expression `len` with depth parameter must be called inside of a macro repetition
--> $DIR/meta-variable-depth-outside-repeat.rs:5:10
|
LL | ${length(0)}
| ^^^^^^^^^^^
LL | ${len(0)}
| ^^^^^^^^

error: aborting due to 1 previous error

108 changes: 60 additions & 48 deletions tests/ui/macros/rfc-3086-metavar-expr/count-and-length-are-distinct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,55 @@
#![feature(macro_metavar_expr)]

fn main() {
macro_rules! one_nested_count_and_length {
macro_rules! one_nested_count_and_len {
( $( [ $( $l:literal ),* ] ),* ) => {
[
// outer-most repetition
$(
// inner-most repetition
$(
${ignore($l)} ${index()}, ${length()},
${ignore($l)} ${index()}, ${len()},
)*
${count($l)}, ${index()}, ${length()},
${count($l)}, ${index()}, ${len()},
)*
${count($l)},
]
};
}
assert_eq!(
one_nested_count_and_length!(["foo"], ["bar", "baz"]),
one_nested_count_and_len!(["foo"], ["bar", "baz"]),
[
// # ["foo"]

// ## inner-most repetition (first iteration)
//
// `index` is 0 because this is the first inner-most iteration.
// `length` is 1 because there is only one inner-most repetition, "foo".
// `len` is 1 because there is only one inner-most repetition, "foo".
0, 1,

// ## outer-most repetition (first iteration)
//
// `count` is 1 because of "foo", i,e, `$l` has only one repetition,
// `index` is 0 because this is the first outer-most iteration.
// `length` is 2 because there are 2 outer-most repetitions, ["foo"] and ["bar", "baz"]
// `len` is 2 because there are 2 outer-most repetitions, ["foo"] and ["bar", "baz"]
1, 0, 2,

// # ["bar", "baz"]

// ## inner-most repetition (first iteration)
//
// `index` is 0 because this is the first inner-most iteration
// `length` is 2 because there are repetitions, "bar" and "baz"
// `len` is 2 because there are repetitions, "bar" and "baz"
0, 2,

// ## inner-most repetition (second iteration)
//
// `index` is 1 because this is the second inner-most iteration
// `length` is 2 because there are repetitions, "bar" and "baz"
// `len` is 2 because there are repetitions, "bar" and "baz"
1, 2,

// ## outer-most repetition (second iteration)
//
// `count` is 2 because of "bar" and "baz", i,e, `$l` has two repetitions,
// `index` is 1 because this is the second outer-most iteration
// `length` is 2 because there are 2 outer-most repetitions, ["foo"] and ["bar", "baz"]
// `len` is 2 because there are 2 outer-most repetitions, ["foo"] and ["bar", "baz"]
2, 1, 2,

// # last count

// Because there are a total of 3 repetitions of `$l`, "foo", "bar" and "baz"
Expand Down Expand Up @@ -131,7 +126,6 @@ fn main() {
&[2][..],
// t u v w x y z
&[7][..],

// (a b c) (d e f)
&[6, 2][..],
// (g h) (i j k l m)
Expand All @@ -142,15 +136,13 @@ fn main() {
&[5, 3][..],
// (t u v w x y z)
&[7, 1][..],

// [ (a b c) (d e f) ]
// [ (g h) (i j k l m) ]
// [ (n) ]
&[14, 5, 3][..],
// [ (o) (p q) (r s) ]
// [ (t u v w x y z) ]
&[12, 4, 2][..],

// {
// [ (a b c) (d e f) ]
// [ (g h) (i j k l m) ]
Expand All @@ -165,43 +157,43 @@ fn main() {
);

// Grouped from the outer-most to the inner-most
macro_rules! three_nested_length {
macro_rules! three_nested_len {
( $( { $( [ $( ( $( $i:ident )* ) )* ] )* } )* ) => {
&[
$( $( $( $(
&[
${ignore($i)} ${length(3)},
${ignore($i)} ${length(2)},
${ignore($i)} ${length(1)},
${ignore($i)} ${length(0)},
${ignore($i)} ${len(3)},
${ignore($i)} ${len(2)},
${ignore($i)} ${len(1)},
${ignore($i)} ${len(0)},
][..],
)* )* )* )*

$( $( $(
&[
${ignore($i)} ${length(2)},
${ignore($i)} ${length(1)},
${ignore($i)} ${length(0)},
${ignore($i)} ${len(2)},
${ignore($i)} ${len(1)},
${ignore($i)} ${len(0)},
][..],
)* )* )*

$( $(
&[
${ignore($i)} ${length(1)},
${ignore($i)} ${length(0)},
${ignore($i)} ${len(1)},
${ignore($i)} ${len(0)},
][..],
)* )*

$(
&[
${ignore($i)} ${length(0)},
${ignore($i)} ${len(0)},
][..],
)*
][..]
}
}
assert_eq!(
three_nested_length!(
three_nested_len!(
{
[ (a b c) (d e f) ]
[ (g h) (i j k l m) ]
Expand All @@ -214,45 +206,64 @@ fn main() {
),
&[
// a b c
&[2, 3, 2, 3][..], &[2, 3, 2, 3][..], &[2, 3, 2, 3][..],
&[2, 3, 2, 3][..],
&[2, 3, 2, 3][..],
&[2, 3, 2, 3][..],
// d e f
&[2, 3, 2, 3][..], &[2, 3, 2, 3][..], &[2, 3, 2, 3][..],
&[2, 3, 2, 3][..],
&[2, 3, 2, 3][..],
&[2, 3, 2, 3][..],
// g h
&[2, 3, 2, 2][..], &[2, 3, 2, 2][..],
&[2, 3, 2, 2][..],
&[2, 3, 2, 2][..],
// i j k l m
&[2, 3, 2, 5][..], &[2, 3, 2, 5][..], &[2, 3, 2, 5][..], &[2, 3, 2, 5][..],
&[2, 3, 2, 5][..],
&[2, 3, 2, 5][..],
&[2, 3, 2, 5][..],
&[2, 3, 2, 5][..],
&[2, 3, 2, 5][..],
// n
&[2, 3, 1, 1][..],
// o
&[2, 2, 3, 1][..],
// p q
&[2, 2, 3, 2][..], &[2, 2, 3, 2][..],
&[2, 2, 3, 2][..],
&[2, 2, 3, 2][..],
// r s
&[2, 2, 3, 2][..], &[2, 2, 3, 2][..],
&[2, 2, 3, 2][..],
&[2, 2, 3, 2][..],
// t u v w x y z
&[2, 2, 1, 7][..], &[2, 2, 1, 7][..], &[2, 2, 1, 7][..], &[2, 2, 1, 7][..],
&[2, 2, 1, 7][..], &[2, 2, 1, 7][..], &[2, 2, 1, 7][..],

&[2, 2, 1, 7][..],
&[2, 2, 1, 7][..],
&[2, 2, 1, 7][..],
&[2, 2, 1, 7][..],
&[2, 2, 1, 7][..],
&[2, 2, 1, 7][..],
&[2, 2, 1, 7][..],
// (a b c) (d e f)
&[2, 3, 2][..], &[2, 3, 2][..],
&[2, 3, 2][..],
&[2, 3, 2][..],
// (g h) (i j k l m)
&[2, 3, 2][..], &[2, 3, 2][..],
&[2, 3, 2][..],
&[2, 3, 2][..],
// (n)
&[2, 3, 1][..],
// (o) (p q) (r s)
&[2, 2, 3][..], &[2, 2, 3][..], &[2, 2, 3][..],
&[2, 2, 3][..],
&[2, 2, 3][..],
&[2, 2, 3][..],
// (t u v w x y z)
&[2, 2, 1][..],

// [ (a b c) (d e f) ]
// [ (g h) (i j k l m) ]
// [ (n) ]
&[2, 3][..], &[2, 3][..], &[2, 3,][..],
&[2, 3][..],
&[2, 3][..],
&[2, 3,][..],
// [ (o) (p q) (r s) ]
// [ (t u v w x y z) ]
&[2, 2][..], &[2, 2][..],

&[2, 2][..],
&[2, 2][..],
// {
// [ (a b c) (d e f) ]
// [ (g h) (i j k l m) ]
Expand All @@ -262,10 +273,11 @@ fn main() {
// [ (o) (p q) (r s) ]
// [ (t u v w x y z) ]
// }
&[2][..], &[2][..]
&[2][..],
&[2][..]
][..]
);

// It is possible to say, to some degree, that count is an "amalgamation" of length (see
// each length line result and compare them with the count results)
// It is possible to say, to some degree, that count is an "amalgamation" of len (see
// each len line result and compare them with the count results)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ macro_rules! count_depth_limits {
};
}

/// Produce (index, length) pairs for literals in a macro repetition.
/// Produce (index, len) pairs for literals in a macro repetition.
/// The literal is not included in the output, so this macro uses the
/// `ignore` meta-variable expression to create a non-expanding
/// repetition binding.
macro_rules! enumerate_literals {
( $( ($l:stmt) ),* ) => {
[$( ${ignore($l)} (${index()}, ${length()}) ),*]
[$( ${ignore($l)} (${index()}, ${len()}) ),*]
};
}

/// Produce index and length tuples for literals in a 2-dimensional
/// Produce index and len tuples for literals in a 2-dimensional
/// macro repetition.
macro_rules! enumerate_literals_2 {
( $( [ $( ($l:literal) ),* ] ),* ) => {
Expand All @@ -56,9 +56,9 @@ macro_rules! enumerate_literals_2 {
$(
(
${index(1)},
${length(1)},
${len(1)},
${index(0)},
${length(0)},
${len(0)},
$l
),
)*
Expand Down Expand Up @@ -134,7 +134,6 @@ fn main() {
(0, 2, 0, 3, "foo"),
(0, 2, 1, 3, "bar"),
(0, 2, 2, 3, "baz"),

(1, 2, 0, 4, "qux"),
(1, 2, 1, 4, "quux"),
(1, 2, 2, 4, "quuz"),
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/macros/rfc-3086-metavar-expr/macro-expansion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ macro_rules! example {
_nested: vec![
$(
Example {
_indexes: &[(${index()}, ${length()})],
_indexes: &[(${index()}, ${len()})],
_counts: &[${count($x, 0)}, ${count($x, 1)}],
_nested: vec![
$(
Example {
_indexes: &[(${index(1)}, ${length(1)}), (${index()}, ${length()})],
_indexes: &[(${index(1)}, ${len(1)}), (${index()}, ${len()})],
_counts: &[${count($x)}],
_nested: vec![
$(
Example {
_indexes: &[
(${index(2)}, ${length(2)}),
(${index(1)}, ${length(1)}),
(${index()}, ${length()})
(${index(2)}, ${len(2)}),
(${index(1)}, ${len(1)}),
(${index()}, ${len()})
],
_counts: &[],
_nested: vec![],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ macro_rules! c {
(
$( $(
${ignore($foo)}
${length(0)}
${length(10)}
//~^ ERROR depth parameter of meta-variable expression `length` must be less than 2
${len(0)}
${len(10)}
//~^ ERROR depth parameter of meta-variable expression `len` must be less than 2
)* )*
)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ error: depth parameter of meta-variable expression `index` must be less than 3
LL | ${index(10)},
| ^^^^^^^^^^^

error: depth parameter of meta-variable expression `length` must be less than 2
error: depth parameter of meta-variable expression `len` must be less than 2
--> $DIR/out-of-bounds-arguments.rs:32:18
|
LL | ${length(10)}
| ^^^^^^^^^^^^
LL | ${len(10)}
| ^^^^^^^^^

error: aborting due to 3 previous errors

7 changes: 3 additions & 4 deletions tests/ui/macros/rfc-3086-metavar-expr/required-feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ macro_rules! ignore {
}};
}

macro_rules! length {
macro_rules! len {
( $( $e:stmt ),* ) => {
$( ${ignore($e)} ${length()} )*
$( ${ignore($e)} ${len()} )*
//~^ ERROR meta-variable expressions are unstable
//~| ERROR meta-variable expressions are unstable
};
}

fn main() {
}
fn main() {}
Loading

0 comments on commit 6e74155

Please sign in to comment.