rust-lang / rust-lang/rust

`deduce_closure_signature` fails in with ambiguous self-referential aliases

Open
#156,206 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-higher-ranked C-bug T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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 https://github.com/rust-lang/trait-system-refactor-initiative/issues/191#issuecomment-3307163025

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the self-contained Rust reproducer around needs_super and confirm that the closure without an explicit parameter type fails during deduce_closure_signature. Read the linked trait-system refactor discussion and investigate the higher-kinded inference-variable requirement. Done means the ambiguous self-referential alias case can infer the closure signature successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.