S0137: cannot infer lifetime for returned reference
Generated from rellum-diagnostics/src/db.rs.
Explanation
When a function returns a reference and more than one input reference could be the source, elision cannot choose a sound lifetime relationship. The function must spell out the shared named lifetime explicitly.
Common causes
- returning one of two input references with an elided return lifetime
- using conditional logic to choose between multiple borrowed inputs
- omitting a named lifetime where the output must be tied to several inputs
Canonical fixes
- add an explicit named lifetime to the related inputs and output
Before:
choose(a: &String, b: &String) : &String = a
After:
choose(a: &'a String, b: &'a String) : &'a String = a
- return an owned value if the result should not be tied to an input borrow
Code example
choose(a: &String, b: &String) : &String = a