Skip to content

deduce_closure_signature fails in with ambiguous self-referential aliases #156206

@lcnr

Description

@lcnr
trait Foo<'a> {
    type Input;
}

impl<'a, F: Fn(&'a u32)> Foo<'a> for F {
    type Input = &'a u32;
}

fn needs_super<F: for<'a> Fn(<F as Foo<'a>>::Input) + for<'a> Foo<'a>>(_: F) {}

fn main() {
    needs_super(|_: &u32| {}); // doesn't need deduce sig rn
    needs_super(|_| {}); // fails with old solver
}

taken from rust-lang/trait-system-refactor-initiative#191 (comment)

We currently don't decide the closure signature for needs_super even though we have a ?expectation: for<'a> Fn(<?expectation as Foo<'a>>::Input). Doing this properly relies on higher-kinded inference variables.

With higher-kinded infer vars, we could set the closure signature to ?inf[?expectation, 'a] and constrain that infer var via a Projection(<?expectation as Foo<'!a>>::Input, [?expectation, '!a]) goal (where '!a is a placeholder.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)T-typesRelevant to the types team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    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