Skip to content

Bounds on associated types of super-traits not propagated #44656

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

Closed
gnzlbg opened this issue Sep 17, 2017 · 4 comments
Closed

Bounds on associated types of super-traits not propagated #44656

gnzlbg opened this issue Sep 17, 2017 · 4 comments

Comments

@gnzlbg
Copy link
Contributor

gnzlbg commented Sep 17, 2017

MWE on the playground:

pub trait WithAssoc {
  type Assoc;
  fn wa(&self) {}
}

pub trait Baz {}

pub trait Moo: WithAssoc
  where Self::Assoc: Baz // this is allowed
{}

pub trait Foo: Moo
// where Self::Assoc: Baz // but bound is not propagated
{
  fn foo(&self) {
    self.wa();
  }
}

fn main() {}
@gnzlbg gnzlbg closed this as completed Sep 17, 2017
@arielb1
Copy link
Contributor

arielb1 commented Sep 17, 2017

duplicate of #20671

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Sep 17, 2017

@arielb1 I want to write a trait like this:

pub trait Point: std::ops::Index<usize> where Self::Output: Float {};

but if I do that I need to repeat that where clause everywhere where I use the trait.

If I could write my own index trait I would just do:

pub trait Index<T> {
  type Output: Float;
  fn index...
}

and then I can just require that and never have to write the bound. Is there a way to add that bound externally so that I don't have to repeat it everywhere?

@arielb1
Copy link
Contributor

arielb1 commented Sep 17, 2017

and then I can just require that and never have to write the bound. Is there a way to add that bound externally so that I don't have to repeat it everywhere?

Not that I know of. The implied bounds RFC might improve the situation in the future - got to talk about that with @nikomatsakis .

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Sep 17, 2017

The following works:

pub trait Point
  : std::ops::Index<usize, Output = <Self as Point>::Output> {
     type Output: Float;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants