Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Would output along the following lines be an improvement?

   error[E0597]: `buffer` does not live long enough
   --> src/main.rs:63:21
      |
   59 |     let report = {
      |         ------ borrow later stored here
   60 |         let mut buffer = Vec::new();
      |             ---------- binding `buffer` declared here
   61 |         let ctx = Context {
   62 |             config: &config,
      |             ------ this field and `buffer` are required by `Context` to have the same lifetime
   63 |             buffer: &mut buffer,
      |                     ^^^^^^^^^^^ borrowed value does not live long enough
   ...
   68 |     };
      |     - `buffer` dropped here while still borrowed
   help: consider making different fields in `Context` have independent lifetimes
     |
   4 | struct Context<'a> {
     |                ^^
   5 |     config: &'a Config,
     |              ^^
   6 |     buffer: &'a mut Vec<u8>,
     |              ^^
   7 | }




Wow, yes, that would be great in this case. What would it do for pick_first?

It would be similar, pointing at the other argument. Neither case would have an applicable suggestion, just point in the right direction. I don't know if at the time we emit the error for `pick_first` we're able to evaluate the function's body to see if changing the lifetimes is feasible or not.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: