-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.F-on_unimplementedError messages that can be tackled with `#[rustc_on_unimplemented]`Error messages that can be tackled with `#[rustc_on_unimplemented]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
After #54946, the code let x = [0..10]; for _ in x {}
will cause the following output:
error[E0277]: `[std::ops::Range<{integer}>; 1]` is not an iterator
--> $DIR/array-of-ranges.rs:11:14
|
LL | for _ in array_of_range {}
| ^^^^^^^^^^^^^^ if you meant to iterate between two values, remove the square brackets
|
= help: the trait `std::iter::Iterator` is not implemented for `[std::ops::Range<{integer}>; 1]`
= note: `[start..end]` is an array of one `Range`; you might have meant to have a `Range` without the brackets: `start..end`
= note: required by `std::iter::IntoIterator::into_iter`
Add a way to identify this case to rustc_on_unimplemented
, in order to avoid giving this misleading/incorrect diagnostic.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.F-on_unimplementedError messages that can be tackled with `#[rustc_on_unimplemented]`Error messages that can be tackled with `#[rustc_on_unimplemented]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
fmease commentedon Oct 19, 2022
Can't the concrete issue regarding
[a..b]
be fixed by replacing the#[rustc_on_unimplemented]
“rule” with a syntactic check in the compiler similar to the logic you implemented in #89251 that suggestsa[a.len() - 1]
when encounteringa[-1]
?estebank commentedon Oct 19, 2022
@fmease yes, it could be by maybe introducing a new error code or do some special handling of E0277 like we already do for other things, I just have a desire to try to reduce the amount of probing code that we have to implement, and potentially get as "declarative" as possible, but we can indeed do that. The amount of code to get rustc_on_unimplemented to differentiate this and to implement custom handling might be around the same (unless caught earlier).