-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Suggest struct pattern when destructuring Range with .. syntax #149952
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
base: main
Are you sure you want to change the base?
Suggest struct pattern when destructuring Range with .. syntax #149952
Conversation
|
r? @Alexendoo |
|
I'm not part of the compiler team so I'll pass it back over to r? @lcnr |
| 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), |
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.
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", |
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.
Nit:
| "if you meant to destructure a `Range`, use the struct pattern", | |
| "if you meant to destructure a `Range`, use a struct pattern", |
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