Skip to content
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

[1/2] Implement macro meta-variable expressions #94368

Merged
merged 1 commit into from
Mar 11, 2022

Conversation

c410-f3r
Copy link
Contributor

@c410-f3r c410-f3r commented Feb 25, 2022

See #93545 (comment)

The logic behind length, index and count was removed but the parsing code is still present, i.e., everything is simply ignored like ignored.

r? @petrochenkov

cc #83527

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 25, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 25, 2022
compiler/rustc_expand/src/mbe/metavar_expr.rs Outdated Show resolved Hide resolved
compiler/rustc_expand/src/mbe/metavar_expr.rs Outdated Show resolved Hide resolved
compiler/rustc_expand/src/mbe/metavar_expr.rs Outdated Show resolved Hide resolved
compiler/rustc_expand/src/mbe/metavar_expr.rs Outdated Show resolved Hide resolved
compiler/rustc_expand/src/mbe/metavar_expr.rs Outdated Show resolved Hide resolved
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 6, 2022
@c410-f3r c410-f3r force-pushed the metaaaaaaaaaaaaaaaaaaaaaaaaaaa branch from ff69ee6 to 23c54cb Compare March 6, 2022 22:19
@c410-f3r
Copy link
Contributor Author

c410-f3r commented Mar 6, 2022

Thanks again for the review, @petrochenkov.

I addressed everything but #94368 (comment) so let me know your thoughts.

@rustbot label +S-waiting-on-review -S-waiting-on-author

@rustbot
Copy link
Collaborator

rustbot commented Mar 6, 2022

Error: Label review can only be set by Rust team members

Please let @rust-lang/release know if you're having trouble with this bot.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 6, 2022
@rust-log-analyzer

This comment has been minimized.

@c410-f3r c410-f3r force-pushed the metaaaaaaaaaaaaaaaaaaaaaaaaaaa branch from 23c54cb to 1038182 Compare March 6, 2022 22:43
compiler/rustc_expand/src/mbe/metavar_expr.rs Outdated Show resolved Hide resolved
compiler/rustc_expand/src/mbe/metavar_expr.rs Outdated Show resolved Hide resolved
compiler/rustc_expand/src/mbe/metavar_expr.rs Outdated Show resolved Hide resolved
compiler/rustc_expand/src/mbe/metavar_expr.rs Show resolved Hide resolved
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 9, 2022
@c410-f3r c410-f3r force-pushed the metaaaaaaaaaaaaaaaaaaaaaaaaaaa branch from 1038182 to 04b7811 Compare March 9, 2022 13:48
@c410-f3r
Copy link
Contributor Author

c410-f3r commented Mar 9, 2022

I guess this is it

@rustbot label +S-waiting-on-review -S-waiting-on-author

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 9, 2022
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Mar 9, 2022

📌 Commit 04b781175e653574c0d6665bf1d09e5ebb8090f8 has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 9, 2022
@bors
Copy link
Contributor

bors commented Mar 9, 2022

⌛ Testing commit 04b781175e653574c0d6665bf1d09e5ebb8090f8 with merge a47a581b8c5f5342dc59e31854c85f531edb3c94...

@bors
Copy link
Contributor

bors commented Mar 9, 2022

💔 Test failed - checks-actions

@bors bors removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Mar 9, 2022
@bors bors added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 9, 2022
@c410-f3r
Copy link
Contributor Author

c410-f3r commented Mar 9, 2022

CI is broken -> #94774 (comment)

@c410-f3r c410-f3r force-pushed the metaaaaaaaaaaaaaaaaaaaaaaaaaaa branch from 04b7811 to 8073a88 Compare March 9, 2022 19:46
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Mar 9, 2022

📌 Commit 8073a88 has been approved by petrochenkov

@bors
Copy link
Contributor

bors commented Mar 9, 2022

🌲 The tree is currently closed for pull requests below priority 50. This pull request will be tested once the tree is reopened.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 9, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Mar 9, 2022
…aaaa, r=petrochenkov

[1/2] Implement macro meta-variable expressions

See rust-lang#93545 (comment)

The logic behind `length`, `index` and `count` was removed but the parsing code is still present, i.e., everything is simply ignored like `ignored`.

r? `@petrochenkov`
@rust-log-analyzer

This comment has been minimized.

@c410-f3r
Copy link
Contributor Author

2022-03-09T19:24:39.6807544Z /checkout/src/test/rustdoc-gui/mobile.goml mobile... FAILED
2022-03-09T19:24:39.6808635Z [ERROR] (line 27) Error: Evaluation failed: assert didn't fail: for command compare-elements-position-near-false: ("#preferred-light-theme .setting-name", "#preferred-light-theme .choice", {"y": 16})

Unrelated error

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Mar 10, 2022
…aaaa, r=petrochenkov

[1/2] Implement macro meta-variable expressions

See rust-lang#93545 (comment)

The logic behind `length`, `index` and `count` was removed but the parsing code is still present, i.e., everything is simply ignored like `ignored`.

r? `@petrochenkov`
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 10, 2022
Rollup of 7 pull requests

Successful merges:

 - rust-lang#93950 (Use modern formatting for format! macros)
 - rust-lang#94274 (Treat unstable lints as unknown)
 - rust-lang#94368 ([1/2] Implement macro meta-variable expressions)
 - rust-lang#94719 (Statically compile libstdc++ everywhere if asked)
 - rust-lang#94728 (Only emit pointer-like metadata for `Box<T, A>` when `A` is ZST)
 - rust-lang#94790 (enable portable-simd doctests in Miri)
 - rust-lang#94811 (Update browser-ui-test version)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 634a6b0 into rust-lang:master Mar 11, 2022
@rustbot rustbot added this to the 1.61.0 milestone Mar 11, 2022
@Dylan-DPC Dylan-DPC mentioned this pull request Mar 18, 2022
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jun 9, 2022
…lett

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

## Non-stabilized expressions

rust-lang#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.
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jun 9, 2022
…lett

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

## Non-stabilized expressions

rust-lang#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants