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

Catch Javascript style "rest patterns" #120591

Closed
camsteffen opened this issue Feb 2, 2024 · 0 comments · Fixed by #120597
Closed

Catch Javascript style "rest patterns" #120591

camsteffen opened this issue Feb 2, 2024 · 0 comments · Fixed by #120597
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name resolution T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@camsteffen
Copy link
Contributor

Code

fn test() {
    match [] {
        [] => {}
        [head, ..tail] => {}
    }
}

Current output

error[E0425]: cannot find value `tail` in this scope
 --> src/lib.rs:4:18
  |
4 |         [head, ..tail] => {}
  |                  ^^^^ not found in this scope

error[E0658]: exclusive range pattern syntax is experimental
 --> src/lib.rs:4:16
  |
4 |         [head, ..tail] => {}
  |                ^^^^^^
  |
  = note: see issue #37854 <https://github.com/rust-lang/rust/issues/37854> for more information

error[E0527]: pattern requires 2 elements but array has 0
 --> src/lib.rs:4:9
  |
4 |         [head, ..tail] => {}
  |         ^^^^^^^^^^^^^^ expected 0 elements

Some errors have detailed explanations: E0425, E0527, E0658.
For more information about an error, try `rustc --explain E0425`.

Desired output

Did you mean to bind `tail` to the rest of the elements?

    [head, tail @ ..] => {}

Rationale and extra context

No response

Other cases

It could work with either two or three dots.

Rust Version

rustc 1.77.0-nightly (89e2160c4 2023-12-27)
binary: rustc
commit-hash: 89e2160c4ca5808657ed55392620ed1dbbce78d1
commit-date: 2023-12-27
host: x86_64-apple-darwin
release: 1.77.0-nightly
LLVM version: 17.0.6

Anything else?

No response

@camsteffen camsteffen added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 2, 2024
@fmease fmease self-assigned this Feb 2, 2024
@fmease fmease added the A-resolve Area: Name resolution label Feb 2, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 6, 2024
…in-pat, r=estebank

Suggest `[tail @ ..]` on `[..tail]` and `[...tail]` where `tail` is unresolved

Fixes rust-lang#120591.
~~Will conflict with rust-lang#120570~~ (rebased).

r? estebank or compiler
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 6, 2024
…in-pat, r=estebank

Suggest `[tail @ ..]` on `[..tail]` and `[...tail]` where `tail` is unresolved

Fixes rust-lang#120591.
~~Will conflict with rust-lang#120570~~ (rebased).

r? estebank or compiler
@bors bors closed this as completed in 89aa85d Feb 6, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 6, 2024
Rollup merge of rust-lang#120597 - fmease:sugg-on-js-style-spread-op-in-pat, r=estebank

Suggest `[tail @ ..]` on `[..tail]` and `[...tail]` where `tail` is unresolved

Fixes rust-lang#120591.
~~Will conflict with rust-lang#120570~~ (rebased).

r? estebank or compiler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name resolution T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants