Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upMismatched assumptions for interaction between associated type and lifetime in trait #24622
Comments
huonw
added
I-wrong
A-lifetimes
A-traits
A-associated-items
labels
Apr 20, 2015
This comment has been minimized.
This comment has been minimized.
|
triage: P-high |
rust-highfive
added
the
P-medium
label
Apr 20, 2015
This comment has been minimized.
This comment has been minimized.
|
petgraph uses this kind of trait to provide generic "neighbor vertex" iterators. |
This comment has been minimized.
This comment has been minimized.
|
I think a cleaner example is: pub trait Foo<'a> {
type Bar;
}
impl<'a, T> Foo<'a> for T { type Bar = &'a T; }
fn denormalise<'a, T>(t: &'a T) -> <T as Foo<'a>>::Bar {
t
}
pub fn free_and_use<T: for<'a> Foo<'a>,
F: for<'a> FnOnce(<T as Foo<'a>>::Bar)>(x: T, f: F) {
let y;
'body: loop { // lifetime annotations added for clarity
's: loop { y = denormalise(&x); break }
drop(x);
return f(y);
}
}
pub fn main() {
free_and_use("foo".to_string(), |s| println!("{}", s));
}It is clear here that the declaration and implementation of |
This comment has been minimized.
This comment has been minimized.
|
Yes, I see the problem. It lies in some of the logic around type parameter outlives rules -- we assume type parameters outlive the current fn, and we assume the same of projections, which is clearly wrong. I've been wanting to revisit these rules about projections and how long they live (#23442) though not for soundness reasons. |
This comment has been minimized.
This comment has been minimized.
|
triage: P-high |
rust-highfive
added
P-high
and removed
P-medium
labels
Apr 24, 2015
nikomatsakis
self-assigned this
Apr 24, 2015
This comment has been minimized.
This comment has been minimized.
|
Just FYI -- I've been working steadily on this. I'm going to try and writeup my thoughts "soon" (famous last words). |
brson
added
the
T-lang
label
Jun 5, 2015
nikomatsakis
added a commit
to nikomatsakis/rust
that referenced
this issue
Jun 8, 2015
nikomatsakis
added a commit
to nikomatsakis/rust
that referenced
this issue
Jun 9, 2015
nikomatsakis
added a commit
to nikomatsakis/rust
that referenced
this issue
Jul 6, 2015
nikomatsakis
added a commit
to nikomatsakis/rust
that referenced
this issue
Jul 13, 2015
nikomatsakis
added a commit
to nikomatsakis/rust
that referenced
this issue
Jul 13, 2015
nikomatsakis
added a commit
to nikomatsakis/rust
that referenced
this issue
Jul 14, 2015
nikomatsakis
added a commit
to nikomatsakis/rust
that referenced
this issue
Jul 14, 2015
Ryman
referenced this issue
Jul 17, 2015
Merged
[RFC] Clarify (and improve) rules for projections and well-formedness #1214
nikomatsakis
added a commit
to nikomatsakis/rust
that referenced
this issue
Jul 25, 2015
nikomatsakis
added a commit
to nikomatsakis/rust
that referenced
this issue
Jul 25, 2015
nikomatsakis
added a commit
to nikomatsakis/rust
that referenced
this issue
Jul 28, 2015
nikomatsakis
added a commit
to nikomatsakis/rust
that referenced
this issue
Jul 28, 2015
nikomatsakis
added a commit
to nikomatsakis/rust
that referenced
this issue
Aug 1, 2015
nikomatsakis
added a commit
to nikomatsakis/rust
that referenced
this issue
Aug 4, 2015
nikomatsakis
added a commit
to nikomatsakis/rust
that referenced
this issue
Aug 5, 2015
nikomatsakis
referenced this issue
Aug 7, 2015
Open
Projections, lifetimes, and WF tracking issue (RFC 1214) #27579
This comment has been minimized.
This comment has been minimized.
|
This original example is now giving me an error on stable: http://is.gd/bidora The question is, did we add a test? |
This comment has been minimized.
This comment has been minimized.
|
The test associated-types-outlives.rs claims to be a regression test for this issue. Closing! |
huonw commentedApr 20, 2015
This segfaults.
The
implis allowing&'a Stringbecause'ais in scope, but the use infooassumes thatBaris independent of'a.(Noticed in http://stackoverflow.com/q/29745134/1256624 .)