Skip to content

New example of higher-ranked lifetime error #103515

@nappa85

Description

@nappa85

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-GATsArea: Generic associated types (GATs)A-async-awaitArea: Async & AwaitA-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-type-systemArea: Type systemAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.E-needs-mcveCall 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.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions