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

Help is suggesting to use __iterator_get_unchecked #107983

Closed
MultisampledNight opened this issue Feb 13, 2023 · 1 comment · Fixed by #108049
Closed

Help is suggesting to use __iterator_get_unchecked #107983

MultisampledNight opened this issue Feb 13, 2023 · 1 comment · Fixed by #108049
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@MultisampledNight
Copy link
Contributor

MultisampledNight commented Feb 13, 2023

Code

fn i_can_has_iterator() -> impl Iterator<Item = u32> {
    Box::new(1..=10) as Box<dyn Iterator>
}

Current output

Compiling iterconfusion v0.1.0 (/irrelevant/iterconfusion)
error[E0191]: the value of the associated type `Item` (from trait `Iterator`) must be specified
 --> src/lib.rs:2:33
  |
2 |     Box::new(1..=10) as Box<dyn Iterator>
  |                                 ^^^^^^^^ help: specify the associated type: `Iterator<Item = Type>`

error[E0271]: expected `Box<dyn Iterator>` to be an iterator that yields `u32`, but it yields `<dyn Iterator as Iterator>::Item`
    --> src/lib.rs:1:28
     |
1    | fn i_can_has_iterator() -> impl Iterator<Item = u32> {
     |                            ^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found `u32`
2    |     Box::new(1..=10) as Box<dyn Iterator>
     |     ------------------------------------- return type was inferred to be `Box<dyn Iterator>` here
     |
     = note: expected associated type `<dyn Iterator as Iterator>::Item`
                           found type `u32`
help: a method is available that returns `<dyn Iterator as Iterator>::Item`
    --> /home/multisn8/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:3852:5
     |
3852 | /     unsafe fn __iterator_get_unchecked(&mut self, _idx: usize) -> Self::Item
3853 | |     where
3854 | |         Self: TrustedRandomAccessNoCoerce,
     | |__________________________________________^ consider calling `__iterator_get_unchecked`

Some errors have detailed explanations: E0191, E0271.
For more information about an error, try `rustc --explain E0191`.
error: could not compile `iterconfusion` due to 2 previous errors

Desired output

error[E0191]: the value of the associated type `Item` (from trait `Iterator`) must be specified
 --> src/lib.rs:2:33
  |
2 |     Box::new(1..=10) as Box<dyn Iterator>
  |                                 ^^^^^^^^ help: specify the associated type: `Iterator<Item = Type>`
help: likely you want this to match the output type, `Iterator<Item = u32>`
 --> src/lib.rs:2:40
  |
2 |     Box::new(1..=10) as Box<dyn Iterator<Item = u32>>
  |                                         ++++++++++++

Rationale and extra context

I don't think I as an outside user of stdlib should be confronted with using internal unsafe APIs such as __iterator_get_unchecked.

Other cases

No response

Anything else?

rustc -V: rustc 1.69.0-nightly (5b8f28453 2023-02-12)

@MultisampledNight MultisampledNight added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 13, 2023
@mejrs
Copy link
Contributor

mejrs commented Feb 13, 2023

This seems like a prime use case for #51992

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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants