generic-associated-types

Generic associated type may not live long enough

心已入冬 提交于 2021-01-28 13:50:44
问题 Take the following example (Playground): #![feature(generic_associated_types)] #![allow(incomplete_features)] trait Produce { type CustomError<'a>; fn produce<'a>(&'a self) -> Result<(), Self::CustomError<'a>>; } struct GenericProduce<T> { val: T, } struct GenericError<'a, T> { producer: &'a T, } impl<T> Produce for GenericProduce<T> { type CustomError<'a> = GenericError<'a, T>; fn produce<'a>(&'a self) -> Result<(), Self::CustomError<'a>> { Err(GenericError{producer: &self.val}) } } The

Generic associated type may not live long enough

喜欢而已 提交于 2021-01-28 13:39:07
问题 Take the following example (Playground): #![feature(generic_associated_types)] #![allow(incomplete_features)] trait Produce { type CustomError<'a>; fn produce<'a>(&'a self) -> Result<(), Self::CustomError<'a>>; } struct GenericProduce<T> { val: T, } struct GenericError<'a, T> { producer: &'a T, } impl<T> Produce for GenericProduce<T> { type CustomError<'a> = GenericError<'a, T>; fn produce<'a>(&'a self) -> Result<(), Self::CustomError<'a>> { Err(GenericError{producer: &self.val}) } } The