New example of higher-ranked lifetime error #103515
Labels
A-async-await
Area: Async & Await
A-GATs
Area: Generic associated types (GATs)
A-higher-ranked
Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)
A-type-system
Area: Type system
AsyncAwait-Triaged
Async-await issues that have been triaged during a working group meeting.
C-bug
Category: This is a bug.
E-needs-mcve
Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
As discussed in #92096, I've found another example of higher-ranked lifetime error
Long story short, I was developing a struct that contains a string key and a database connection. For other problems the connection was already owned, but the key was a Cow<'key, str> to avoid allocation when unneeded.
The constructor accepted S: Into<Cow<'key, str>>, so you can pass in even a static str or a String, no problems.
Everything was looking good, mi lib crates using that struct built fine, until I plugged it into my warp webserver, at this point I've got my higher-ranked lifetime error.
You can test yourself in this project where I've replicated the problem: https://github.com/nappa85/hrtb-error
To solve the problem, I've converted the Cow<'key, str> into a String and removed the lifetime from my struct.
To test the solution you simply have to change the pointed branch from "cow" to "owned" inside Cargo.toml
The text was updated successfully, but these errors were encountered: