Description
I had a problem getting the compiler to accept an implicit lifetime trait method implemented for an explicit lifetime object. @estebank encouraged me to submit this as a bug, though I did find a workaround.
After fixing a bunch of compiler errors in my code, I finally got to see "error: lifetime may not live long enough" for code like in this playground.
It would be nice if the compiler could figure out that the lifetimes here are actually OK (which I think they are), but it is complicated since the trait has no lifetime, the target implementation type does not have a lifetime, but the method result does have a lifetime.
I tried fixing with various hints, but the only fix that worked for me was to change the Trait to include a lifetime, which got rid of the error, as in this playground code. This is actually OK, but it meant that I had to do a whole bunch of code editing since I had to change the Trait method signature, and most callers had to be modified.
Meta
This behavior happens in both stable and nightly on the playground.
rustc --version --verbose
:
rustc 1.72.1 (d5c2e9c34 2023-09-13)
binary: rustc
commit-hash: d5c2e9c342b358556da91d61ed4133f6f50fc0c3
commit-date: 2023-09-13
host: x86_64-unknown-linux-gnu
release: 1.72.1
LLVM version: 16.0.5