Skip to content

regression around trait bounds with associated types  #33586

@nikomatsakis

Description

@nikomatsakis
Contributor

The following code works on stable, but not on the latest master. I believe it is valid.

trait ParallelIterator {
    type Item;
    fn drive_unindexed<C>(self, consumer: C) -> C::Result
        where C: Consumer<Self::Item>;
}

pub trait Consumer<ITEM> {
    type Result;
}

pub struct Enumerate<M> {
    base: M,
}

impl<M> ParallelIterator for Enumerate<M>
    where M: ParallelIterator,
{
    type Item = (usize, M::Item);

    fn drive_unindexed<C>(self, consumer: C) -> C::Result
        where C: Consumer<Self::Item>
    {
        panic!()
    }
}

fn main() { }

On master I get:

lunch-box. rustc ~/tmp/reduce.rs
/home/nmatsakis/tmp/reduce.rs:3:5: 4:39 error: the trait bound `C: Consumer<Self>` is not satisfied [E0277]
/home/nmatsakis/tmp/reduce.rs:3     fn drive_unindexed<C>(self, consumer: C) -> C::Result
                                    ^
/home/nmatsakis/tmp/reduce.rs:3:5: 4:39 help: run `rustc --explain E0277` to see a detailed explanation
/home/nmatsakis/tmp/reduce.rs:3:5: 4:39 help: consider adding a `where C: Consumer<Self>` bound
/home/nmatsakis/tmp/reduce.rs:20:5: 24:6 error: the trait bound `C: Consumer<Enumerate<M>>` is not satisfied [E0277]
/home/nmatsakis/tmp/reduce.rs:20     fn drive_unindexed<C>(self, consumer: C) -> C::Result
                                     ^
/home/nmatsakis/tmp/reduce.rs:20:5: 24:6 help: run `rustc --explain E0277` to see a detailed explanation
/home/nmatsakis/tmp/reduce.rs:20:5: 24:6 help: consider adding a `where C: Consumer<Enumerate<M>>` bound
error: aborting due to 2 previous errors

Activity

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on May 12, 2016
nikomatsakis

nikomatsakis commented on May 12, 2016

@nikomatsakis
ContributorAuthor

(This affects the latest Rayon.)

nikomatsakis

nikomatsakis commented on May 12, 2016

@nikomatsakis
ContributorAuthor

Note that the error messages are talking about Consumer<Self>.

nikomatsakis

nikomatsakis commented on May 12, 2016

@nikomatsakis
ContributorAuthor

Really this is enough to show the problem:

trait ParallelIterator {
    type Item;
    fn drive_unindexed<C>(self, consumer: C) -> C::Result
        where C: Consumer<Self::Item>;
}

pub trait Consumer<ITEM> {
    type Result;
}

fn main() { }
nikomatsakis

nikomatsakis commented on May 12, 2016

@nikomatsakis
ContributorAuthor

This DOES compile, which gives a pretty good clue:

trait ParallelIterator {
    type Item;
    fn drive_unindexed<C>(self, consumer: C) -> <C as Consumer<Self::Item>>::Result
        where C: Consumer<Self::Item>;
}

pub trait Consumer<ITEM> {
    type Result;
}

fn main() { }
nikomatsakis

nikomatsakis commented on May 12, 2016

@nikomatsakis
ContributorAuthor

cc @eddyb any PRs that you've seen whih might affect how C::Result is resolved?

metajack

metajack commented on May 12, 2016

@metajack
Contributor

This is blocking a Servo upgrade of rustc currently. We seem to be stuck around 2016-05-07 until this is fixed.

nikomatsakis

nikomatsakis commented on May 12, 2016

@nikomatsakis
ContributorAuthor

Seems likely to be a problem in the resolve refactoring. Basically the Self::Item in Consumer<Self::Item> gets translated to Self.

cc @jseyfried the problem seems to lie in resolve

nikomatsakis

nikomatsakis commented on May 12, 2016

@nikomatsakis
ContributorAuthor

never mind, I think the problem is in astconv

eddyb

eddyb commented on May 12, 2016

@eddyb
Member

Got to love nondescript cleanup commits.
This broke saving the final Def, which was completely hidden by the ast_ty_to_ty_cache, until I removed that recently.
It wasn't a problem with expression paths because those don't use the resulting Def for anything and instead insert their own resolved method or associated constant Def.

alexcrichton

alexcrichton commented on May 12, 2016

@alexcrichton
Member

I've also noticed that this crate fails on the current nightly for presumably similar reasons

added a commit that references this issue on May 13, 2016
709e5c5
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

    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @metajack@alexcrichton@eddyb@nikomatsakis

      Issue actions

        regression around trait bounds with associated types · Issue #33586 · rust-lang/rust