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

Make missing_fragment_specifier an error in edition 2024 #128006

Merged
merged 1 commit into from
Jul 27, 2024

Conversation

tgross35
Copy link
Contributor

@tgross35 tgross35 commented Jul 20, 2024

missing_fragment_specifier has been a future compatibility warning since 2017. Uplifting it to an unconditional hard error was attempted in 2020, but eventually reverted due to fallout.

Make it an error only in edition >= 2024, leaving the lint for older editions. This change will make it easier to support more macro syntax that relies on usage of $.

Fixes #40107


It is rather late for the edition but since this change is relatively small, it seems worth at least bringing up. This follows a brief Zulip discussion (cc @tmandry).

Making this an edition-dependent lint has come up before but there was not a strong motivation. I am proposing it at this time because this would simplify the named macro capture groups RFC, which has had mildly positive response, and makes use of new $ syntax in the matcher. The proposed syntax currently parses as metavariables without a fragment specifier; this warning is raised, but there are no errors.

It is obviously not known that this specific RFC will eventually be accepted, but forbidding missing_fragment_specifier should make it easier to support any new syntax in the future that makes use of $ in different ways. The syntax conflict is also not impossible to overcome, but making it clear that unnamed metavariables are rejected makes things more straightforward and should allow for better diagnostics.

@Mark-Simulacrum suggested making this forbid-by-default instead of an error at #40107 (comment), but I don't think this would allow the same level of syntax flexibility.

It is also possible to reconsider making this an unconditional error since four years have elapsed since the previous attempt, but this seems likely to hit the same pitfalls. (Possibly worth a crater run?)

Nominating for discussion to get this on the radar.

r? @petrochenkov

Tracking:

@tgross35 tgross35 added T-lang Relevant to the language team, which will review and decide on the PR/issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. D-edition Diagnostics: An error or lint that should account for edition differences. I-lang-nominated Nominated for discussion during a lang team meeting. A-edition-2024 Area: The 2024 edition labels Jul 20, 2024
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 20, 2024
@tgross35
Copy link
Contributor Author

tgross35 commented Jul 20, 2024

This PR is really just a proof of concept at this point to start discussion, needs more tests and maybe we can reuse the diagnostics somehow. And I am unsure why the error fires twice both for the lint (as noted in the FIXME that should be removed) and the diagnostic (petrochenkov I could use your guidance).

@WaffleLapkin

This comment has been minimized.

@petrochenkov
Copy link
Contributor

I'd prefer to turn this into a hard error if possible.
Maybe make it FutureReleaseErrorReportInDeps first, if crater still finds too many errors after all these years.

@petrochenkov petrochenkov added S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 23, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 24, 2024
…unconditional, r=<try>

[do not merge] crater: missing fragment specifier FutureReleaseErrorReportInDeps

Test making missing fragment specifiers a deny by default error.

See rust-lang#128006

r? `@petrochenkov`
@joshtriplett
Copy link
Member

We discussed this in today's lang team meeting. We are in favor of making this change for the edition.

Independently, we'd also be in favor of confirming whether we can do it in past editions at this point (in case things have changed since 2020). That checking should not be a blocker for proceeding with making it a hard error for Rust 2024, though.

@traviscross
Copy link
Contributor

traviscross commented Jul 24, 2024

@rustbot labels -needs-fcp -I-lang-nominated -S-waiting-on-team

We had 5/6 members present and this seemed a clear call. This is OK to proceed as far as lang is concerned (without FCP).

On the edition team side...

We've opened an edition tracking issue for this:

@tgross35: To be included in the edition, in addition to this PR, this will need a chapter added to the edition guide, and the Reference will need to be checked and a PR made for any updates that should happen there.

Also, will this cause an error, as desired, if someone using one of these fragments writes (in Rust 2021)?:

#![deny(rust_2024_compatibility)]

cc @ehuss

@rustbot rustbot removed needs-fcp This change is insta-stable, so needs a completed FCP to proceed. I-lang-nominated Nominated for discussion during a lang team meeting. S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels Jul 24, 2024
@tgross35
Copy link
Contributor Author

tgross35 commented Jul 24, 2024

Thank you for discussing this. It seems like it makes sense to move this PR forward, with a change to unconditional for crater coming as a followup since that isn't time-sensitive.

Also, will this cause an error, as desired, if someone using one of these fragments writes (in Rust 2021)?:

#![deny(rust_2024_compatibility)]

Is there a way to add a lint to multiple lint groups? It seems to lint on rust_2024_compatibility that the reason needs to be an EditionError, but it seems like we might not want to lose the seemingly more noisy (in a good way) FutureReleaseErrorReportInDeps. From #128122.

I don't know exactly what is needed to make the changes in this PR make sense, if they don't already. So:

@rustbot ready

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 24, 2024
@bors
Copy link
Contributor

bors commented Jul 25, 2024

☔ The latest upstream changes (presumably #128155) made this pull request unmergeable. Please resolve the merge conflicts.

@ehuss
Copy link
Contributor

ehuss commented Jul 25, 2024

Is there a way to add a lint to multiple lint groups?

Not easily AFAIK.

I don't recall us ever having something that needed to be both an edition lint and a future reporting lint.

I think this PR shouldn't be a problem in itself, and I don't think this needs a migration lint. The lint is already deny-by-default, and we generally expect that a project should be warning-free before starting the migration. I also don't see anyone in crates.io allowing it.

I'm assuming the intent here is that this PR is just a temporary change, since it looks like the intent is to make it a hard error in all editions. I do not know what criteria you will be using to make that change, since it looks like from #76605 there was a decent amount of regressions.

@traviscross
Copy link
Contributor

OK. Per the reply from @ehuss, since this is already deny-by-default, this is OK from an edition perspective.

@petrochenkov: This is ready for your review and good to go both as far as lang and edition are concerned.

@tgross35
Copy link
Contributor Author

tgross35 commented Jul 26, 2024

I'm assuming the intent here is that this PR is just a temporary change, since it looks like the intent is to make it a hard error in all editions. I do not know what criteria you will be using to make that change, since it looks like from #76605 there was a decent amount of regressions.

As I am understanding it, the process will roughly be:

node_id,
BuiltinLintDiag::MissingFragmentSpecifier,
);
if psess.edition >= Edition::Edition2024 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks edition hygiene and uses global psess.edition instead of span.edition(), so 2024 edition code won't be able to use old crates with missing metavar kinds.
But that should be fine if it's eventually going to turn into a hard error anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to span.edition() to be safe.

@petrochenkov
Copy link
Contributor

r=me after rebase.
@rustbot author

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 27, 2024
@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 27, 2024
`missing_fragment_specifier` has been a future compatibility warning
since 2017. Uplifting it to an unconditional hard error was attempted in
2020, but eventually reverted due to fallout.

Make it an error only in edition >= 2024, leaving the lint for older
editions. This change will make it easier to support more macro syntax
that relies on usage of `$`.

Fixes <rust-lang#40107>
@tgross35 tgross35 force-pushed the missing-fragment-specifier-e2024 branch from 4e851a5 to 8c402f1 Compare July 27, 2024 09:33
@tgross35
Copy link
Contributor Author

Rebased, tests still pass after using span.edition(). Thanks for taking a look.

@bors r=petrochenkov

@bors
Copy link
Contributor

bors commented Jul 27, 2024

📌 Commit 8c402f1 has been approved by petrochenkov

It is now in the queue for this repository.

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 27, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 27, 2024
…r-e2024, r=petrochenkov

Make `missing_fragment_specifier` an error in edition 2024

`missing_fragment_specifier` has been a future compatibility warning since 2017. Uplifting it to an unconditional hard error was attempted in 2020, but eventually reverted due to fallout.

Make it an error only in edition >= 2024, leaving the lint for older editions. This change will make it easier to support more macro syntax that relies on usage of `$`.

Fixes <rust-lang#40107>

---

It is rather late for the edition but since this change is relatively small, it seems worth at least bringing up. This follows a brief [Zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/268952-edition/topic/.60.20DBD.20-.3E.20hard.20error) (cc `@tmandry).`

Making this an edition-dependent lint has come up before but there was not a strong motivation. I am proposing it at this time because this would simplify the [named macro capture groups](rust-lang/rfcs#3649) RFC, which has had mildly positive response, and makes use of new `$` syntax in the matcher. The proposed syntax currently parses as metavariables without a fragment specifier; this warning is raised, but there are no errors.

It is obviously not known that this specific RFC will eventually be accepted, but forbidding `missing_fragment_specifier` should make it easier to support any new syntax in the future that makes use of `$` in different ways. The syntax conflict is also not impossible to overcome, but making it clear that unnamed metavariables are rejected makes things more straightforward and should allow for better diagnostics.

`@Mark-Simulacrum` suggested making this forbid-by-default instead of an error at rust-lang#40107 (comment), but I don't think this would allow the same level of syntax flexibility.

It is also possible to reconsider making this an unconditional error since four years have elapsed since the previous attempt, but this seems likely to hit the same pitfalls. (Possibly worth a crater run?)

Tracking:

- rust-lang#128143
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 27, 2024
…iaskrgr

Rollup of 3 pull requests

Successful merges:

 - rust-lang#128006 (Make `missing_fragment_specifier` an error in edition 2024)
 - rust-lang#128207 (improve error message when `global_asm!` uses `asm!` options)
 - rust-lang#128266 (update `rust.channel` default value documentation)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors
Copy link
Contributor

bors commented Jul 27, 2024

⌛ Testing commit 8c402f1 with merge 8fe0c75...

@bors
Copy link
Contributor

bors commented Jul 27, 2024

☀️ Test successful - checks-actions
Approved by: petrochenkov
Pushing 8fe0c75 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 27, 2024
@bors bors merged commit 8fe0c75 into rust-lang:master Jul 27, 2024
7 checks passed
@rustbot rustbot added this to the 1.82.0 milestone Jul 27, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (8fe0c75): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (primary -3.2%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.2% [-3.2%, -3.2%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -3.2% [-3.2%, -3.2%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 771.748s -> 772.472s (0.09%)
Artifact size: 329.08 MiB -> 329.05 MiB (-0.01%)

@tgross35 tgross35 deleted the missing-fragment-specifier-e2024 branch July 27, 2024 17:15
tgross35 added a commit to tgross35/rust that referenced this pull request Jul 31, 2024
This was attempted in [1] then reverted in [2] because of fallout.
Recently, this was made an edition-dependent error in [3].

Make missing fragment specifiers an unconditional error again.

[1]: rust-lang#75516
[2]: rust-lang#80210
[3]: rust-lang#128006
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 31, 2024
…unconditional, r=<try>

[crater] Make `missing_fragment_specifier` an unconditional error

This was attempted in [1] then reverted in [2] because of fallout. Recently, this was made an edition-dependent error in [3].

Experiment with turning missing fragment specifiers an unconditional error again.

More context: rust-lang#128006

[1]: rust-lang#75516
[2]: rust-lang#80210
[3]: rust-lang#128006
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 D-edition Diagnostics: An error or lint that should account for edition differences. merged-by-bors This PR was explicitly merged by bors. 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. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracking issue for future-incompatibility lint missing_fragment_specifier
9 participants