Skip to content

Conversation

@Delta17920
Copy link
Contributor

@Delta17920 Delta17920 commented Dec 13, 2025

implemented a new diagnostic in rustc_resolve to detect invalid range destructuring attempts (e.g., let start..end = range). The fix identifies when resolution fails for identifiers acting as range bounds specifically handling cases where bounds are parsed as expressions and suggests the correct struct pattern syntax (std::ops::Range { start, end }). This replaces confusing "cannot find value" errors with actionable help, verified by a new UI test covering various identifier names.

Fixes #149777

@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. labels Dec 13, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 13, 2025

r? @lcnr

rustbot has assigned @lcnr.
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

@Delta17920
Copy link
Contributor Author

r? @Alexendoo

@rustbot rustbot assigned Alexendoo and unassigned lcnr Dec 13, 2025
@Alexendoo
Copy link
Member

I'm not part of the compiler team so I'll pass it back over to r? @lcnr

@rustbot rustbot assigned lcnr and unassigned Alexendoo Dec 13, 2025
err.span_suggestion_verbose(
pat.span,
"if you meant to destructure a `Range`, use the struct pattern",
format!("std::ops::Range {{ start: {}, end: {} }}", start_name, end_name),
Copy link
Contributor

@PatchMixolydic PatchMixolydic Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be helpful if this suggested std::range::Range/core::range::Range when #![feature(new_range)] is enabled (might not be necessary since new_range is still unstable).


err.span_suggestion_verbose(
pat.span,
"if you meant to destructure a `Range`, use the struct pattern",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
"if you meant to destructure a `Range`, use the struct pattern",
"if you meant to destructure a `Range`, use a struct pattern",

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggest struct destructuring when attempting to destructure using range syntax

5 participants