Cannot create function reference with parameters that don't have to outlive the functions lifetime

363668b
Opened by Erin Yuki Schlarb at 2024-09-03 09:04:23

List of things tried (that I remember):

  • Using the same lifetime for both the closure reference and it's parameters renders the reference uncallable: https://is.gd/CpXw0w
  • Using different lifetimes for the closure reference and it's parameters fails to compile, since the parameters must outlive the closure itself: https://is.gd/q5mJly
  • Using Higher-Rank Trait Bounds works, but is infeasible since it requires the parameter references types to be defined directly where the closure reference itself is defined: https://is.gd/genxSf

Since anything is better than unsafe { transmute(parameter_reference) }, I'd appreciate any comments on how to properly implement this.

  1. Higher-ranked lifetimes on types (so using for<'b> Func<'a, &'b usize>) seems like the most "obvious" solution, but since Func is not a trait, it doesn't work. I'm not sure what the best solution to this is, but it's probably something we should support at some point.

    James Miller at 2016-05-31 05:41:25

  2. So your answer is that higher-ranked lifetimes could, potentially at some point, be implemented for non-traits to solve this kind of problem?

    Erin Yuki Schlarb at 2016-05-31 10:37:43

  3. @alexander255 it seems like the best solution at least. I don't really have a good idea about what to do right now though.

    James Miller at 2016-06-01 00:54:46

  4. triage: any updates?

    Noah Lev at 2020-09-15 17:05:02