Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
trait Stack {
type Next;
}
// This compiles
fn push<S: Stack>(state: S, val: int) -> S::Next {
panic!()
}
// This doesn't compile, surprising that rustc doesn't know S has assoc type Next
fn push<S>(state: S, val: int) -> S::Next where S: Stack {
panic!()
}
// This compiles. Surprising the explictness is req
fn push<S>(state: S, val: int) -> <S as Stack>::Next where S: Stack {
panic!()
}
// This compiles, allowed redundancy is surprising
fn push<S: Stack>(state: S, val: int) -> S::Next where S: Stack {
panic!()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment