Ambiguous output when higher rank trait bound is not met #95182
Labels
A-async-await
Area: Async & Await
A-diagnostics
Area: Messages for errors, warnings, and lints
A-higher-ranked
Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)
A-lifetimes
Area: Lifetimes / regions
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Given the following code demonstrating an invalid lifetime mismatch between the borrowed whom argument and the returned future:
Playground for more context: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=58bcba6782e856d0de5f3d1271bf2c9e
The output from rustc makes a strange claim about a mismatched type with the expected and found type labels being identical:
I believe the underlying issue is simply that the whom reference does not necessarily outlive the future that it returns. That is, by the time the future is awaited, it could be beyond the lifetime of whom. The compiler is correct to halt on this code, however, the error message is where I think the bug really lies as it asks the developer to character-by-character compare an identical string only to guess at what the real issue is. Further, changing this code very slightly reveals a greatly improved error message by simply using closure syntax instead of the named fn:
Rust playground for the revised sample: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f2ea2a2834215e0acdc6b88de3b70471
Now the error message we get is detailed and helpful:
EDIT: I discovered a much simpler example that well highlights the poor error message as opposed to the underlying and very real lifetime issue that existed in my code.
The text was updated successfully, but these errors were encountered: