Skip to content

Impossible to pass diverging closures as an argument #39033

@nagisa

Description

@nagisa
fn banana<F: FnOnce()>(f: F) -> ! { f(); loop {} }

fn main() {
    banana(move || -> ! { loop {} })
}

result

error[E0271]: type mismatch resolving `<[closure@<anon>:6:12: 6:36] as std::ops::FnOnce<()>>::Output == ()`
 --> <anon>:6:5
  |
6 |     banana(move || -> ! { loop {} })
  |     ^^^^^^ expected !, found ()
  |
  = note: expected type `!`
  = note:    found type `()`
  = note: required by `banana`

Used to work in 1.8.0, so is a regression from stable to stable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    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