Skip to content

Commit

Permalink
Stabilize meta variables expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
c410-f3r committed Mar 21, 2024
1 parent 1388d7a commit 93b1119
Show file tree
Hide file tree
Showing 22 changed files with 173 additions and 276 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#![allow(internal_features)]
#![allow(rustc::default_hash_types)]
#![allow(rustc::potential_query_instability)]
#![cfg_attr(bootstrap, feature(macro_metavar_expr))]
#![cfg_attr(not(parallel_compiler), feature(cell_leak))]
#![deny(unsafe_op_in_unsafe_fn)]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
Expand All @@ -25,7 +26,6 @@
#![feature(hasher_prefixfree_extras)]
#![feature(lazy_cell)]
#![feature(lint_reasons)]
#![feature(macro_metavar_expr)]
#![feature(maybe_uninit_uninit_array)]
#![feature(min_specialization)]
#![feature(negative_impls)]
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_data_structures/src/tagged_ptr/impl_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/// Basic usage:
///
/// ```
/// #![feature(macro_metavar_expr)]
/// #![cfg_attr(bootstrap, feature(macro_metavar_expr))]
/// use rustc_data_structures::{impl_tag, tagged_ptr::Tag};
///
/// #[derive(Copy, Clone, PartialEq, Debug)]
Expand Down Expand Up @@ -51,7 +51,7 @@
/// Structs are supported:
///
/// ```
/// #![feature(macro_metavar_expr)]
/// #![cfg_attr(bootstrap, feature(macro_metavar_expr))]
/// # use rustc_data_structures::impl_tag;
/// #[derive(Copy, Clone)]
/// struct Flags { a: bool, b: bool }
Expand All @@ -68,7 +68,7 @@
/// Not specifying all values results in a compile error:
///
/// ```compile_fail,E0004
/// #![feature(macro_metavar_expr)]
/// #![cfg_attr(bootstrap, feature(macro_metavar_expr))]
/// # use rustc_data_structures::impl_tag;
/// #[derive(Copy, Clone)]
/// enum E {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#![feature(if_let_guard)]
#![feature(let_chains)]
#![feature(lint_reasons)]
#![feature(macro_metavar_expr)]
#![cfg_attr(bootstrap, feature(macro_metavar_expr))]
#![feature(map_try_insert)]
#![feature(proc_macro_diagnostic)]
#![feature(proc_macro_internals)]
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_expand/src/mbe/quoted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,6 @@ fn parse_tree<'a>(
return TokenTree::token(token::Dollar, span);
}
Ok(elem) => {
maybe_emit_macro_metavar_expr_feature(
features,
sess,
delim_span.entire(),
);
return TokenTree::MetaVarExpr(delim_span, elem);
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#![feature(let_chains)]
#![feature(if_let_guard)]
#![feature(proc_macro_internals)]
#![feature(macro_metavar_expr)]
#![cfg_attr(bootstrap, feature(macro_metavar_expr))]
#![feature(min_specialization)]
#![feature(trusted_len)]
#![feature(try_blocks)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#![feature(yeet_expr)]
#![feature(const_option)]
#![feature(ptr_alignment_type)]
#![feature(macro_metavar_expr)]
#![cfg_attr(bootstrap, feature(macro_metavar_expr))]
#![allow(internal_features)]
#![allow(rustc::potential_query_instability)]
#![allow(rustc::diagnostic_outside_of_impl)]
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
//
// Language features:
// tidy-alphabetical-start
#![cfg_attr(bootstrap, feature(macro_metavar_expr))]
#![feature(abi_unadjusted)]
#![feature(adt_const_params)]
#![feature(allow_internal_unsafe)]
Expand Down Expand Up @@ -238,7 +239,6 @@
#![feature(lang_items)]
#![feature(let_chains)]
#![feature(link_llvm_intrinsics)]
#![feature(macro_metavar_expr)]
#![feature(min_exhaustive_patterns)]
#![feature(min_specialization)]
#![feature(multiple_supertrait_upcastable)]
Expand Down
2 changes: 1 addition & 1 deletion src/tools/tidy/src/ui_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const ENTRY_LIMIT: usize = 900;
// FIXME: The following limits should be reduced eventually.

const ISSUES_ENTRY_LIMIT: usize = 1750;
const ROOT_ENTRY_LIMIT: usize = 859;
const ROOT_ENTRY_LIMIT: usize = 860;

const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[
"rs", // test source files
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/macros/meta-variable-depth-outside-repeat.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(macro_metavar_expr)]

macro_rules! metavar {
( $i:expr ) => {
${length(0)}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/macros/meta-variable-depth-outside-repeat.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: meta-variable expression `length` with depth parameter must be called inside of a macro repetition
--> $DIR/meta-variable-depth-outside-repeat.rs:5:10
--> $DIR/meta-variable-depth-outside-repeat.rs:3:10
|
LL | ${length(0)}
| ^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//@ run-pass

#![feature(macro_metavar_expr)]

fn main() {
macro_rules! one_nested_count_and_length {
( $( [ $( $l:literal ),* ] ),* ) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,6 @@

#![feature(macro_metavar_expr)]

/// Count the number of idents in a macro repetition.
macro_rules! count_idents {
( $( $i:ident ),* ) => {
${count($i)}
};
}

/// Count the number of idents in a 2-dimensional macro repetition.
macro_rules! count_idents_2 {
( $( [ $( $i:ident ),* ] ),* ) => {
${count($i)}
};
}

/// Mostly counts the number of OUTER-MOST repetitions
macro_rules! count_depth_limits {
( $( { $( [ $( $outer:ident : ( $( $inner:ident )* ) )* ] )* } )* ) => {
(
(
${count($inner)},
${count($inner, 0)},
${count($inner, 1)},
${count($inner, 2)},
${count($inner, 3)},
),
(
${count($outer)},
${count($outer, 0)},
${count($outer, 1)},
${count($outer, 2)},
),
)
};
}

/// Produce (index, length) 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()}) ),*]
};
}

/// Produce index and length tuples for literals in a 2-dimensional
/// macro repetition.
macro_rules! enumerate_literals_2 {
( $( [ $( ($l:literal) ),* ] ),* ) => {
[
$(
$(
(
${index(1)},
${length(1)},
${index(0)},
${length(0)},
$l
),
)*
)*
]
};
}

/// Generate macros that count idents and then add a constant number
/// to the count.
///
Expand Down Expand Up @@ -108,39 +43,6 @@ make_picker!(first => a, b; a);
make_picker!(second => a, b; b);

fn main() {
assert_eq!(count_idents!(a, b, c), 3);
assert_eq!(count_idents_2!([a, b, c], [d, e], [f]), 6);
assert_eq!(
count_depth_limits! {
{
[ A: (a b c) D: (d e f) ]
[ G: (g h) I: (i j k l m) ]
[ N: (n) ]
}
{
[ O: (o) P: (p q) R: (r s) ]
[ T: (t u v w x y z) ]
}
},
((26, 26, 9, 5, 2), (9, 9, 5, 2))
);
assert_eq!(enumerate_literals![("foo"), ("bar")], [(0, 2), (1, 2)]);
assert_eq!(
enumerate_literals_2![
[("foo"), ("bar"), ("baz")],
[("qux"), ("quux"), ("quuz"), ("xyzzy")]
],
[
(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"),
(1, 2, 3, 4, "xyzzy"),
]
);
assert_eq!(plus_one!(a, b, c), 4);
assert_eq!(plus_five!(a, b), 7);
assert_eq!(first!(1, 2), 1);
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/macros/rfc-3086-metavar-expr/issue-111904.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(macro_metavar_expr)]

macro_rules! foo {
( $( $($t:ident),* );* ) => { ${count($t,)} }
//~^ ERROR `count` followed by a comma must have an associated
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/macros/rfc-3086-metavar-expr/issue-111904.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error: `count` followed by a comma must have an associated index indicating its depth
--> $DIR/issue-111904.rs:4:37
--> $DIR/issue-111904.rs:2:37
|
LL | ( $( $($t:ident),* );* ) => { ${count($t,)} }
| ^^^^^

error: expected expression, found `$`
--> $DIR/issue-111904.rs:4:35
--> $DIR/issue-111904.rs:2:35
|
LL | ( $( $($t:ident),* );* ) => { ${count($t,)} }
| ^ expected expression
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/macros/rfc-3086-metavar-expr/macro-expansion.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//@ run-pass

#![feature(macro_metavar_expr)]

#[derive(Debug)]
struct Example<'a> {
_indexes: &'a [(u32, u32)],
Expand Down
102 changes: 102 additions & 0 deletions tests/ui/macros/rfc-3086-metavar-expr/operations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//@ run-pass

/// Count the number of idents in a macro repetition.
macro_rules! count_idents {
( $( $i:ident ),* ) => {
${count($i)}
};
}

/// Count the number of idents in a 2-dimensional macro repetition.
macro_rules! count_idents_2 {
( $( [ $( $i:ident ),* ] ),* ) => {
${count($i)}
};
}

/// Mostly counts the number of OUTER-MOST repetitions
macro_rules! count_depth_limits {
( $( { $( [ $( $outer:ident : ( $( $inner:ident )* ) )* ] )* } )* ) => {
(
(
${count($inner)},
${count($inner, 0)},
${count($inner, 1)},
${count($inner, 2)},
${count($inner, 3)},
),
(
${count($outer)},
${count($outer, 0)},
${count($outer, 1)},
${count($outer, 2)},
),
)
};
}

/// Produce (index, length) 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()}) ),*]
};
}

/// Produce index and length tuples for literals in a 2-dimensional
/// macro repetition.
macro_rules! enumerate_literals_2 {
( $( [ $( ($l:literal) ),* ] ),* ) => {
[
$(
$(
(
${index(1)},
${length(1)},
${index(0)},
${length(0)},
$l
),
)*
)*
]
};
}

fn main() {
assert_eq!(count_idents!(a, b, c), 3);
assert_eq!(count_idents_2!([a, b, c], [d, e], [f]), 6);
assert_eq!(
count_depth_limits! {
{
[ A: (a b c) D: (d e f) ]
[ G: (g h) I: (i j k l m) ]
[ N: (n) ]
}
{
[ O: (o) P: (p q) R: (r s) ]
[ T: (t u v w x y z) ]
}
},
((26, 26, 9, 5, 2), (9, 9, 5, 2))
);
assert_eq!(enumerate_literals![("foo"), ("bar")], [(0, 2), (1, 2)]);
assert_eq!(
enumerate_literals_2![
[("foo"), ("bar"), ("baz")],
[("qux"), ("quux"), ("quuz"), ("xyzzy")]
],
[
(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"),
(1, 2, 3, 4, "xyzzy"),
]
);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(macro_metavar_expr)]

macro_rules! a {
( $( { $( [ $( ( $( $foo:ident )* ) )* ] )* } )* ) => {
(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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:5:14
|
LL | ${count($foo, 10)},
| ^^^^^^^^^^^^^^^^^

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:17:18
|
LL | ${index(10)},
| ^^^^^^^^^^^

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:30:18
|
LL | ${length(10)}
| ^^^^^^^^^^^^
Expand Down
Loading

0 comments on commit 93b1119

Please sign in to comment.