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

Open
2 of 7 tasks
traviscross opened this issue Apr 10, 2024 · 12 comments
Open
2 of 7 tasks
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-impl-incomplete Status: The implementation is incomplete. S-tracking-needs-documentation Status: Needs documentation. S-tracking-needs-migration-lint Status: This item needs a migration lint. 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

  • Is there a reasonable semantically-appropriate name for expr_2021, or should we just call it that per the RFC?

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 {});
}

@eholk
Copy link
Contributor

eholk commented Jun 21, 2024

You know, all these examples to answer questions we have here should probably be added to the test suite so we have more confidence in the future.

flip1995 pushed a commit to flip1995/rust-clippy that referenced this issue Jun 28, 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 #123865

Tracking:

- rust-lang/rust#123742
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 9, 2024
…xpr2024, r=compiler-errors,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`
jhpratt added a commit to jhpratt/rust that referenced this issue Jul 10, 2024
…xpr2024, r=compiler-errors,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 Jul 10, 2024
…xpr2024, r=compiler-errors,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```
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jul 10, 2024
Rollup merge of rust-lang#125627 - vincenzopalazzo:macros/cargo-fix-expr2024, r=compiler-errors,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``
@ehuss
Copy link
Contributor

ehuss commented Jul 10, 2024

Draft of edition docs is up at rust-lang/edition-guide#312.

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-impl-incomplete Status: The implementation is incomplete. S-tracking-needs-documentation Status: Needs documentation. S-tracking-needs-migration-lint Status: This item needs a migration lint. 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

4 participants