Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ben0x539 opened this issue Oct 6, 2012 · 5 comments
Closed

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

ben0x539 opened this issue Oct 6, 2012 · 5 comments
Labels
A-typesystem Area: The type system
Milestone

Comments

@ben0x539
Copy link
Contributor

ben0x539 commented Oct 6, 2012

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.

@nikomatsakis
Copy link
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. =)

@nikomatsakis
Copy link
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.

@catamorphism
Copy link
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.

@catamorphism
Copy link
Contributor

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

@nikomatsakis
Copy link
Contributor

This should be fixed.

RalfJung pushed a commit to RalfJung/rust that referenced this issue Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system
Projects
None yet
Development

No branches or pull requests

3 participants