Skip to content

surprising error with opaque types #204

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

Open
lcnr opened this issue May 8, 2025 · 1 comment
Open

surprising error with opaque types #204

lcnr opened this issue May 8, 2025 · 1 comment

Comments

@lcnr
Copy link
Contributor

lcnr commented May 8, 2025

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`
@lcnr
Copy link
Contributor Author

lcnr commented May 8, 2025

This adds a use referencing placeholders to the opaque type storage, might be fixed #140497

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant