Exhaustively handle expressions in patterns by oli-obk · Pull Request #134228 · rust-lang/rust

@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 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

@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

compiler-errors

compiler-errors

bors added a commit to rust-lang-ci/rust that referenced this pull request

Jan 10, 2025
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`

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Jan 10, 2025
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

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Jan 16, 2025
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

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Jan 16, 2025
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

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Jan 16, 2025
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

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Jan 16, 2025
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

bors added a commit to rust-lang-ci/rust that referenced this pull request

Jan 17, 2025
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.

bors added a commit to rust-lang-ci/rust that referenced this pull request

Jan 17, 2025
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.

bors added a commit to rust-lang-ci/rust that referenced this pull request

Jan 20, 2025
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.

bors added a commit to rust-lang-ci/rust that referenced this pull request

Jan 23, 2025
Merge `PatKind::Path` into `PatKind::Expr`

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.

bors added a commit to rust-lang-ci/rust that referenced this pull request

Jan 23, 2025
Merge `PatKind::Path` into `PatKind::Expr`

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.

bors added a commit to rust-lang-ci/rust that referenced this pull request

Jan 29, 2025
Merge `PatKind::Path` into `PatKind::Expr`

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.

This was referenced

Jan 30, 2025

bors added a commit to rust-lang-ci/rust that referenced this pull request

Feb 3, 2025
…, r=<try>

Fix accidentally not emitting overflowing literals lints anymore in patterns

This was regressed in rust-lang#134228 (not in beta yet).

The issue was that previously we nested `hir::Expr` inside `hir::PatKind::Lit`, so it was linted by the expression code.

So now I've set it up for visitors to be able to directly visit literals and get all literals

jieyouxu added a commit to jieyouxu/rust that referenced this pull request

Feb 5, 2025
…eril

Reject negative literals for unsigned or char types in pattern ranges and literals

It sucks a bit that we have to duplicate the work here (normal expressions just get this for free from the `ExprKind::UnOp(UnOp::Neg, ...)` typeck logic.

In rust-lang#134228 I caused

```rust
fn main() {
    match 42_u8 {
        -10..255 => {},
        _ => {}
    }
}
```

to just compile without even a lint.

I can't believe we didn't have tests for this

Amusingly rust-lang#136302 will also register a delayed bug in `lit_to_const` for this, so we'll have a redundancy if something like this fails again.

jieyouxu added a commit to jieyouxu/rust that referenced this pull request

Feb 5, 2025
…ks, r=compiler-errors

Fix accidentally not emitting overflowing literals lints anymore in patterns

This was regressed in rust-lang#134228 (not in beta yet).

The issue was that previously we nested `hir::Expr` inside `hir::PatKind::Lit`, so it was linted by the expression code.

So now I've set it up for visitors to be able to directly visit literals and get all literals

jieyouxu added a commit to jieyouxu/rust that referenced this pull request

Feb 5, 2025
…eril

Reject negative literals for unsigned or char types in pattern ranges and literals

It sucks a bit that we have to duplicate the work here (normal expressions just get this for free from the `ExprKind::UnOp(UnOp::Neg, ...)` typeck logic.

In rust-lang#134228 I caused

```rust
fn main() {
    match 42_u8 {
        -10..255 => {},
        _ => {}
    }
}
```

to just compile without even a lint.

I can't believe we didn't have tests for this

Amusingly rust-lang#136302 will also register a delayed bug in `lit_to_const` for this, so we'll have a redundancy if something like this fails again.

jieyouxu added a commit to jieyouxu/rust that referenced this pull request

Feb 5, 2025
…ks, r=compiler-errors

Fix accidentally not emitting overflowing literals lints anymore in patterns

This was regressed in rust-lang#134228 (not in beta yet).

The issue was that previously we nested `hir::Expr` inside `hir::PatKind::Lit`, so it was linted by the expression code.

So now I've set it up for visitors to be able to directly visit literals and get all literals

jieyouxu added a commit to jieyouxu/rust that referenced this pull request

Feb 5, 2025
…eril

Reject negative literals for unsigned or char types in pattern ranges and literals

It sucks a bit that we have to duplicate the work here (normal expressions just get this for free from the `ExprKind::UnOp(UnOp::Neg, ...)` typeck logic.

In rust-lang#134228 I caused

```rust
fn main() {
    match 42_u8 {
        -10..255 => {},
        _ => {}
    }
}
```

to just compile without even a lint.

I can't believe we didn't have tests for this

Amusingly rust-lang#136302 will also register a delayed bug in `lit_to_const` for this, so we'll have a redundancy if something like this fails again.

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Feb 6, 2025
Rollup merge of rust-lang#136304 - oli-obk:push-ymxoklvzrpvx, r=Nadrieril

Reject negative literals for unsigned or char types in pattern ranges and literals

It sucks a bit that we have to duplicate the work here (normal expressions just get this for free from the `ExprKind::UnOp(UnOp::Neg, ...)` typeck logic.

In rust-lang#134228 I caused

```rust
fn main() {
    match 42_u8 {
        -10..255 => {},
        _ => {}
    }
}
```

to just compile without even a lint.

I can't believe we didn't have tests for this

Amusingly rust-lang#136302 will also register a delayed bug in `lit_to_const` for this, so we'll have a redundancy if something like this fails again.

workingjubilee added a commit to workingjubilee/rustc that referenced this pull request

Feb 6, 2025
…ks, r=compiler-errors

Fix accidentally not emitting overflowing literals lints anymore in patterns

This was regressed in rust-lang#134228 (not in beta yet).

The issue was that previously we nested `hir::Expr` inside `hir::PatKind::Lit`, so it was linted by the expression code.

So now I've set it up for visitors to be able to directly visit literals and get all literals

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Feb 6, 2025
…ks, r=compiler-errors

Fix accidentally not emitting overflowing literals lints anymore in patterns

This was regressed in rust-lang#134228 (not in beta yet).

The issue was that previously we nested `hir::Expr` inside `hir::PatKind::Lit`, so it was linted by the expression code.

So now I've set it up for visitors to be able to directly visit literals and get all literals

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Feb 6, 2025
Rollup merge of rust-lang#136393 - oli-obk:pattern-type-lit-oflo-checks, r=compiler-errors

Fix accidentally not emitting overflowing literals lints anymore in patterns

This was regressed in rust-lang#134228 (not in beta yet).

The issue was that previously we nested `hir::Expr` inside `hir::PatKind::Lit`, so it was linted by the expression code.

So now I've set it up for visitors to be able to directly visit literals and get all literals

github-actions bot pushed a commit to rust-lang/miri that referenced this pull request

Feb 7, 2025
…piler-errors

Fix accidentally not emitting overflowing literals lints anymore in patterns

This was regressed in rust-lang/rust#134228 (not in beta yet).

The issue was that previously we nested `hir::Expr` inside `hir::PatKind::Lit`, so it was linted by the expression code.

So now I've set it up for visitors to be able to directly visit literals and get all literals

github-actions bot pushed a commit to ytmimi/rustfmt that referenced this pull request

Feb 12, 2025
Only treat plain literal patterns as short

See rust-lang/rust#134228 (comment) and rust-lang/rust#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

Zalathar added a commit to Zalathar/rust that referenced this pull request

Feb 14, 2025
This matches the HIR changes in rust-lang#134228, which introduced `PatExpr` to hold the
subset of "expressions" that can appear in a pattern.

Shourya742 pushed a commit to Shourya742/rust that referenced this pull request

Feb 15, 2025
This matches the HIR changes in rust-lang#134228, which introduced `PatExpr` to hold the
subset of "expressions" that can appear in a pattern.

Shourya742 pushed a commit to Shourya742/rust that referenced this pull request

Feb 15, 2025
This matches the HIR changes in rust-lang#134228, which introduced `PatExpr` to hold the
subset of "expressions" that can appear in a pattern.

flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request

Feb 20, 2025
…piler-errors

Fix accidentally not emitting overflowing literals lints anymore in patterns

This was regressed in rust-lang/rust#134228 (not in beta yet).

The issue was that previously we nested `hir::Expr` inside `hir::PatKind::Lit`, so it was linted by the expression code.

So now I've set it up for visitors to be able to directly visit literals and get all literals