Skip to content
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

Don't suggest calling .iter() when unsatified Iterator bound does not originate from an expression #50773

Closed
kennytm opened this issue May 15, 2018 · 0 comments · Fixed by #54946
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@kennytm
Copy link
Member

kennytm commented May 15, 2018

Demo:

struct S<I: Iterator>(I);
struct T(S<u8>);
fn main() {}

This will cause the strange suggestion:

error[E0277]: the trait bound `u8: std::iter::Iterator` is not satisfied
 --> src/main.rs:2:10
  |
2 | struct T(S<u8>);
  |          ^^^^^^ `u8` is not an iterator; maybe try calling `.iter()` or a similar method
  |
  = help: the trait `std::iter::Iterator` is not implemented for `u8`
note: required by `S`
 --> src/main.rs:1:1
  |
1 | struct S<I: Iterator>(I);
  | ^^^^^^^^^^^^^^^^^^^^^^^^^

There is no place to "call .iter()". That suggestion should be removed here.

@kennytm kennytm added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints labels May 15, 2018
estebank added a commit to estebank/rust that referenced this issue Oct 10, 2018
 - 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)
bors added a commit that referenced this issue Oct 15, 2018
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)
bors added a commit that referenced this issue Oct 17, 2018
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant