-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Mismatched assumptions for interaction between associated type and lifetime in trait #24622
Comments
triage: P-high |
petgraph uses this kind of trait to provide generic "neighbor vertex" iterators. |
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 |
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. |
triage: P-high |
Just FYI -- I've been working steadily on this. I'm going to try and writeup my thoughts "soon" (famous last words). |
object types impose minimal constraints on their arguments. Also modify regionck to consider `<P0 as TraitRef<P1..Pn>>::Foo: 'r` to hold if `Pi: 'r` (for all `i`). This is a fallback, because in some cases we can impose looser requirements. Currently the inference is sound but not precise. Fixes rust-lang#24622. Adapted cherry-pick of 45f93290969f19d8217a2e4dff7b12dc81957eb6.
object types impose minimal constraints on their arguments. Also modify regionck to consider `<P0 as TraitRef<P1..Pn>>::Foo: 'r` to hold if `Pi: 'r` (for all `i`). This is a fallback, because in some cases we can impose looser requirements. Currently the inference is sound but not precise. Fixes rust-lang#24622. Adapted cherry-pick of 45f93290969f19d8217a2e4dff7b12dc81957eb6.
object types impose minimal constraints on their arguments. Also modify regionck to consider `<P0 as TraitRef<P1..Pn>>::Foo: 'r` to hold if `Pi: 'r` (for all `i`). This is a fallback, because in some cases we can impose looser requirements. Currently the inference is sound but not precise. Fixes rust-lang#24622. Adapted cherry-pick of 45f93290969f19d8217a2e4dff7b12dc81957eb6.
object types impose minimal constraints on their arguments. Also modify regionck to consider `<P0 as TraitRef<P1..Pn>>::Foo: 'r` to hold if `Pi: 'r` (for all `i`). This is a fallback, because in some cases we can impose looser requirements. Currently the inference is sound but not precise. Fixes rust-lang#24622. Adapted cherry-pick of 45f93290969f19d8217a2e4dff7b12dc81957eb6.
This original example is now giving me an error on stable: http://is.gd/bidora The question is, did we add a test? |
The test associated-types-outlives.rs claims to be a regression test for this issue. Closing! |
This segfaults.
The
impl
is allowing&'a String
because'a
is in scope, but the use infoo
assumes thatBar
is independent of'a
.(Noticed in http://stackoverflow.com/q/29745134/1256624 .)
The text was updated successfully, but these errors were encountered: