-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Suggest using ranges in loops on primitive types, instead of calling .iter() #34353
Comments
That error message is already somewhat special, but it uses a special attribute on the trait itself. This would require actually special-casing Iterator in this case, and I'm not sure how useful that would be for the effort. I'm skeptical that this kind of thing is 1) particularly common and 2) something that somebody would deliberately do. What I mean by that second point is that there's a difference between doing |
@Aatch These are valid points. I agree that if not trivial to implement, it doesn't make sense given this is probably a rare occurrence. Mainly I was thinking the easiest could be expanding the already existing hint (hard-coded string?) to perhaps be |
Once #47613 gets merged, this can be trivially added. |
- Detect one element array of `Range` type, which is potentially a typo: `for _ in [0..10] {}` where iterating between `0` and `10` was intended. (rust-lang#23141) - Suggest `.bytes()` and `.chars()` for `String`. - Suggest borrowing or `.iter()` on arrays (rust-lang#36391) - Suggest using range literal when iterating on integers (rust-lang#34353) - Do not suggest `.iter()` by default (rust-lang#50773, rust-lang#46806)
Add filtering option to `rustc_on_unimplemented` and reword `Iterator` E0277 errors - Add more targetting filters for arrays to `rustc_on_unimplemented` (Fix #53766) - Detect one element array of `Range` type, which is potentially a typo: `for _ in [0..10] {}` where iterating between `0` and `10` was intended. (Fix #23141) - Suggest `.bytes()` and `.chars()` for `String`. - Suggest borrowing or `.iter()` on arrays (Fix #36391) - Suggest using range literal when iterating on integers (Fix #34353) - Do not suggest `.iter()` by default (Fix #50773, fix #46806) - Add regression test (Fix #22872)
Add filtering option to `rustc_on_unimplemented` and reword `Iterator` E0277 errors - Add more targetting filters for arrays to `rustc_on_unimplemented` (Fix #53766) - Detect one element array of `Range` type, which is potentially a typo: `for _ in [0..10] {}` where iterating between `0` and `10` was intended. (Fix #23141) - Suggest `.bytes()` and `.chars()` for `String`. - Suggest borrowing or `.iter()` on arrays (Fix #36391) - Suggest using range literal when iterating on integers (Fix #34353) - Do not suggest `.iter()` by default (Fix #50773, fix #46806) - Add regression test (Fix #22872)
The following code results in output that isn't specifically helpful:
Compiler output:
Primitive types do not [currently] implement
Iterator
. Perhaps the output could see the type is primitive and suggest to create a type that implementsIterator
, such as a range with0..max
?Meta
The text was updated successfully, but these errors were encountered: