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

Add filtering to rustc_on_unimplemented to avoid misleading suggestion #55000

Open
estebank opened this issue Oct 11, 2018 · 2 comments
Open
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. F-on_unimplemented Error messages that can be tackled with `#[rustc_on_unimplemented]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

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.

@estebank estebank added the A-diagnostics Area: Messages for errors, warnings, and lints label Oct 11, 2018
@JohnTitor JohnTitor added C-enhancement Category: An issue proposing an enhancement or a PR with one. F-on_unimplemented Error messages that can be tackled with `#[rustc_on_unimplemented]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 12, 2020
@fmease
Copy link
Member

fmease commented 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 suggests a[a.len() - 1] when encountering a[-1]?

@estebank
Copy link
Contributor Author

@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).

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. F-on_unimplemented Error messages that can be tackled with `#[rustc_on_unimplemented]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants