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
fnfoo<'a>(v:&'a[uint],f: |&'auint|){for x in v.iter(){f(x);}}
fnfoo<'a>(v:&'a[uint],f: |&'auint|){for x in v.iter(){let&ref x = x;f(x);}}
This doesn't:
fnfoo<'a>(v:&'a[uint],f: |&'auint|){for&ref x in v.iter(){f(x);}}
error: borrowed value does not live long enough
fnfoo<'a>(v:&'aVec<uint>,f: |&'auint|){for&ref x in v.iter(){f(x);}}
^~~~~~~~
note: reference must be valid for the lifetime 'a as defined on the block...
fn foo<'a>(v:&'a Vec<uint>, f: |&'a uint|){for&ref x in v.iter(){f(x);}}
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: ...but borrowed value is only valid for the block
fn foo<'a>(v:&'a Vec<uint>, f: |&'a uint|){for&ref x in v.iter(){f(x);}}
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The patterns may seem redundant, but while the original code had &(_, ref x), that is not necessary to demonstrate the issue.
The error suggests the lifetime used for x is the lifetime of the v.iter() rvalue, instead of 'a from slice::Items<'a, uint>.
These two work:
This doesn't:
The patterns may seem redundant, but while the original code had
&(_, ref x)
, that is not necessary to demonstrate the issue.The error suggests the lifetime used for
x
is the lifetime of thev.iter()
rvalue, instead of'a
fromslice::Items<'a, uint>
.cc @pcwalton
The text was updated successfully, but these errors were encountered: