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

Cleanup: Move an impl-Trait check from AST validation to AST lowering #132214

Merged
merged 1 commit into from
Oct 27, 2024

Conversation

fmease
Copy link
Member

@fmease fmease commented Oct 27, 2024

Namely the one that rejects impl Trait in qself types and non-final path segments.
There's no good reason to perform this during AST validation.
We have better infrastructure in place in the AST lowerer (ImplTraitContext).
This shaves off a lot of code.
We now lower impl Trait in bad positions to {type error} which allows us to
remove a special case from HIR ty lowering.

Coincidentally fixes #126725. Well, it only masks it by passing {type error} to HIR analysis instead of a "bad" opaque. I was able to find a new reproducer for it. See the issue.

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

rustbot commented Oct 27, 2024

r? @petrochenkov

rustbot has assigned @petrochenkov.
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 S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 27, 2024
Comment on lines -1207 to -1214
// `<impl Trait as OtherTrait>::Assoc` makes no sense.
struct_span_code_err!(
self.dcx(),
tcx.def_span(alias_ty.def_id),
E0667,
"`impl Trait` is not allowed in path parameters"
)
.emit() // Already reported in an earlier stage.
Copy link
Member Author

@fmease fmease Oct 27, 2024

Choose a reason for hiding this comment

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

This should've been a span_delayed_bug in the first place (before this PR). This double emission (once during AST validation, once here during HIR ty lowering) actually lead to two identical diagnostics getting emitted (indeed, even without -Zdeduplicate-diagnostics=no).

LL | fn projection_is_disallowed(x: impl Iterator) -> <impl Iterator>::Item {
| ^^^^^^^^^^^^^

error[E0277]: the trait bound `impl Debug: Step` is not satisfied
Copy link
Member Author

@fmease fmease Oct 27, 2024

Choose a reason for hiding this comment

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

Both "impl Debug: Step diagnostics" were just useless. They obscured the more important issues (impl-Trait in a forbidden context) and plastered the terminal.

@rust-log-analyzer

This comment has been minimized.

Copy link
Member Author

@fmease fmease Oct 27, 2024

Choose a reason for hiding this comment

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

cc @compiler-errors since you assigned yourself to #126725. However, my PR just masks the bug by lowering the "bad" opaque to {type error}. I should come up with a different reproducer as the underlying bug still hasn't been fixed.

Copy link
Member Author

@fmease fmease Oct 27, 2024

Choose a reason for hiding this comment

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

Right, I was able to find a new reproducer for the underlying bug: #126725 (comment). I guess I will reopen #126725 once it gets closed. And I should maybe add a new crash test in this PR.

@compiler-errors
Copy link
Member

Thanks @fmease for your very detailed comments as always 👍

@bors r+

@bors
Copy link
Contributor

bors commented Oct 27, 2024

📌 Commit 442f395 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 Oct 27, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 27, 2024
…compiler-errors

Cleanup: Move an impl-Trait check from AST validation to AST lowering

Namely the one that rejects `impl Trait` in qself types and non-final path segments.
There's no good reason to perform this during AST validation.
We have better infrastructure in place in the AST lowerer (`ImplTraitContext`).
This shaves off a lot of code.
We now lower `impl Trait` in bad positions to `{type error}` which allows us to
remove a special case from HIR ty lowering.

Coincidentally fixes rust-lang#126725. Well, it only *masks* it by passing `{type error}` to HIR analysis instead of a "bad" opaque. I was able to find a new reproducer for it. See the issue.
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 27, 2024
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#132043 (Simplify param handling in `resolve_bound_vars`)
 - rust-lang#132214 (Cleanup: Move an impl-Trait check from AST validation to AST lowering)
 - rust-lang#132221 (Clean up some comments on lint implementation)
 - rust-lang#132228 (Revert "ci update freebsd version proposal, freebsd 12 being eol.")
 - rust-lang#132234 (Miri subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 574a8ba into rust-lang:master Oct 27, 2024
6 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Oct 27, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 27, 2024
Rollup merge of rust-lang#132214 - fmease:mv-impl-trait-val-paths, r=compiler-errors

Cleanup: Move an impl-Trait check from AST validation to AST lowering

Namely the one that rejects `impl Trait` in qself types and non-final path segments.
There's no good reason to perform this during AST validation.
We have better infrastructure in place in the AST lowerer (`ImplTraitContext`).
This shaves off a lot of code.
We now lower `impl Trait` in bad positions to `{type error}` which allows us to
remove a special case from HIR ty lowering.

Coincidentally fixes rust-lang#126725. Well, it only *masks* it by passing `{type error}` to HIR analysis instead of a "bad" opaque. I was able to find a new reproducer for it. See the issue.
@bors
Copy link
Contributor

bors commented Oct 27, 2024

⌛ Testing commit 442f395 with merge df4ca44...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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-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.

ICE: X should not have been constrained via normalization
6 participants