Skip to content

Erroneous E0367 on struct containing a closure returning an array #58311

Closed
@carado

Description

The following code fails in the playground, on the latest stable (1.32.0), latest beta (1.33.0-beta.6) and latest nightly (2019-02-07):

struct S<F: Fn() -> [u8; 1]>(F);

impl<F: Fn() -> [u8; 1]> Drop for S<F> {
    fn drop(&mut self) {}
}

fn main() {}

The error is the following:

error[E0367]: The requirement `<F as std::ops::FnOnce<()>>::Output == [u8; _]` is added only by the Drop impl.
 --> src/main.rs:3:1
  |
3 | / impl<F: Fn() -> [u8; 1]> Drop for S<F> {
4 | |     fn drop(&mut self) {}
5 | | }
  | |_^
  |
note: The same requirement must be part of the struct/enum definition
 --> src/main.rs:1:1
  |
1 | struct S<F: Fn() -> [u8; 1]>(F);
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The error seems to be the same regardless of rust version, and regardless of whether the function is an Fn, an FnMut, or an FnOnce (in particular, the error mentions std::ops::FnOnce<()>>::Output even when F isn't an FnOnce, if that's relevant).

The error does not occur when the return type [u8; 1] is replaced with, for example, u8 or (u8, u8), but still occurs with a more complex type still containing an array such as (u8, [u8; 1], u8);

Have a nice day.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions