Skip to content

Add filtering to rustc_on_unimplemented to avoid misleading suggestion #55000

@estebank

Description

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

Activity

added
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
F-on_unimplementedError messages that can be tackled with `#[rustc_on_unimplemented]`
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Apr 12, 2020
fmease

fmease commented on Oct 19, 2022

@fmease
Member

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

estebank commented on Oct 19, 2022

@estebank
ContributorAuthor

@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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.F-on_unimplementedError messages that can be tackled with `#[rustc_on_unimplemented]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @estebank@fmease@JohnTitor

        Issue actions

          Add filtering to `rustc_on_unimplemented` to avoid misleading suggestion · Issue #55000 · rust-lang/rust