Skip to content

Diagnostic doesn't clarify that error "cyclic type of infinite size" refers to type size / a failed occurs-check & not to the size of the in-memory representation of its values  #149842

@jacobsa

Description

@jacobsa

Here is a snippet from some (more realistic) code for creating a struct that contains a closure which, when run, will delete the struct:

struct Foo<F> {
    f: Option<F>,
}

unsafe fn make_self_deleting() -> impl Sized {
    let foo = Box::into_raw(Box::new(Foo { f: None }));
    (*foo).f = Some(|| {
        let _ = Box::from_raw(foo);
    });

    foo
}

(Playground)

This involves a self-referential type, since the struct Foo is generic over the closure that it contains, but the closure captures a pointer to Foo, so it's unsurprising that the compiler rejects it. However the error is a bit weird:

cyclic type of infinite size

I agree with the "cyclic" part, but I was surprised by the "infinite size" part. That's not actually true here, is it? The closure needs to capture only one pointer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-type-systemArea: Type systemD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.T-typesRelevant to the types 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