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

Tracking Issue for updating expr macro fragment specifier for Rust 2024 #123742

Closed
10 tasks done
traviscross opened this issue Apr 10, 2024 · 16 comments
Closed
10 tasks done
Assignees
Labels
A-edition-2024 Area: The 2024 edition A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. S-tracking-ready-for-edition Status: This issue is ready for inclusion in the edition. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@traviscross
Copy link
Contributor

traviscross commented Apr 10, 2024

This is a tracking issue for updating the expr fragment specifier for Rust 2024 according to the policy described in RFC 3531:

The feature gate for the issue is #![feature(expr_fragment_specifier_2024)].

About tracking issues

Tracking issues are used to record the overall progress of implementation. They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions. A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature. Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

Steps

Unresolved Questions

Related

cc @rust-lang/wg-macros @eholk @vincenzopalazzo

@traviscross traviscross added C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) T-lang Relevant to the language team, which will review and decide on the PR/issue. A-edition-2024 Area: The 2024 edition labels Apr 10, 2024
@eholk
Copy link
Contributor

eholk commented Apr 12, 2024

Do we also need item_2021, block_2021, etc.?

@eholk eholk self-assigned this Apr 12, 2024
@Veykril
Copy link
Member

Veykril commented Apr 13, 2024

It depends on what changes to the grammar have occured.

@ehuss
Copy link
Contributor

ehuss commented Apr 13, 2024

Can someone please write down what changes are being done for this?

@eholk
Copy link
Contributor

eholk commented Apr 16, 2024

I haven't heard a clear answer, but it sounds like maybe supporting const { ... } in expressions is the only potential change.

@eholk
Copy link
Contributor

eholk commented Apr 17, 2024

Based on #86730, it looks like we also need to update expr to match let chains.

@eholk
Copy link
Contributor

eholk commented Apr 17, 2024

We might need to update item since we'll be requiring unsafe extern blocks in 2024, but it's not totally clear to me since I think you will be able to use unsafe extern in earlier editions, it just won't be required.

@eholk
Copy link
Contributor

eholk commented Apr 23, 2024

I guess the other potential change for expr is let chains. I spent some time working on them today, and it's not really clear to me what the right behavior is right now.

As I understand the RFC and #86730, we want to update expr in edition 2024 to match let x = y, even though that form is only allowed in the test position of an if or while loop.

This seems weird to me. Do we have expr match let chains unconditionally, and then expect the expansion will fail? Does expr only match a let chain if the macro is called in test position?

I think instead it'd make more sense to add a cond nonterminal what matches anything that can appear in the test position of an if or while loop.

bors added a commit to rust-lang-ci/rust that referenced this issue May 17, 2024
Update `expr` matcher for Edition 2024 and add `expr_2021` nonterminal

This commit adds a new nonterminal `expr_2021` in macro patterns, and `expr_fragment_specifier_2024` feature flag.

This change also updates `expr` so that on Edition 2024 it will also match `const { ... }` blocks, while `expr_2021` preserves the current behavior of `expr`, matching expressions without `const` blocks.

Joint work with `@vincenzopalazzo.`

Issue rust-lang#123742
@traviscross traviscross added S-tracking-impl-incomplete Status: The implementation is incomplete. S-tracking-needs-migration-lint Status: This item needs a migration lint. S-tracking-needs-documentation Status: Needs documentation. B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. labels May 21, 2024
@ehuss
Copy link
Contributor

ehuss commented Jun 20, 2024

See also #126749 about whether or not $item should accept safe fn foo();, and if so should there be a separate $item_2021 for that?

@ehuss
Copy link
Contributor

ehuss commented Jun 20, 2024

@compiler-errors pointed out that safe items won't be an issue, because $item already fails to parse safe fn foo(); because $item can already start with the safe token, so ignore my last comment.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 20, 2024
…xpr2024, r=eholk

migration lint for `expr2024` for the edition 2024

This is adding a migration lint for the current (in the 2021 edition and previous)
to move expr to expr_2021 from expr

Issue rust-lang#123742

I created also a repository to test out the migration https://github.com/vincenzopalazzo/expr2024-cargo-fix-migration

Co-Developed-by: `@eholk`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 20, 2024
Make edition dependent `:expr` macro fragment act like the edition-dependent `:pat` fragment does

Parse the `:expr` fragment as `:expr_2021` in editions <=2021, and as `:expr` in edition 2024. This is similar to how we parse `:pat` as `:pat_param` in edition <=2018 and `:pat_with_or` in >=2021, and means we can get rid of a span dependency from `nonterminal_may_begin_with`.

Specifically, this fixes a theoretical regression since the `expr_2021` macro fragment previously would allow `const {}` if the *caller* is edition 2024. This is inconsistent with the way that the `pat` macro fragment was upgraded, and also leads to surprising behavior when a macro *caller* crate upgrades to edtion 2024, since they may have parsing changes that they never asked for (with no way of opting out of it).

This PR also allows using `expr_2021` in all editions. Why was this was disallowed in the first place? It's purely additive, and also it's still feature gated?

r? `@fmease` `@eholk` cc `@vincenzopalazzo`
cc rust-lang#123865

Tracking:

- rust-lang#123742
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 21, 2024
Make edition dependent `:expr` macro fragment act like the edition-dependent `:pat` fragment does

Parse the `:expr` fragment as `:expr_2021` in editions <=2021, and as `:expr` in edition 2024. This is similar to how we parse `:pat` as `:pat_param` in edition <=2018 and `:pat_with_or` in >=2021, and means we can get rid of a span dependency from `nonterminal_may_begin_with`.

Specifically, this fixes a theoretical regression since the `expr_2021` macro fragment previously would allow `const {}` if the *caller* is edition 2024. This is inconsistent with the way that the `pat` macro fragment was upgraded, and also leads to surprising behavior when a macro *caller* crate upgrades to edtion 2024, since they may have parsing changes that they never asked for (with no way of opting out of it).

This PR also allows using `expr_2021` in all editions. Why was this was disallowed in the first place? It's purely additive, and also it's still feature gated?

r? ``@fmease`` ``@eholk`` cc ``@vincenzopalazzo``
cc rust-lang#123865

Tracking:

- rust-lang#123742
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 21, 2024
Make edition dependent `:expr` macro fragment act like the edition-dependent `:pat` fragment does

Parse the `:expr` fragment as `:expr_2021` in editions <=2021, and as `:expr` in edition 2024. This is similar to how we parse `:pat` as `:pat_param` in edition <=2018 and `:pat_with_or` in >=2021, and means we can get rid of a span dependency from `nonterminal_may_begin_with`.

Specifically, this fixes a theoretical regression since the `expr_2021` macro fragment previously would allow `const {}` if the *caller* is edition 2024. This is inconsistent with the way that the `pat` macro fragment was upgraded, and also leads to surprising behavior when a macro *caller* crate upgrades to edtion 2024, since they may have parsing changes that they never asked for (with no way of opting out of it).

This PR also allows using `expr_2021` in all editions. Why was this was disallowed in the first place? It's purely additive, and also it's still feature gated?

r? ```@fmease``` ```@eholk``` cc ```@vincenzopalazzo```
cc rust-lang#123865

Tracking:

- rust-lang#123742
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jun 21, 2024
Rollup merge of rust-lang#126700 - compiler-errors:fragment, r=fmease

Make edition dependent `:expr` macro fragment act like the edition-dependent `:pat` fragment does

Parse the `:expr` fragment as `:expr_2021` in editions <=2021, and as `:expr` in edition 2024. This is similar to how we parse `:pat` as `:pat_param` in edition <=2018 and `:pat_with_or` in >=2021, and means we can get rid of a span dependency from `nonterminal_may_begin_with`.

Specifically, this fixes a theoretical regression since the `expr_2021` macro fragment previously would allow `const {}` if the *caller* is edition 2024. This is inconsistent with the way that the `pat` macro fragment was upgraded, and also leads to surprising behavior when a macro *caller* crate upgrades to edtion 2024, since they may have parsing changes that they never asked for (with no way of opting out of it).

This PR also allows using `expr_2021` in all editions. Why was this was disallowed in the first place? It's purely additive, and also it's still feature gated?

r? ```@fmease``` ```@eholk``` cc ```@vincenzopalazzo```
cc rust-lang#123865

Tracking:

- rust-lang#123742
@traviscross
Copy link
Contributor Author

To confirm, the current understanding (now reflected in the issue description) is that the item fragment specifier does not need to be migrated.

This is because this is currently an error on stable Rust:

macro_rules! item {
    ($x:item) => {};
    ($(x:tt)*) => {};
}

fn main() {
    item!(safe fn foo() {});
}

...and because this is not an error on stable Rust:

macro_rules! item {
    ($x:item) => { 0u8 };
    ($(x:tt)*) => { 0u16 };
}

fn main() {
    let _: u8 = item!(unsafe extern {});
}

@traviscross traviscross removed the S-tracking-needs-migration-lint Status: This item needs a migration lint. label Jul 16, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 31, 2024
…pression_tok, r=eholk,compiler-errors

[RFC] mbe: consider the `_` in 2024 an expression

This commit is adding the possibility to parse the `_` as an expression inside the esition 2024.

Link: https://rust-lang.zulipchat.com/#narrow/stream/404510-wg-macros/topic/supporting.20.60_.60.20expressions

Issue rust-lang#123742

r? `@eholk`
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Aug 1, 2024
Rollup merge of rust-lang#126697 - vincenzopalazzo:macros/find_the_expression_tok, r=eholk,compiler-errors

[RFC] mbe: consider the `_` in 2024 an expression

This commit is adding the possibility to parse the `_` as an expression inside the esition 2024.

Link: https://rust-lang.zulipchat.com/#narrow/stream/404510-wg-macros/topic/supporting.20.60_.60.20expressions

Issue rust-lang#123742

r? `@eholk`
@ehuss ehuss removed the S-tracking-needs-documentation Status: Needs documentation. label Aug 19, 2024
@traviscross
Copy link
Contributor Author

@rustbot labels +I-lang-nominated

Should we name this new specifier expr_2015 rather than expr_2021?

@rustbot rustbot added the I-lang-nominated Nominated for discussion during a lang team meeting. label Aug 28, 2024
@traviscross
Copy link
Contributor Author

traviscross commented Aug 28, 2024

@rustbot labels -I-lang-nominated

We discussed in the call today. We'll name this expr_2021, as it is now.

And we'll want to get that new specifier stabilized soon, ahead of the edition.

@rustbot rustbot removed the I-lang-nominated Nominated for discussion during a lang team meeting. label Aug 28, 2024
@traviscross traviscross added the S-tracking-ready-to-stabilize Status: This is ready to stabilize; it may need a stabilization report and a PR label Aug 28, 2024
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Sep 19, 2024
…acros-between-edition, r=compiler-errors

test: cross-edition metavar fragment specifiers

There's a subtle interaction between macros with metavar expressions and the edition-dependent fragment matching behavior. This test illustrates the current behavior when using macro-generating-macros across crate boundaries with different editions.

See the original suggestion rust-lang#123865 (comment)

Tracking:

- rust-lang#123742
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 19, 2024
…ros-between-edition, r=compiler-errors

test: cross-edition metavar fragment specifiers

There's a subtle interaction between macros with metavar expressions and the edition-dependent fragment matching behavior. This test illustrates the current behavior when using macro-generating-macros across crate boundaries with different editions.

See the original suggestion rust-lang#123865 (comment)

Tracking:

- rust-lang#123742
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Sep 20, 2024
…acros-between-edition, r=compiler-errors

test: cross-edition metavar fragment specifiers

There's a subtle interaction between macros with metavar expressions and the edition-dependent fragment matching behavior. This test illustrates the current behavior when using macro-generating-macros across crate boundaries with different editions.

See the original suggestion rust-lang#123865 (comment)

Tracking:

- rust-lang#123742
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 20, 2024
Rollup merge of rust-lang#129755 - vincenzopalazzo:macros/recursive-macros-between-edition, r=compiler-errors

test: cross-edition metavar fragment specifiers

There's a subtle interaction between macros with metavar expressions and the edition-dependent fragment matching behavior. This test illustrates the current behavior when using macro-generating-macros across crate boundaries with different editions.

See the original suggestion rust-lang#123865 (comment)

Tracking:

- rust-lang#123742
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 30, 2024
…r-errors

Stabilize expr_2021 fragment specifier in all editions

This is part of the `expr`/`expr_2021` fragment specifier for Edition 2024 (rust-lang#123742). The RFC says we can support expr_2021 in as many editions as is practical, and there's nothing particularly hard about supporting it all the way back to 2015.

In editions 2021 and earlier, `expr` and `expr_2021` are synonyms. Their behavior diverges starting in Edition 2024. This is checked by the `expr_2021_inline_const.rs` test.

cc `@vincenzopalazzo` `@rust-lang/wg-macros` `@traviscross`
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 1, 2024
…r-errors,traviscross

Stabilize expr_2021 fragment specifier in all editions

This is part of the `expr`/`expr_2021` fragment specifier for Edition 2024 (rust-lang#123742). The RFC says we can support expr_2021 in as many editions as is practical, and there's nothing particularly hard about supporting it all the way back to 2015.

In editions 2021 and earlier, `expr` and `expr_2021` are synonyms. Their behavior diverges starting in Edition 2024. This is checked by the `expr_2021_inline_const.rs` test.

cc `@vincenzopalazzo` `@rust-lang/wg-macros` `@traviscross`
@ehuss ehuss removed the S-tracking-impl-incomplete Status: The implementation is incomplete. label Oct 1, 2024
@traviscross traviscross added S-tracking-ready-for-edition Status: This issue is ready for inclusion in the edition. and removed S-tracking-ready-to-stabilize Status: This is ready to stabilize; it may need a stabilization report and a PR labels Oct 1, 2024
@traviscross
Copy link
Contributor Author

@rustbot labels +S-tracking-ready-for-edition

We reviewed this item in the edition call, and we confirmed this is now ready for Rust 2024.

Thanks to @eholk and @vincenzopalazzo for pushing forward on this important work.

@vincenzopalazzo
Copy link
Member

Thank @traviscross manage and coordinate the work👌🏼

youngspe added a commit to youngspe/rust-syntax that referenced this issue Nov 11, 2024
- Add `pat_param` specifier from 2021 edition
- Add `expr_2021` specifier from 2024 edition: https://doc.rust-lang.org/edition-guide/rust-2024/macro-fragment-specifiers.html
  - This specifier is currently unstable but the name seems to be confirmed: rust-lang/rust#123742 (comment)
- Require a word boundary (`\b`) at the end of the specifier
- Replace `[A-Za-z0-9_]` with `\w`
- Allow spaces before and after the `:` in metavariable declarations
- Add tests for the new specifiers and spacing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edition-2024 Area: The 2024 edition A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. S-tracking-ready-for-edition Status: This issue is ready for inclusion in the edition. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants