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

Program with HRTB rejected with inexplicable error message #50301

Closed
ytausky opened this issue Apr 28, 2018 · 2 comments · Fixed by #63577
Closed

Program with HRTB rejected with inexplicable error message #50301

ytausky opened this issue Apr 28, 2018 · 2 comments · Fixed by #63577
Labels
A-inference Area: Type inference C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@ytausky
Copy link
Contributor

ytausky commented Apr 28, 2018

(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.

@XAMPPRocky XAMPPRocky added T-lang Relevant to the language team, which will review and decide on the PR/issue. A-inference Area: Type inference C-bug Category: This is a bug. labels Oct 2, 2018
@jakubadamw
Copy link
Contributor

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

@jakubadamw
Copy link
Contributor

@rustbot modify labels: E-needstest

@rustbot rustbot added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Aug 10, 2019
Centril added a commit to Centril/rust that referenced this issue Aug 15, 2019
Test HRTB issue accepted by compiler

Hi! First Rust PR, so if anything needs changing just let me know and I'll take care of it right away.

Closes rust-lang#50301 which was marked E-needstest
Centril added a commit to Centril/rust that referenced this issue Aug 15, 2019
Test HRTB issue accepted by compiler

Hi! First Rust PR, so if anything needs changing just let me know and I'll take care of it right away.

Closes rust-lang#50301 which was marked E-needstest
Centril added a commit to Centril/rust that referenced this issue Aug 15, 2019
Test HRTB issue accepted by compiler

Hi! First Rust PR, so if anything needs changing just let me know and I'll take care of it right away.

Closes rust-lang#50301 which was marked E-needstest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inference Area: Type inference C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants