Skip to content

RFC 1214 problems with bounds on associated type of type parameter #30311

Closed
@jld

Description

@jld

Consider this function:

fn example<O, B: ToOwned<Owned=O>>(_:&B) { }

This gives an RFC 1214 warning about needing to also add a O: Borrow<B> constraint in order to mention ToOwned<Owned=O>, but I don't understand why. As I understand it, this is effectively a type-level function being passed a proof that B: ToOwned, which necessarily includes a proof that <B as ToOwned>::Owned: Borrow<B>. Requiring an additional proof that <B as ToOwned>::Owned == O to instantiate the fn shouldn't weaken that… right?

Indeed, what I'd expected was the opposite: that I could declare where B: ToOwned<Owned=O> and that would be enough to satisfy any O: Borrow<B> obligations within the scope of the binder (e.g., calling HashMap::get) without having to explicitly declare that.

The above example is trivial for simplicity's sake, but the context where I ran into this wasn't: the owned type was an associated type of a type parameter of the impl containing the fn that was parameterized on the borrowed type.

(cc @aturon)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemC-bugCategory: This is a bug.I-needs-decisionIssue: In need of a decision.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions