You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<anon>:4:1: 6:2 error: in type `&'a Bar<'b>`, reference has a longer lifetime than the data it references
<anon>:4 struct Foo<'a, 'b> {
<anon>:5 _field: &'a Bar<'b>
<anon>:6 }
<anon>:4:1: 6:2 note: the pointer is valid for the lifetime 'a as defined on the struct at 4:0
<anon>:4 struct Foo<'a, 'b> {
<anon>:5 _field: &'a Bar<'b>
<anon>:6 }
<anon>:4:1: 6:2 note: but the referenced data is only valid for the lifetime 'b as defined on the struct at 4:0
<anon>:4 struct Foo<'a, 'b> {
<anon>:5 _field: &'a Bar<'b>
<anon>:6 }
error: aborting due to previous error
playpen: application terminated with error code 101
Program ended.
Despite the lifetimes of 'a and 'b not having been bound yet.
This is happens using rustc 0.12.0-pre (23c1f9b3c 2014-08-30 21:51:25 +0000).
The text was updated successfully, but these errors were encountered:
I don't think this is a bug. The only way for the &'a Bar<'b> pointer to be valid is if the 'b lifetime is at least as long as the 'a one (if it wasn't, you would have a pointer apparently valid for 'a pointing to data only valid for shorter lifetime). The correct fix is to tell the compiler that 'b is at least as long as 'a:
The following code:
Playpen: http://is.gd/oPQAxE
Gives the errors:
Despite the lifetimes of
'a
and'b
not having been bound yet.This is happens using
rustc 0.12.0-pre (23c1f9b3c 2014-08-30 21:51:25 +0000)
.The text was updated successfully, but these errors were encountered: