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

Mostly parser: Eliminate code that's been dead / semi-dead since the removal of type ascription syntax #138898

Merged
merged 5 commits into from
Mar 26, 2025

Conversation

fmease
Copy link
Member

@fmease fmease commented Mar 24, 2025

Disclaimer: This PR is intended to mostly clean up code as opposed to bringing about behavioral changes. Therefore it doesn't aim to address any of the 'FIXME: remove after a month [dated: 2023-05-02]: "type ascription syntax has been removed, see issue [#]101728"'.


By commit:

  1. Removes truly dead code:
    • Since 1.71 (Remove type ascription from parser and diagnostics #109128) let _ = { f: x }; is a syntax error as opposed to a semantic error which allows the parse-time diagnostic (suggestion) "struct literal body without path // you might have forgotten […]" to kick in.
    • The analysis-time diagnostic (suggestion) from <=1.70 "cannot find value `f` in this scope // you might have forgotten […]" is therefore no longer reachable.
  2. Updates is_certainly_not_a_block to be in line with the current grammar:
    • The seq. { ident: is definitely not the start of a block. Before the removal of ty ascr, { ident: ty_start would begin a block expr.
    • This shouldn't make more code compile IINM, it should ultimately only affect diagnostics.
    • For example, if T { f: () } {} will now be interpreted as an if with struct lit T { f: () } as its condition (which is banned in the parser anyway) as opposed to just T (with the consequent being f : () which is also invalid (since 1.71)). The diagnostics are almost the same because we have two separate parse recovery procedures + diagnostics: StructLiteralNeedingParens (invalid struct lit) before and StructLiteralNotAllowedHere (struct lits aren't allowed here) now, as you can see from the diff.
    • (As an aside, even before this PR, fn maybe_suggest_struct_literal should've just used the much older & clearer StructLiteralNotAllowedHere)
    • NB: This does sadly regress the compiler output for tests/ui/parser/type-ascription-in-pattern.rs but that can be fixed in follow-up PRs. It's not super important IMO and a natural consequence.
  3. Removes code that's become dead due to the prior commit.
  4. Merge and simplify UI tests pertaining to this issue, so it's easier to add more regression tests like for the two cases mentioned above.
  5. Merge UI tests and add the two regression tests.

Best reviewed commit by commit (on request I'll partially squash after approval).

@fmease fmease added the C-cleanup Category: PRs that clean code up or issues documenting cleanup. label Mar 24, 2025
@rustbot
Copy link
Collaborator

rustbot commented Mar 24, 2025

r? @BoxyUwU

rustbot has assigned @BoxyUwU.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-tidy Area: The tidy tool S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 24, 2025
@rustbot
Copy link
Collaborator

rustbot commented Mar 24, 2025

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

@rust-log-analyzer

This comment has been minimized.

@fmease fmease force-pushed the decrustify-parser-post-ty-ascr branch from bae038e to b573f39 Compare March 24, 2025 18:22
@rust-log-analyzer

This comment has been minimized.

Since `{ ident: ident }` is a parse error, these fields are dead.
@fmease fmease force-pushed the decrustify-parser-post-ty-ascr branch from b573f39 to d5585b3 Compare March 24, 2025 19:04
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

r=me, i don't think it needs squashing.

i somewhat think is_certainly_not_a_block should have some sort of prefix like _for_diagnostics to make it clear that it's not a guarantee, but also the way it's being used today is also not really "for diagnosics" either since it influences parsing without may_recover (but, i guess that's fine technically in this situation...)

@compiler-errors
Copy link
Member

r? compiler-errors @bors r+

@bors
Copy link
Contributor

bors commented Mar 24, 2025

📌 Commit d5585b3 has been approved by compiler-errors

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-review Status: Awaiting review from the assignee but also interested parties. labels Mar 24, 2025
fmease added 4 commits March 25, 2025 15:15
thanks to the removal of type ascription.
StructLiteralNeedingParens is no longer reachable always giving
precedence to StructLiteralNotAllowedHere.

As an aside: The former error struct shouldn't've existed in the
first place. We should've just used the latter in this branch.
This makes it a lot easier to add smaller regression tests
related to "incorrectly placed" struct literals.
…st cases

Note that issue-111692.rs was incorrectly named: It's a regression test for
issue [#]112278, not for [#]111692. That's been addressed, too.
@fmease fmease force-pushed the decrustify-parser-post-ty-ascr branch from d5585b3 to b501e58 Compare March 25, 2025 14:16
@fmease
Copy link
Member Author

fmease commented Mar 25, 2025

I've allowed myself to further simplify is_certainly_not_a_block and to fix a typo (diff). Sry

@bors r=compiler-errors

@bors
Copy link
Contributor

bors commented Mar 25, 2025

📌 Commit b501e58 has been approved by compiler-errors

It is now in the queue for this repository.

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 26, 2025
Rollup of 7 pull requests

Successful merges:

 - rust-lang#138483 (Target modifiers fix for bool flags without value)
 - rust-lang#138818 (Don't produce debug information for compiler-introduced-vars when desugaring assignments.)
 - rust-lang#138898 (Mostly parser: Eliminate code that's been dead / semi-dead since the removal of type ascription syntax)
 - rust-lang#138930 (Add bootstrap step diff to CI job analysis)
 - rust-lang#138954 (Ensure `define_opaque` attrs are accounted for in HIR hash)
 - rust-lang#138959 (Revert "Make MatchPairTree::place non-optional")
 - rust-lang#138967 (Fix typo in error message)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 30344f7 into rust-lang:master Mar 26, 2025
6 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Mar 26, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 26, 2025
Rollup merge of rust-lang#138898 - fmease:decrustify-parser-post-ty-ascr, r=compiler-errors

Mostly parser: Eliminate code that's been dead / semi-dead since the removal of type ascription syntax

**Disclaimer**: This PR is intended to mostly clean up code as opposed to bringing about behavioral changes. Therefore it doesn't aim to address any of the 'FIXME: remove after a month [dated: 2023-05-02]: "type ascription syntax has been removed, see issue [#]101728"'.

---

By commit:

1. Removes truly dead code:
   * Since 1.71 (rust-lang#109128) `let _ = { f: x };` is a syntax error as opposed to a semantic error which allows the parse-time diagnostic (suggestion) "*struct literal body without path // you might have forgotten […]*" to kick in.
   * The analysis-time diagnostic (suggestion) from <=1.70 "*cannot find value \`f\` in this scope // you might have forgotten […]*" is therefore no longer reachable.
2. Updates `is_certainly_not_a_block` to be in line with the current grammar:
   * The seq. `{ ident:` is definitely not the start of a block. Before the removal of ty ascr, `{ ident: ty_start` would begin a block expr.
   * This shouldn't make more code compile IINM, it should *ultimately* only affect diagnostics.
   * For example, `if T { f: () } {}` will now be interpreted as an `if` with struct lit `T { f: () }` as its *condition* (which is banned in the parser anyway) as opposed to just `T` (with the *consequent* being `f : ()` which is also invalid (since 1.71)). The diagnostics are almost the same because we have two separate parse recovery procedures + diagnostics: `StructLiteralNeedingParens` (*invalid struct lit*) before and `StructLiteralNotAllowedHere` (*struct lits aren't allowed here*) now, as you can see from the diff.
   * (As an aside, even before this PR, fn `maybe_suggest_struct_literal` should've just used the much older & clearer `StructLiteralNotAllowedHere`)
   * NB: This does sadly regress the compiler output for `tests/ui/parser/type-ascription-in-pattern.rs` but that can be fixed in follow-up PRs. It's not super important IMO and a natural consequence.
3. Removes code that's become dead due to the prior commit.
   * Basically reverts rust-lang#106620 + rust-lang#112475 (without regressing rustc's output!).
   * Now the older & more robust parse recovery procedure (cc `StructLiteralNotAllowedHere`) takes care of the cases the removed code used to handle.
   * This automatically fixes the suggestions for \[[playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=7e2030163b11ee96d17adc3325b01780)\]:
     * `if Ty::<i32> { f: K }.m() {}`: `if Ty::<i32> { SomeStruct { f: K } }.m() {}` (broken) → ` if (Ty::<i32> { f: K }).m() {}`
     * `if <T as Trait>::Out { f: K::<> }.m() {}`: `if <T as Trait>(::Out { f: K::<> }).m() {}` (broken) → `if (<T as Trait>::Out { f: K::<> }).m() {}`
4. Merge and simplify UI tests pertaining to this issue, so it's easier to add more regression tests like for the two cases mentioned above.
5. Merge UI tests and add the two regression tests.

Best reviewed commit by commit (on request I'll partially squash after approval).
@fmease fmease deleted the decrustify-parser-post-ty-ascr branch March 26, 2025 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tidy Area: The tidy tool C-cleanup Category: PRs that clean code up or issues documenting cleanup. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.

6 participants