-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Conversation
rustbot has assigned @compiler-errors. Use |
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 |
763003c
to
9af4537
Compare
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 |
9af4537
to
42752cc
Compare
This comment has been minimized.
This comment has been minimized.
42752cc
to
7cee193
Compare
This comment has been minimized.
This comment has been minimized.
@rustbot author |
7cee193
to
37cf874
Compare
This comment has been minimized.
This comment has been minimized.
37cf874
to
20f5e3f
Compare
☔ The latest upstream changes (presumably #134243) made this pull request unmergeable. Please resolve the merge conflicts. |
20f5e3f
to
c3783c4
Compare
☔ The latest upstream changes (presumably #134788) made this pull request unmergeable. Please resolve the merge conflicts. |
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.
Other than the naming, which I think we should rename to PatExpr
to make it clear that it's the subset of expressions allowed in pats, I think this looks fine.
This comment was marked as resolved.
This comment was marked as resolved.
@bors r=compiler-errors |
Merge `PatKind::Path` into `PatKind::Lit` Follow-up to rust-lang#134228 We always had a duplication where `Path`s could be represented as `PatKind::Path` or `PatKind::Lit(ExprKind::Path)`. We had to handle both everywhere, and still do after rust-lang#134228, so I'm removing it now. subsequently we can also nuke `visit_pattern_type_pattern`
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#134228 (Exhaustively handle expressions in patterns) - rust-lang#135194 (triagebot: mark tidy changes with a more specific `A-tidy` label) - rust-lang#135222 (Ensure that we don't try to access fields on a non-struct pattern type) - rust-lang#135250 (A couple simple borrowck cleanups) - rust-lang#135252 (Fix release notes link) - rust-lang#135253 (Revert rust-lang#131365) Failed merges: - rust-lang#135195 (Make `lit_to_mir_constant` and `lit_to_const` infallible) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#134228 (Exhaustively handle expressions in patterns) - rust-lang#135194 (triagebot: mark tidy changes with a more specific `A-tidy` label) - rust-lang#135222 (Ensure that we don't try to access fields on a non-struct pattern type) - rust-lang#135250 (A couple simple borrowck cleanups) - rust-lang#135252 (Fix release notes link) - rust-lang#135253 (Revert rust-lang#131365) Failed merges: - rust-lang#135195 (Make `lit_to_mir_constant` and `lit_to_const` infallible) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#134228 - oli-obk:pat-lit-path, r=compiler-errors Exhaustively handle expressions in patterns 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
Only treat plain literal patterns as short See rust-lang#134228 (comment) and rust-lang#134228 (comment) for context. We never wanted to treat const blocks and paths as short, only plain literals. I don't know how to write a test for this, it.s not clear to me how the short pattern check actually affects the formatting
Merge `PatKind::Path` into `PatKind::Lit` Follow-up to rust-lang#134228 We always had a duplication where `Path`s could be represented as `PatKind::Path` or `PatKind::Lit(ExprKind::Path)`. We had to handle both everywhere, and still do after rust-lang#134228, so I'm removing it now. subsequently we can also nuke `visit_pattern_type_pattern`
Rollup merge of rust-lang#135251 - oli-obk:push-lmpyvvyrtplk, r=ytmimi Only treat plain literal patterns as short See rust-lang#134228 (comment) and rust-lang#134228 (comment) for context. We never wanted to treat const blocks and paths as short, only plain literals. I don't know how to write a test for this, it.s not clear to me how the short pattern check actually affects the formatting
Only treat plain literal patterns as short See rust-lang#134228 (comment) and rust-lang#134228 (comment) for context. We never wanted to treat const blocks and paths as short, only plain literals. I don't know how to write a test for this, it.s not clear to me how the short pattern check actually affects the formatting
Only treat plain literal patterns as short See rust-lang#134228 (comment) and rust-lang#134228 (comment) for context. We never wanted to treat const blocks and paths as short, only plain literals. I don't know how to write a test for this, it.s not clear to me how the short pattern check actually affects the formatting
Only treat plain literal patterns as short See rust-lang#134228 (comment) and rust-lang#134228 (comment) for context. We never wanted to treat const blocks and paths as short, only plain literals. I don't know how to write a test for this, it.s not clear to me how the short pattern check actually affects the formatting
Rollup merge of rust-lang#135251 - oli-obk:push-lmpyvvyrtplk, r=ytmimi Only treat plain literal patterns as short See rust-lang#134228 (comment) and rust-lang#134228 (comment) for context. We never wanted to treat const blocks and paths as short, only plain literals. I don't know how to write a test for this, it.s not clear to me how the short pattern check actually affects the formatting
Merge `PatKind::Path` into `PatKind::Lit` Follow-up to rust-lang#134228 We always had a duplication where `Path`s could be represented as `PatKind::Path` or `PatKind::Lit(ExprKind::Path)`. We had to handle both everywhere, and still do after rust-lang#134228, so I'm removing it now.
Merge `PatKind::Path` into `PatKind::Lit` Follow-up to rust-lang#134228 We always had a duplication where `Path`s could be represented as `PatKind::Path` or `PatKind::Lit(ExprKind::Path)`. We had to handle both everywhere, and still do after rust-lang#134228, so I'm removing it now.
We currently have this invariant in HIR that a
PatKind::Lit
or aPatKind::Range
only containsExprKind::Lit
ExprKind::UnOp(Neg, ExprKind::Lit)
ExprKind::Path
ExprKind::ConstBlock
So I made
PatKind::Lit
andPatKind::Range
stop containingExpr
, and instead created aPatLit
type whosekind
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
handlingIt may be interesting on merging
ExprKind::{Path,Lit,ConstBlock}
in the future and using the samePatLit
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