Skip to content

Commit 93b1119

Browse files
committed
Stabilize meta variables expressions
1 parent 1388d7a commit 93b1119

22 files changed

+173
-276
lines changed

Diff for: compiler/rustc_data_structures/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#![allow(internal_features)]
1111
#![allow(rustc::default_hash_types)]
1212
#![allow(rustc::potential_query_instability)]
13+
#![cfg_attr(bootstrap, feature(macro_metavar_expr))]
1314
#![cfg_attr(not(parallel_compiler), feature(cell_leak))]
1415
#![deny(unsafe_op_in_unsafe_fn)]
1516
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
@@ -25,7 +26,6 @@
2526
#![feature(hasher_prefixfree_extras)]
2627
#![feature(lazy_cell)]
2728
#![feature(lint_reasons)]
28-
#![feature(macro_metavar_expr)]
2929
#![feature(maybe_uninit_uninit_array)]
3030
#![feature(min_specialization)]
3131
#![feature(negative_impls)]

Diff for: compiler/rustc_data_structures/src/tagged_ptr/impl_tag.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/// Basic usage:
1212
///
1313
/// ```
14-
/// #![feature(macro_metavar_expr)]
14+
/// #![cfg_attr(bootstrap, feature(macro_metavar_expr))]
1515
/// use rustc_data_structures::{impl_tag, tagged_ptr::Tag};
1616
///
1717
/// #[derive(Copy, Clone, PartialEq, Debug)]
@@ -51,7 +51,7 @@
5151
/// Structs are supported:
5252
///
5353
/// ```
54-
/// #![feature(macro_metavar_expr)]
54+
/// #![cfg_attr(bootstrap, feature(macro_metavar_expr))]
5555
/// # use rustc_data_structures::impl_tag;
5656
/// #[derive(Copy, Clone)]
5757
/// struct Flags { a: bool, b: bool }
@@ -68,7 +68,7 @@
6868
/// Not specifying all values results in a compile error:
6969
///
7070
/// ```compile_fail,E0004
71-
/// #![feature(macro_metavar_expr)]
71+
/// #![cfg_attr(bootstrap, feature(macro_metavar_expr))]
7272
/// # use rustc_data_structures::impl_tag;
7373
/// #[derive(Copy, Clone)]
7474
/// enum E {

Diff for: compiler/rustc_expand/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#![feature(if_let_guard)]
77
#![feature(let_chains)]
88
#![feature(lint_reasons)]
9-
#![feature(macro_metavar_expr)]
9+
#![cfg_attr(bootstrap, feature(macro_metavar_expr))]
1010
#![feature(map_try_insert)]
1111
#![feature(proc_macro_diagnostic)]
1212
#![feature(proc_macro_internals)]

Diff for: compiler/rustc_expand/src/mbe/quoted.rs

-5
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,6 @@ fn parse_tree<'a>(
183183
return TokenTree::token(token::Dollar, span);
184184
}
185185
Ok(elem) => {
186-
maybe_emit_macro_metavar_expr_feature(
187-
features,
188-
sess,
189-
delim_span.entire(),
190-
);
191186
return TokenTree::MetaVarExpr(delim_span, elem);
192187
}
193188
}

Diff for: compiler/rustc_metadata/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#![feature(let_chains)]
1212
#![feature(if_let_guard)]
1313
#![feature(proc_macro_internals)]
14-
#![feature(macro_metavar_expr)]
14+
#![cfg_attr(bootstrap, feature(macro_metavar_expr))]
1515
#![feature(min_specialization)]
1616
#![feature(trusted_len)]
1717
#![feature(try_blocks)]

Diff for: compiler/rustc_middle/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
#![feature(yeet_expr)]
6060
#![feature(const_option)]
6161
#![feature(ptr_alignment_type)]
62-
#![feature(macro_metavar_expr)]
62+
#![cfg_attr(bootstrap, feature(macro_metavar_expr))]
6363
#![allow(internal_features)]
6464
#![allow(rustc::potential_query_instability)]
6565
#![allow(rustc::diagnostic_outside_of_impl)]

Diff for: library/core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@
204204
//
205205
// Language features:
206206
// tidy-alphabetical-start
207+
#![cfg_attr(bootstrap, feature(macro_metavar_expr))]
207208
#![feature(abi_unadjusted)]
208209
#![feature(adt_const_params)]
209210
#![feature(allow_internal_unsafe)]
@@ -238,7 +239,6 @@
238239
#![feature(lang_items)]
239240
#![feature(let_chains)]
240241
#![feature(link_llvm_intrinsics)]
241-
#![feature(macro_metavar_expr)]
242242
#![feature(min_exhaustive_patterns)]
243243
#![feature(min_specialization)]
244244
#![feature(multiple_supertrait_upcastable)]

Diff for: src/tools/tidy/src/ui_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const ENTRY_LIMIT: usize = 900;
1818
// FIXME: The following limits should be reduced eventually.
1919

2020
const ISSUES_ENTRY_LIMIT: usize = 1750;
21-
const ROOT_ENTRY_LIMIT: usize = 859;
21+
const ROOT_ENTRY_LIMIT: usize = 860;
2222

2323
const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[
2424
"rs", // test source files

Diff for: tests/ui/macros/meta-variable-depth-outside-repeat.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(macro_metavar_expr)]
2-
31
macro_rules! metavar {
42
( $i:expr ) => {
53
${length(0)}

Diff for: tests/ui/macros/meta-variable-depth-outside-repeat.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: meta-variable expression `length` with depth parameter must be called inside of a macro repetition
2-
--> $DIR/meta-variable-depth-outside-repeat.rs:5:10
2+
--> $DIR/meta-variable-depth-outside-repeat.rs:3:10
33
|
44
LL | ${length(0)}
55
| ^^^^^^^^^^^

Diff for: tests/ui/macros/rfc-3086-metavar-expr/count-and-length-are-distinct.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//@ run-pass
22

3-
#![feature(macro_metavar_expr)]
4-
53
fn main() {
64
macro_rules! one_nested_count_and_length {
75
( $( [ $( $l:literal ),* ] ),* ) => {

Diff for: tests/ui/macros/rfc-3086-metavar-expr/feature-gate-macro_metavar_expr.rs

-98
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,6 @@
22

33
#![feature(macro_metavar_expr)]
44

5-
/// Count the number of idents in a macro repetition.
6-
macro_rules! count_idents {
7-
( $( $i:ident ),* ) => {
8-
${count($i)}
9-
};
10-
}
11-
12-
/// Count the number of idents in a 2-dimensional macro repetition.
13-
macro_rules! count_idents_2 {
14-
( $( [ $( $i:ident ),* ] ),* ) => {
15-
${count($i)}
16-
};
17-
}
18-
19-
/// Mostly counts the number of OUTER-MOST repetitions
20-
macro_rules! count_depth_limits {
21-
( $( { $( [ $( $outer:ident : ( $( $inner:ident )* ) )* ] )* } )* ) => {
22-
(
23-
(
24-
${count($inner)},
25-
${count($inner, 0)},
26-
${count($inner, 1)},
27-
${count($inner, 2)},
28-
${count($inner, 3)},
29-
),
30-
(
31-
${count($outer)},
32-
${count($outer, 0)},
33-
${count($outer, 1)},
34-
${count($outer, 2)},
35-
),
36-
)
37-
};
38-
}
39-
40-
/// Produce (index, length) pairs for literals in a macro repetition.
41-
/// The literal is not included in the output, so this macro uses the
42-
/// `ignore` meta-variable expression to create a non-expanding
43-
/// repetition binding.
44-
macro_rules! enumerate_literals {
45-
( $( ($l:stmt) ),* ) => {
46-
[$( ${ignore($l)} (${index()}, ${length()}) ),*]
47-
};
48-
}
49-
50-
/// Produce index and length tuples for literals in a 2-dimensional
51-
/// macro repetition.
52-
macro_rules! enumerate_literals_2 {
53-
( $( [ $( ($l:literal) ),* ] ),* ) => {
54-
[
55-
$(
56-
$(
57-
(
58-
${index(1)},
59-
${length(1)},
60-
${index(0)},
61-
${length(0)},
62-
$l
63-
),
64-
)*
65-
)*
66-
]
67-
};
68-
}
69-
705
/// Generate macros that count idents and then add a constant number
716
/// to the count.
727
///
@@ -108,39 +43,6 @@ make_picker!(first => a, b; a);
10843
make_picker!(second => a, b; b);
10944

11045
fn main() {
111-
assert_eq!(count_idents!(a, b, c), 3);
112-
assert_eq!(count_idents_2!([a, b, c], [d, e], [f]), 6);
113-
assert_eq!(
114-
count_depth_limits! {
115-
{
116-
[ A: (a b c) D: (d e f) ]
117-
[ G: (g h) I: (i j k l m) ]
118-
[ N: (n) ]
119-
}
120-
{
121-
[ O: (o) P: (p q) R: (r s) ]
122-
[ T: (t u v w x y z) ]
123-
}
124-
},
125-
((26, 26, 9, 5, 2), (9, 9, 5, 2))
126-
);
127-
assert_eq!(enumerate_literals![("foo"), ("bar")], [(0, 2), (1, 2)]);
128-
assert_eq!(
129-
enumerate_literals_2![
130-
[("foo"), ("bar"), ("baz")],
131-
[("qux"), ("quux"), ("quuz"), ("xyzzy")]
132-
],
133-
[
134-
(0, 2, 0, 3, "foo"),
135-
(0, 2, 1, 3, "bar"),
136-
(0, 2, 2, 3, "baz"),
137-
138-
(1, 2, 0, 4, "qux"),
139-
(1, 2, 1, 4, "quux"),
140-
(1, 2, 2, 4, "quuz"),
141-
(1, 2, 3, 4, "xyzzy"),
142-
]
143-
);
14446
assert_eq!(plus_one!(a, b, c), 4);
14547
assert_eq!(plus_five!(a, b), 7);
14648
assert_eq!(first!(1, 2), 1);

Diff for: tests/ui/macros/rfc-3086-metavar-expr/issue-111904.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(macro_metavar_expr)]
2-
31
macro_rules! foo {
42
( $( $($t:ident),* );* ) => { ${count($t,)} }
53
//~^ ERROR `count` followed by a comma must have an associated

Diff for: tests/ui/macros/rfc-3086-metavar-expr/issue-111904.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: `count` followed by a comma must have an associated index indicating its depth
2-
--> $DIR/issue-111904.rs:4:37
2+
--> $DIR/issue-111904.rs:2:37
33
|
44
LL | ( $( $($t:ident),* );* ) => { ${count($t,)} }
55
| ^^^^^
66

77
error: expected expression, found `$`
8-
--> $DIR/issue-111904.rs:4:35
8+
--> $DIR/issue-111904.rs:2:35
99
|
1010
LL | ( $( $($t:ident),* );* ) => { ${count($t,)} }
1111
| ^ expected expression

Diff for: tests/ui/macros/rfc-3086-metavar-expr/macro-expansion.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//@ run-pass
22

3-
#![feature(macro_metavar_expr)]
4-
53
#[derive(Debug)]
64
struct Example<'a> {
75
_indexes: &'a [(u32, u32)],

Diff for: tests/ui/macros/rfc-3086-metavar-expr/operations.rs

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
//@ run-pass
2+
3+
/// Count the number of idents in a macro repetition.
4+
macro_rules! count_idents {
5+
( $( $i:ident ),* ) => {
6+
${count($i)}
7+
};
8+
}
9+
10+
/// Count the number of idents in a 2-dimensional macro repetition.
11+
macro_rules! count_idents_2 {
12+
( $( [ $( $i:ident ),* ] ),* ) => {
13+
${count($i)}
14+
};
15+
}
16+
17+
/// Mostly counts the number of OUTER-MOST repetitions
18+
macro_rules! count_depth_limits {
19+
( $( { $( [ $( $outer:ident : ( $( $inner:ident )* ) )* ] )* } )* ) => {
20+
(
21+
(
22+
${count($inner)},
23+
${count($inner, 0)},
24+
${count($inner, 1)},
25+
${count($inner, 2)},
26+
${count($inner, 3)},
27+
),
28+
(
29+
${count($outer)},
30+
${count($outer, 0)},
31+
${count($outer, 1)},
32+
${count($outer, 2)},
33+
),
34+
)
35+
};
36+
}
37+
38+
/// Produce (index, length) pairs for literals in a macro repetition.
39+
/// The literal is not included in the output, so this macro uses the
40+
/// `ignore` meta-variable expression to create a non-expanding
41+
/// repetition binding.
42+
macro_rules! enumerate_literals {
43+
( $( ($l:stmt) ),* ) => {
44+
[$( ${ignore($l)} (${index()}, ${length()}) ),*]
45+
};
46+
}
47+
48+
/// Produce index and length tuples for literals in a 2-dimensional
49+
/// macro repetition.
50+
macro_rules! enumerate_literals_2 {
51+
( $( [ $( ($l:literal) ),* ] ),* ) => {
52+
[
53+
$(
54+
$(
55+
(
56+
${index(1)},
57+
${length(1)},
58+
${index(0)},
59+
${length(0)},
60+
$l
61+
),
62+
)*
63+
)*
64+
]
65+
};
66+
}
67+
68+
fn main() {
69+
assert_eq!(count_idents!(a, b, c), 3);
70+
assert_eq!(count_idents_2!([a, b, c], [d, e], [f]), 6);
71+
assert_eq!(
72+
count_depth_limits! {
73+
{
74+
[ A: (a b c) D: (d e f) ]
75+
[ G: (g h) I: (i j k l m) ]
76+
[ N: (n) ]
77+
}
78+
{
79+
[ O: (o) P: (p q) R: (r s) ]
80+
[ T: (t u v w x y z) ]
81+
}
82+
},
83+
((26, 26, 9, 5, 2), (9, 9, 5, 2))
84+
);
85+
assert_eq!(enumerate_literals![("foo"), ("bar")], [(0, 2), (1, 2)]);
86+
assert_eq!(
87+
enumerate_literals_2![
88+
[("foo"), ("bar"), ("baz")],
89+
[("qux"), ("quux"), ("quuz"), ("xyzzy")]
90+
],
91+
[
92+
(0, 2, 0, 3, "foo"),
93+
(0, 2, 1, 3, "bar"),
94+
(0, 2, 2, 3, "baz"),
95+
96+
(1, 2, 0, 4, "qux"),
97+
(1, 2, 1, 4, "quux"),
98+
(1, 2, 2, 4, "quuz"),
99+
(1, 2, 3, 4, "xyzzy"),
100+
]
101+
);
102+
}

Diff for: tests/ui/macros/rfc-3086-metavar-expr/out-of-bounds-arguments.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(macro_metavar_expr)]
2-
31
macro_rules! a {
42
( $( { $( [ $( ( $( $foo:ident )* ) )* ] )* } )* ) => {
53
(

Diff for: tests/ui/macros/rfc-3086-metavar-expr/out-of-bounds-arguments.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
error: depth parameter of meta-variable expression `count` must be less than 4
2-
--> $DIR/out-of-bounds-arguments.rs:7:14
2+
--> $DIR/out-of-bounds-arguments.rs:5:14
33
|
44
LL | ${count($foo, 10)},
55
| ^^^^^^^^^^^^^^^^^
66

77
error: depth parameter of meta-variable expression `index` must be less than 3
8-
--> $DIR/out-of-bounds-arguments.rs:19:18
8+
--> $DIR/out-of-bounds-arguments.rs:17:18
99
|
1010
LL | ${index(10)},
1111
| ^^^^^^^^^^^
1212

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

0 commit comments

Comments
 (0)