Skip to content

Instantly share code, notes, and snippets.

@TimNN

TimNN/exp.rs Secret

Last active September 10, 2016 09:33
Show Gist options
  • Save TimNN/a8f9885c2bfd585dd8af9b6973cfd219 to your computer and use it in GitHub Desktop.
Save TimNN/a8f9885c2bfd585dd8af9b6973cfd219 to your computer and use it in GitHub Desktop.
//! Annotated Version:
//! Lines starting with REQ: state requirements as far as I can figure
//! ie. the ICE does not occur if the requirement is not fulfilled
// REQ: trait with an assoc. ty
trait MappingTrait {
type MappedAssocTy;
}
struct MappedImpl;
// REQ: impl mapping reference to reference
impl<'c> MappingTrait for &'c MappedImpl {
type MappedAssocTy = &'c u8;
}
// REQ: two assoc. tys
trait RootTrait {
type AssocTy1;
type AssocTy2;
}
struct EmptyRoot;
impl RootTrait for EmptyRoot {
// REQ: implementation of mapping trait
type AssocTy1 = MappedImpl;
type AssocTy2 = u16;
}
// REQ: use of each assoc. ty
struct RootWrapper<R: RootTrait> {
_field1: R::AssocTy1,
_field2: R::AssocTy2,
}
// REQ: where clause with references
impl<R: RootTrait> RootTrait for RootWrapper<R> where
for<'d> &'d R::AssocTy1: MappingTrait<MappedAssocTy = &'d u8> {
type AssocTy1 = u32;
type AssocTy2 = u64;
}
// REQ: the failing type in argument position
// NB.: in later rust version, a variable of the failing type is enough
fn root_consumer<R>(_: R) {}
fn main() {
// REQ: two nested wrappers
root_consumer::<RootWrapper<RootWrapper<EmptyRoot>>>(unsafe { ::std::mem::zeroed() });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment