0

I understand why a reference passed to a function must come with minimal required lifetime: to be sure that object behind is not destroyed while function is still operating. What puzzles me is the following:

fn a_function<'a, 'b, T>(arg: &'b T)
where
    T: 'a,
{
    // ...
}

The only reference that comes into the function has the lifetime 'b.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
user3284063
  • 665
  • 5
  • 20
  • 2
    I'm pretty sure it's already been answered but I cannot put my hand on it. – Matthieu M. Oct 10 '17 at 17:19
  • The question, which you have deleted, would be: what does exactly "T: 'a" mean? – user3284063 Oct 10 '17 at 17:25
  • From the linked duplicate: *What `T: 'a` is saying is that any references in `T` must outlive `'a`.*. – Shepmaster Oct 10 '17 at 17:25
  • @user3284063 not *deleted* — moved the the questions title; where it belongs. – Shepmaster Oct 10 '17 at 17:25
  • And the answer to the implicit question about this particular function is that *this specific bound* is apparently meaningless. – Shepmaster Oct 10 '17 at 17:27
  • I disagree with the premise that "a reference [...] must come with minimal required lifetime *to be sure that object behind is not destroyed while function is still operating*". References come with lifetimes so the *caller* can be sure that the called function doesn't do something that would be illegal *for the caller to do* (e.g., storing a short-lived reference into a long-lived data structure, as in the first linked duplicate). – trent Oct 10 '17 at 19:19

0 Answers0