Skip to content

Suggest struct destructuring when attempting to destructure using range syntax #149777

@Alexendoo

Description

@Alexendoo

Code

use std::ops::Range;

fn f(r: Range<u32>) {
    let start..end = r;
}

Current output

error[E0425]: cannot find value `start` in this scope
 --> src/lib.rs:4:9
  |
4 |     let start..end = r;
  |         ^^^^^ not found in this scope

error[E0425]: cannot find value `end` in this scope
 --> src/lib.rs:4:16
  |
4 |     let start..end = r;
  |                ^^^ not found in this scope

Desired output

A suggestion for `let Range { start, end } = r`

Rationale and extra context

I had a Range and attempted to destructure it using a..b as if it were a shorthand for the struct pattern, forgetting about ranges being special patterns already

Other cases

Rust Version

1.91.1

Anything else?

Not sure how common of a mistake this is to make

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions