Skip to content

Diagnostics for blanket impl of closure traits are suboptimal #24210

Closed
@huonw

Description

@huonw
fn direct<F: Fn()>(_: F) {}

trait Foo { fn method(&self) {} }

impl<F: Fn()> Foo for F {}

fn blanket<F: Foo>(_: F) {}

struct Moves;
fn main() {
    let x = Moves;   direct(|| drop(x));

    // let y = Moves;   blanket(|| drop(y));
}

The x line gives

<anon>:11:37: 11:38 error: cannot move out of captured outer variable in an `Fn` closure
<anon>:11     let x = Moves;   direct(|| drop(x));
                                              ^

while the y line gives:

<anon>:13:22: 13:29 error: the trait `core::ops::Fn<()>` is not implemented for the type `[closure <anon>:13:30: 13:40]` [E0277]
<anon>:13     let y = Moves;   blanket(|| drop(y));
                               ^~~~~~~

The latter doesn't really give much information about the problem (moving out of y) and, AFAIK, the most effective way to debug is to find the offending statement via binary search commenting out chunks of code. :(

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemP-lowLow priorityT-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