Skip to content

surprising error with opaque types #204

Open
@lcnr

Description

@lcnr
fn constrain<'a, F: FnOnce(&'a ())>(_: F) {}
fn foo<'a>(_: &'a ()) -> impl Sized + use<'a> {
    constrain(foo); // adds use `opaque<'!a> = ()`
    () // adds use `opaque<'a> = ()` -> leak check error
}
fn main() {}

results in the following error in HIR typeck

error[E0277]: expected a `FnOnce(&())` closure, found `for<'a> fn(&'a ()) -> impl Sized {foo}`
 --> <source>:3:24
  |
3 |     constrain_identity(foo);
  |     ------------------ ^^^ expected an `FnOnce(&())` closure, found `for<'a> fn(&'a ()) -> impl Sized {foo}`
  |     |
  |     required by a bound introduced by this call
  |
  = help: the trait `FnOnce(&())` is not implemented for fn item `for<'a> fn(&'a ()) -> impl Sized {foo}`
note: required by a bound in `constrain_identity`
 --> <source>:1:30
  |
1 | fn constrain_identity<'a, F: FnOnce(&'a ())>(_: F) {}
  |                              ^^^^^^^^^^^^^^ required by this bound in `constrain_identity`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions