-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Make edition dependent :expr
macro fragment act like the edition-dependent :pat
fragment does
#126700
Conversation
@@ -884,7 +884,11 @@ pub enum NonterminalKind { | |||
PatWithOr, | |||
Expr, | |||
/// Matches an expression using the rules from edition 2021 and earlier. | |||
Expr2021, | |||
Expr2021 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated -- but I wonder if we can come up with a more descriptive name. expr_2021
gives me the vibe that its new to 2021 (i.e. >=2021) not legacy to 2021 (i.e. <=2021).
I quite like PatParam
and PatWithOr
naming scheme since it makes it less about edition and more about what it's parsing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree the _2021
suffix's meaning is non-obvious, and even after learning what it means it I keep having trouble remembering the meaning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have been thinking about a good name for a while now because I often get confused when reading the code a week later.
However, I think expr_2021 is one of the best names we can choose. If we update the documentation to explain that expr_2021 includes all features up to the 2021 edition, and expr includes all features of the current edition (up to 2024 in this case), it would be clear.
This approach can be applied retroactively as well. We do not have an expr_2018 because there were no changes in the semantics of expr at that time.
Do you think your concern can be addressed by updating the documentation to clearly explain this way of thinking?
I am also considering that if we give another name without referencing the edition, and if expr keeps changing in the next edition, keeping track of and explaining all the different expr types will be a mess, in my opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can use the year as a suffix for saying "the moment in was introduced", that would mean we would have Expr2015
and Expr2024
; that would follow "the vibe that its new to 2024".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm, are we agreeing that Expr2021 would include all features up to the 2021 edition, and Expr would continue to represent the current edition's features?
Or are you proposing a slightly different idea from what we are currently implementing?
By the way, I am happy with either approach, but I think it is important for users that we clearly indicate the edition where the expr_* is necessary to maintain old behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good catch, that makes a lot of sense! Thanks :)
@bors r+ |
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
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#125627 (migration lint for `expr2024` for the edition 2024) - rust-lang#126481 (Add `powerpc-unknown-openbsd` maintaince status) - rust-lang#126613 (Print the tested value in int_log tests) - rust-lang#126617 (Expand `avx512_target_feature` to include VEX variants) - rust-lang#126686 (Add `#[rustc_dump_{predicates,item_bounds}]`) - rust-lang#126700 (Make edition dependent `:expr` macro fragment act like the edition-dependent `:pat` fragment does) - rust-lang#126707 (Pass target to inaccessible-temp-dir rmake test) - rust-lang#126757 (Properly gate `safe` keyword in pre-expansion) r? `@ghost` `@rustbot` modify labels: rollup
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
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#124101 (Add PidFd::{kill, wait, try_wait}) - rust-lang#126125 (Improve conflict marker recovery) - rust-lang#126481 (Add `powerpc-unknown-openbsd` maintenance status) - rust-lang#126613 (Print the tested value in int_log tests) - rust-lang#126617 (Expand `avx512_target_feature` to include VEX variants) - rust-lang#126700 (Make edition dependent `:expr` macro fragment act like the edition-dependent `:pat` fragment does) - rust-lang#126707 (Pass target to inaccessible-temp-dir rmake test) - rust-lang#126767 (`StaticForeignItem` and `StaticItem` are the same) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#126125 (Improve conflict marker recovery) - rust-lang#126481 (Add `powerpc-unknown-openbsd` maintenance status) - rust-lang#126613 (Print the tested value in int_log tests) - rust-lang#126617 (Expand `avx512_target_feature` to include VEX variants) - rust-lang#126700 (Make edition dependent `:expr` macro fragment act like the edition-dependent `:pat` fragment does) - rust-lang#126707 (Pass target to inaccessible-temp-dir rmake test) - rust-lang#126767 (`StaticForeignItem` and `StaticItem` are the same) - rust-lang#126774 (Fix another assertion failure for some Expect diagnostics.) r? `@ghost` `@rustbot` modify labels: rollup
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
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 fromnonterminal_may_begin_with
.Specifically, this fixes a theoretical regression since the
expr_2021
macro fragment previously would allowconst {}
if the caller is edition 2024. This is inconsistent with the way that thepat
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:
expr
macro fragment specifier for Rust 2024 #123742