Closed
Description
This program fails to compile:
#![crate_type="rlib"]
use std::marker::PhantomData;
pub struct UnionedKeys<'a,K>
where K: UnifyKey + 'a
{
table: &'a mut UnificationTable<K>,
root_key: K,
stack: Vec<K>,
}
pub trait UnifyKey {
type Value;
}
pub struct UnificationTable<K:UnifyKey> {
values: Delegate<K>,
}
pub struct Delegate<K>(PhantomData<K>);
This was supposed to be fixed by #22436, but apparently that fix is not working. I've been wanting to revisit the strategy there anyway, because it leads to infinite recursion in some cases and I'm not happy about it.
The error I see is:
/home/nmatsakis/tmp/bar.rs:5:1: 11:2 error: the associated type `<K as UnifyKey>::Value` may not live long enough [E0309]
/home/nmatsakis/tmp/bar.rs:5 pub struct UnionedKeys<'a,K>
/home/nmatsakis/tmp/bar.rs:6 where K: UnifyKey + 'a
/home/nmatsakis/tmp/bar.rs:7 {
/home/nmatsakis/tmp/bar.rs:8 table: &'a mut UnificationTable<K>,
/home/nmatsakis/tmp/bar.rs:9 root_key: K,
/home/nmatsakis/tmp/bar.rs:10 stack: Vec<K>,
...
/home/nmatsakis/tmp/bar.rs:11:2: 11:2 help: consider adding an explicit lifetime bound `<K as UnifyKey>::Value: 'a`...
/home/nmatsakis/tmp/bar.rs:5:1: 11:2 note: ...so that the reference type `&'a mut UnificationTable<K>` does not outlive the data it points at
/home/nmatsakis/tmp/bar.rs:5 pub struct UnionedKeys<'a,K>
/home/nmatsakis/tmp/bar.rs:6 where K: UnifyKey + 'a
/home/nmatsakis/tmp/bar.rs:7 {
/home/nmatsakis/tmp/bar.rs:8 table: &'a mut UnificationTable<K>,
/home/nmatsakis/tmp/bar.rs:9 root_key: K,
/home/nmatsakis/tmp/bar.rs:10 stack: Vec<K>,
...