Skip to content

mismatched types: expected fn&() -> ! but found fn&() -> _|_ #3681

Closed

Description

@ben0x539

This fails:

fn foo(f: fn() -> !) {}

fn main() {
    foo(|| {fail });
}

with

foo.rs:4:7: 4:18 error: mismatched types: expected `fn&() -> !` but found `fn&() -> _|_` (expected non-returning function, found non-returning function)
foo.rs:4     foo(|| {fail });
                ^~~~~~~~~~~

While this works:

fn foo(f: fn() -> !) {}

fn main() {
    foo(fn() -> ! { fail });
}

I don't know what is going on there but I feel the first snippet should work too.

Activity

  1. nikomatsakis commented on Oct 8, 2012

    @nikomatsakis
    Contributor

    Agreed. The current type checker has two ways to represent the same thing, which I think is what is leading to this problem. I've been thinking we oughta' fix that for some time, this bug gives me a good justification. =)

  2. nikomatsakis commented on Oct 8, 2012

    @nikomatsakis
    Contributor

    Specifically: fn types have a return_style (or something like that) and there is the bottom type. I don't see why we need both.

  3. catamorphism commented on Jan 3, 2013

    @catamorphism
    Contributor

    The reason we have both is that _|_ isn't a first-class type at the moment. That is, you can only mention it in the return type of a function, as !; you can't declare a local with type _|_, or a field in a data structure.

  4. catamorphism commented on Jan 3, 2013

    @catamorphism
    Contributor

    The most conservative fix here would be a way to infer the return_style for closures.

  5. nikomatsakis commented on Jan 8, 2013

    @nikomatsakis
    Contributor

    This should be fixed.

  6. added a commit that references this issue on Jun 29, 2024
  7. added a commit that references this issue on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions