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

Exhaustively handle expressions in patterns #134228

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Dec 12, 2024

We currently have this invariant in HIR that a PatKind::Lit or a PatKind::Range only contains

  • ExprKind::Lit
  • ExprKind::UnOp(Neg, ExprKind::Lit)
  • ExprKind::Path
  • ExprKind::ConstBlock

So I made PatKind::Lit and PatKind::Range stop containing Expr, and instead created a PatLit type whose kind enum only contains those variants.

The only place code got more complicated was in clippy, as it couldn't share as much anymore with Expr handling

It may be interesting on merging ExprKind::{Path,Lit,ConstBlock} in the future and using the same PatLit type (under a new name).

Then it should also be easier to eliminate any and all UnOp(Neg, Lit) | Lit matching that we have across the compiler. Some day we should fold the negation into the literal itself and just store it on the numeric literals

@rustbot
Copy link
Collaborator

rustbot commented Dec 12, 2024

r? @compiler-errors

rustbot has assigned @compiler-errors.
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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Dec 12, 2024
@rustbot
Copy link
Collaborator

rustbot commented Dec 12, 2024

HIR ty lowering was modified

cc @fmease

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred in match checking

cc @Nadrieril

@rustbot
Copy link
Collaborator

rustbot commented Dec 12, 2024

HIR ty lowering was modified

cc @fmease

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred in match checking

cc @Nadrieril

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 12, 2024
@oli-obk
Copy link
Contributor Author

oli-obk commented Dec 13, 2024

I removed the PatKind::Path removal from this PR. I think it should be done, but I'm doing it as a follow-up PR in #134248

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 13, 2024
@rust-log-analyzer

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants