Closed
Description
I tried this code https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=374040a5ff329e636d37acd10f828a69:
#![feature(generic_associated_types)]
use either::Either;
pub trait HasChildrenOf {
type T;
type TRef<'a>;
fn ref_children<'a>(&'a self) -> Vec<Self::TRef<'a>>;
fn take_children(self) -> Vec<Self::T>;
}
impl<Left, Right> HasChildrenOf for Either<Left, Right>
where
Left: HasChildrenOf,
Right: HasChildrenOf,
{
type T = Either<Left::T, Right::T>;
type TRef<'a>
where
<Left as HasChildrenOf>::T: 'a,
<Right as HasChildrenOf>::T: 'a
= Either<&'a Left::T, &'a Right::T>;
fn ref_children<'a>(&'a self) -> Vec<Self::TRef<'a>> {
todo!()
}
fn take_children(self) -> Vec<Self::T> {
todo!()
}
}
I expected to see this happen: A slightly better error message
Instead, this happened: A slightly confusing error message
error[E0309]: the associated type `<Left as HasChildrenOf>::T` may not live long enough
--> src/lib.rs:19:5
|
19 | / type TRef<'a>
20 | | where
21 | | <Left as HasChildrenOf>::T: 'a,
22 | | <Right as HasChildrenOf>::T: 'a
23 | | = Either<&'a Left::T, &'a Right::T>;
| |________________________________________^
|
= help: consider adding an explicit lifetime bound `<Left as HasChildrenOf>::T: 'a`...
= note: ...so that the type `<Left as HasChildrenOf>::T` will meet its required lifetime bounds
Meta
rustc --version --verbose
:
rustc 1.55.0-nightly (868c702d0 2021-06-30)
binary: rustc
commit-hash: 868c702d0c9a471a28fb55f0148eb1e3e8b1dcc5
commit-date: 2021-06-30
host: x86_64-pc-windows-gnu
release: 1.55.0-nightly
LLVM version: 12.0.1
Backtrace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment