Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typechecking failure with HRTBs and associated types #68862

Closed
arpj-rebola opened this issue Feb 5, 2020 · 1 comment
Closed

Typechecking failure with HRTBs and associated types #68862

arpj-rebola opened this issue Feb 5, 2020 · 1 comment

Comments

@arpj-rebola
Copy link

Rust fails to typecheck the following code:

trait Aaa: Sized where
	for<'a> &'a Self: AaaLt<'a, Self>
{}

trait AaaLt<'a, A: Aaa> where
	for<'b> &'b A: AaaLt<'b, A>
{
	type View;
}

trait AaaPlus: Aaa where
	for<'a> &'a Self: AaaLt<'a, Self>,
	for<'a> <&'a Self as AaaLt<'a, Self>>::View: Bbb
{}

trait Bbb {
}

struct Foo<'a> {
	x: &'a usize
}
impl<'a> Bbb for Foo<'a> {
}

struct Bar {
}
impl Aaa for Bar {
}
impl<'a> AaaLt<'a, Bar> for &'a Bar {
	type View = Foo<'a>;
}
impl AaaPlus for Bar {
}

with error: the trait bound for<'a> <&'a dirty::Bar as dirty::AaaLt<'a, dirty::Bar>>::View: dirty::Bbb is not satisfied.

What I am trying to do is the following. I want to have a marker trait Aaa that defines some associated types. One of those associated types View have lifetime parameters. But generic associated types are not currently allowed in stable Rust, so I define them as types associated to a lifetime-parameterized trait that every reference must satisfy; I use a higher-rank trait bound for this purpose.

For a specialization of the trait Aaa called AaaPlus, (each instantiation of) the type View must satisfy some other trait Bbb. Despite the corresponding traits being implemented for Bar: AaaPlus and Foo<'a>: Bbb, Rust is failing to typecheck this.

@jonas-schievink
Copy link
Contributor

Yeah this is a known issue with HRTB projections, covered by older issues like #30472, so closing in favor of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants