Skip to content

recursive call results in unconstrained opaque type args #145

@lcnr

Description

@lcnr

affected test

  • tests/ui/impl-trait/recursive-bound-eval.rs
pub trait Parser<E> {
    fn parse(&self) -> E;
}

impl<E, T: Fn() -> E> Parser<E> for T {
    fn parse(&self) -> E {
        self()
    }
}

pub fn recursive_fn<E>() -> impl Parser<E> {
    move || recursive_fn().parse()
}

fn main() {}

Even when allowing the method call, we end up with following opaque type definitions and ambiguous goal

  • opaque<?recursive_call> = ?infer
  • opaque<E> = closure<fn() -> E>
  • ?infer: Parser<E> (from the .parse() call)

We could (and maybe should) apply, the defining use opaque<E> = closure<fn() -> E> to opaque<?recursive_call>, equating ?infer with closure<fn() -> ?recursive_call>, at which point this will compile after proving closure<fn() -> ?recursive_call>: Parser<E>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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