Skip to content

Program with HRTB rejected with inexplicable error message #50301

Closed

Description

@ytausky

(Sorry about the non-informative title, I couldn't come up with a useful description.)

As discovered towards the end of this forum thread, the following code (playground) fails to compile:

trait Trait
where
    for<'a> &'a Self::IntoIter: IntoIterator<Item = u32>,
{
    type IntoIter;
    fn get(&self) -> Self::IntoIter;
}

struct Impl(Vec<u32>);

impl Trait for Impl {
    type IntoIter = ImplIntoIter;
    fn get(&self) -> Self::IntoIter {
        ImplIntoIter(self.0.clone())
    }
}

struct ImplIntoIter(Vec<u32>);

impl<'a> IntoIterator for &'a ImplIntoIter {
    type Item = <Self::IntoIter as Iterator>::Item;
    type IntoIter = std::iter::Cloned<std::slice::Iter<'a, u32>>;
    fn into_iter(self) -> Self::IntoIter {
        (&self.0).into_iter().cloned()
    }
}

I get the following error message:

error[E0271]: type mismatch resolving `for<'a> <std::slice::Iter<'a, u32> as std::iter::Iterator>::Item == &u32`
  --> src/lib.rs:13:6
   |
13 | impl Trait for Impl {
   |      ^^^^^ expected bound lifetime parameter 'a, found concrete lifetime
   |
   = note: required because of the requirements on the impl of `std::iter::Iterator` for `std::iter::Cloned<std::slice::Iter<'_, u32>>`

Changing the definition of Item to u32 makes the program compile, but it seems like it should be accepted as it is.

Activity

  1. added
    T-lang
    A-inference
    C-bug
    on Oct 2, 2018
  2. jakubadamw commented on Aug 8, 2019

    @jakubadamw
    Contributor

    This program is no longer rejected, neither in 1.36, nor in nightly-2019-08-07.

  3. jakubadamw commented on Aug 10, 2019

    @jakubadamw
    Contributor

    @rustbot modify labels: E-needstest

  4. added
    E-needs-test
    on Aug 10, 2019
  5. added 3 commits that reference this issue on Aug 15, 2019
    2faf7f9
    8576227
    77f2694
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-inferenceC-bugE-needs-testT-lang

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions