-
-
Notifications
You must be signed in to change notification settings - Fork 15k
New example of higher-ranked lifetime error #103515
Copy link
Copy link
Open
Labels
A-GATsArea: Generic associated types (GATs)Area: Generic associated types (GATs)A-async-awaitArea: Async & AwaitArea: Async & AwaitA-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-type-systemArea: Type systemArea: Type systemAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.Category: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-GATsArea: Generic associated types (GATs)Area: Generic associated types (GATs)A-async-awaitArea: Async & AwaitArea: Async & AwaitA-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-type-systemArea: Type systemArea: Type systemAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.Category: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
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