Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New example of higher-ranked lifetime error #103515

Open
nappa85 opened this issue Oct 25, 2022 · 1 comment
Open

New example of higher-ranked lifetime error #103515

nappa85 opened this issue Oct 25, 2022 · 1 comment
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. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@nappa85
Copy link

nappa85 commented Oct 25, 2022

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

@rustbot rustbot added A-async-await Area: Async & Await A-type-system Area: Type system C-bug Category: This is a bug. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs labels Oct 25, 2022
@jackh726 jackh726 added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Oct 25, 2022
@eholk eholk added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label Nov 7, 2022
@eholk
Copy link
Contributor

eholk commented Nov 7, 2022

Discussed in wg-async triage meeting today.

Thanks for the helpful repo that demonstrates the issue! A good next step would be to see if we can reduce the issue even further.

@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 5, 2023
@fmease fmease added A-GATs Area: Generic associated types (GATs) A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) and removed F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs labels Sep 24, 2024
@fmease fmease added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants