Skip to content

Instantly share code, notes, and snippets.

@scalexm
Last active July 31, 2018 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scalexm/e3e4ecefe970a2df861cc158e50c363c to your computer and use it in GitHub Desktop.
Save scalexm/e3e4ecefe970a2df861cc158e50c363c to your computer and use it in GitHub Desktop.
// chalk does not handle outlive requirements for now, so we say that
// `T: 'a` iff `T: Outlives<'a>`
trait Outlives<'a> { }
struct Slice<'a, T> where T: Outlives<'a> { }
// hack for implied outlive requirements: if you have e.g. `&'a T: 'b` then you must have `T: 'b`
// (see https://play.rust-lang.org/?gist=3e5410767c6d596ed7c5b2686f9f6ba1&version=stable&mode=debug&edition=2015)
impl<'a, 'b, T> Outlives<'b> for T where Slice<'a, T>: Outlives<'b> { }
trait StreamingIterator {
// if you remove the where clause, then chalk won't accept the impl below
type Item<'a> where <Self as StreamingIterator>::Item<'a>: Outlives<'a>;
}
struct Stream<T> { }
impl<T> StreamingIterator for Stream<T> {
type Item<'a> = Slice<'a, T>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment