rust/compiler
Yuki Okushi afa2edbe42
Rollup merge of #95860 - c410-f3r:stabilize-meta, r=joshtriplett
Stabilize `$$` in Rust 1.63.0

# Stabilization proposal

This PR proposes the stabilization of a subset of `#![feature(macro_metavar_expr)]` or more specifically, the stabilization of dollar-dollar (`$$`).

Tracking issue: #83527
Version: 1.63 (2022-06-28 => beta, 2022-08-11 => stable).

## What is stabilized

```rust
macro_rules! foo {
    () => {
        macro_rules! bar {
            ( $$( $$any:tt )* ) => { $$( $$any )* };
        }
    };
}

fn main() {
    foo!();
}
```

## Motivation

For more examples, see the [RFC](https://github.com/markbt/rfcs/blob/macro_metavar_expr/text/0000-macro-metavar-expr.md).

Users must currently resort to a tricky and not so well-known hack to declare nested macros with repetitions.

```rust
macro_rules! foo {
    ($dollar:tt) => {
        macro_rules! bar {
            ( $dollar ( $any:tt )* ) => { $dollar ( $any )* };
        }
    };
}
fn main() {
    foo!($);
}
```

As seen above, such hack is fragile and makes work with declarative macros much more unpleasant. Dollar-dollar (`$$`), on the other hand, makes nested macros more intuitive.

## What isn't stabilized

`count`, `ignore`, `index` and `length` are not being stabilized due to the lack of consensus.

## History

* 2021-02-22, [RFC: Declarative macro metavariable expressions](https://github.com/rust-lang/rfcs/pull/3086)
* 2021-03-26, [Tracking Issue for RFC 3086: macro metavariable expressions](https://github.com/rust-lang/rust/issues/83527)
* 2022-02-01, [Implement macro meta-variable expressions](https://github.com/rust-lang/rust/pull/93545)
* 2022-02-25, [[1/2] Implement macro meta-variable expressions](https://github.com/rust-lang/rust/pull/94368)
* 2022-03-11, [[2/2] Implement macro meta-variable expressions](https://github.com/rust-lang/rust/pull/94833)
* 2022-03-12, [Fix remaining meta-variable expression TODOs](https://github.com/rust-lang/rust/pull/94884)
* 2019-03-21, [[macro-metavar-expr] Fix generated tokens hygiene](https://github.com/rust-lang/rust/pull/95188)
* 2022-04-07, [Kickstart the inner usage of macro_metavar_expr](https://github.com/rust-lang/rust/pull/95761)
* 2022-04-07, [[macro_metavar_expr] Add tests to ensure the feature requirement](https://github.com/rust-lang/rust/pull/95764)

## Non-stabilized expressions

https://github.com/rust-lang/rust/issues/83527 lists several concerns about some characteristics of `count`, `index` and `length` that effectively make their stabilization unfeasible. `$$` and `ignore`, however, are not part of any discussion and thus are suitable for stabilization.

It is not in the scope of this PR to detail each concern or suggest any possible converging solution. Such thing should be restrained in this tracking issue.

## Tests

This list is a subset of https://github.com/rust-lang/rust/tree/master/src/test/ui/macros/rfc-3086-metavar-expr

* [Ensures that nested macros have correct behavior](https://github.com/rust-lang/rust/blob/master/src/test/ui/macros/rfc-3086-metavar-expr/dollar-dollar-has-correct-behavior.rs)

* [Compares produced tokens to assert expected outputs](https://github.com/rust-lang/rust/blob/master/src/test/ui/macros/rfc-3086-metavar-expr/feature-gate-macro_metavar_expr.rs)

* [Checks the declarations of the feature](https://github.com/rust-lang/rust/blob/master/src/test/ui/macros/rfc-3086-metavar-expr/required-feature.rs)

* [Verifies all possible errors that can occur due to incorrect user input](https://github.com/rust-lang/rust/blob/master/src/test/ui/macros/rfc-3086-metavar-expr/syntax-errors.rs)

## Possible future work

Once consensus is achieved, other nightly expressions can be stabilized.

Thanks ``@markbt`` for creating the RFC and thanks to ``@petrochenkov`` and ``@mark-i-m`` for reviewing the implementations.
2022-06-09 19:19:55 +09:00
..
rustc Auto merge of #96737 - ChrisDenton:win-manifest, r=wesleywiser 2022-06-02 07:58:29 +00:00
rustc_apfloat Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_arena
rustc_ast Rollup merge of #97856 - compiler-errors:bad-let-suggestions, r=estebank 2022-06-08 13:32:20 -07:00
rustc_ast_lowering Extract lower_generic_and_bounds function 2022-06-07 18:29:07 -03:00
rustc_ast_passes Auto merge of #97512 - scottmcm:add-coldcc, r=nagisa,lcnr 2022-06-07 08:12:45 +00:00
rustc_ast_pretty Revert #96682. 2022-06-02 11:22:16 +10:00
rustc_attr RFC3239: Implement compact cfg(target(..)) 2022-05-24 13:51:36 +02:00
rustc_borrowck Auto merge of #97081 - oli-obk:outlives_query_fast_path, r=jackh726 2022-06-07 21:44:40 +00:00
rustc_builtin_macros Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_codegen_cranelift Auto merge of #97825 - Dylan-DPC:rollup-ya51k1k, r=Dylan-DPC 2022-06-07 11:08:58 +00:00
rustc_codegen_gcc Remove unused macro rule 2022-06-07 08:50:13 -04:00
rustc_codegen_llvm Rollup merge of #97846 - pcwalton:align-bits, r=michaelwoerister 2022-06-08 13:43:19 +02:00
rustc_codegen_ssa Rename rustc_serialize::opaque::Encoder as MemEncoder. 2022-06-08 09:50:44 +10:00
rustc_const_eval Auto merge of #97740 - RalfJung:ctfe-cycle-spans, r=lcnr 2022-06-09 01:52:15 +00:00
rustc_data_structures Rename rustc_serialize::opaque::Encoder as MemEncoder. 2022-06-08 09:50:44 +10:00
rustc_driver Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis 2022-06-07 05:04:14 +00:00
rustc_error_codes Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis 2022-06-07 05:04:14 +00:00
rustc_error_messages migrate check_for_for_in_in_typo diagnostic 2022-05-31 16:28:05 -05:00
rustc_errors Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis 2022-06-07 05:04:14 +00:00
rustc_expand Rollup merge of #95860 - c410-f3r:stabilize-meta, r=joshtriplett 2022-06-09 19:19:55 +09:00
rustc_feature Auto merge of #97512 - scottmcm:add-coldcc, r=nagisa,lcnr 2022-06-07 08:12:45 +00:00
rustc_fs_util
rustc_graphviz Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_hir Don't suggest adding let in certain if conditions 2022-06-07 21:02:58 -07:00
rustc_hir_pretty Compute lifetimes in scope at diagnostic time. 2022-06-04 15:28:15 +02:00
rustc_incremental Rename rustc_serialize::opaque::Encoder as MemEncoder. 2022-06-08 09:50:44 +10:00
rustc_index Auto merge of #97862 - SparrowLii:superset, r=lcnr 2022-06-09 07:13:46 +00:00
rustc_infer Auto merge of #97447 - nnethercote:improve-folding, r=jackh726 2022-06-08 05:36:40 +00:00
rustc_interface Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_lexer
rustc_lint Folding revamp. 2022-06-08 09:24:03 +10:00
rustc_lint_defs Use serde_json for json error messages 2022-06-03 16:46:19 +00:00
rustc_llvm RustWrapper: adapt to APInt API changes in LLVM 15 2022-06-07 14:47:57 -04:00
rustc_log clippy::complexity fixes 2022-05-26 13:14:24 +02:00
rustc_macros Auto merge of #94732 - nnethercote:infallible-encoder, r=bjorn3 2022-06-08 10:24:12 +00:00
rustc_metadata Rename rustc_serialize::opaque::Encoder as MemEncoder. 2022-06-08 09:50:44 +10:00
rustc_middle Auto merge of #97740 - RalfJung:ctfe-cycle-spans, r=lcnr 2022-06-09 01:52:15 +00:00
rustc_mir_build Rollup merge of #97325 - tmiasko:capture-enum-field, r=arora-aman 2022-06-07 17:25:43 +02:00
rustc_mir_dataflow Rollup merge of #97597 - tmiasko:simplify-locals-side-effects, r=RalfJung,JakobDegen 2022-06-08 07:37:30 +02:00
rustc_mir_transform Auto merge of #97740 - RalfJung:ctfe-cycle-spans, r=lcnr 2022-06-09 01:52:15 +00:00
rustc_monomorphize Folding revamp. 2022-06-08 09:24:03 +10:00
rustc_parse Rollup merge of #97857 - ChayimFriedman2:box-identifier-help, r=compiler-errors 2022-06-08 13:32:21 -07:00
rustc_parse_format
rustc_passes Rollup merge of #97301 - semicoleon:unstable-reexport, r=petrochenkov 2022-06-07 11:41:07 +02:00
rustc_plugin_impl Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_privacy Folding revamp. 2022-06-08 09:24:03 +10:00
rustc_query_impl Rename rustc_serialize::opaque::Encoder as MemEncoder. 2022-06-08 09:50:44 +10:00
rustc_query_system Rename rustc_serialize::opaque::Encoder as MemEncoder. 2022-06-08 09:50:44 +10:00
rustc_resolve Don't suggest adding let in certain if conditions 2022-06-07 21:02:58 -07:00
rustc_save_analysis Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_serialize Rename rustc_serialize::opaque::Encoder as MemEncoder. 2022-06-08 09:50:44 +10:00
rustc_session bye BorrowckMode 2022-06-08 10:46:52 +02:00
rustc_span Rename rustc_serialize::opaque::Encoder as MemEncoder. 2022-06-08 09:50:44 +10:00
rustc_symbol_mangling Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_target Auto merge of #97512 - scottmcm:add-coldcc, r=nagisa,lcnr 2022-06-07 08:12:45 +00:00
rustc_trait_selection Auto merge of #97860 - Dylan-DPC:rollup-t3vxos8, r=Dylan-DPC 2022-06-08 08:05:47 +00:00
rustc_traits Folding revamp. 2022-06-08 09:24:03 +10:00
rustc_ty_utils Auto merge of #97860 - Dylan-DPC:rollup-t3vxos8, r=Dylan-DPC 2022-06-08 08:05:47 +00:00
rustc_type_ir Rename rustc_serialize::opaque::Encoder as MemEncoder. 2022-06-08 09:50:44 +10:00
rustc_typeck Rollup merge of #97856 - compiler-errors:bad-let-suggestions, r=estebank 2022-06-08 13:32:20 -07:00