Skip to content

Improper use of closures not detected #51486

@remexre

Description

@remexre

The following code gets "overflow evaluating the requirement [closure@src/main.rs:20:19: 20:28]: std::ops::FnMut<(i32,)>" if the line in main is uncommented.
If the error should exist (which I'm unsure about), it should be detected without needing to call map.
If not, that's a bug.

enum Foo<T> {
    A(T),
    B(Box<Foo<T>>, Box<Foo<T>>),
}

impl<T> Foo<T> {
    fn map<F, T2>(self, mut f: F) -> Foo<T2>
    where
        F: FnMut(T) -> T2,
    {
        match self {
            Foo::A(x) => Foo::A(f(x)),
            Foo::B(x, y) => Foo::B(Box::new(x.map(&mut f)), Box::new(y.map(&mut f))),
        }
    }
}

fn main() {
    // Foo::A(0).map(|x| x + 1);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsC-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