Skip to content

Moved variables with the same name as a static method sometimes result in erronous nonsensical errors #26589

Closed
@Tobba

Description

@Tobba
struct Foo;

impl Foo {
    pub fn init() {
    }
}

struct Bar;

fn main() {
    let init = Bar;
    drop(init);
    let foo = move || {
      Foo::init();
    };
}

Results in

<anon>:14:7: 14:16 error: capture of moved value: `init`
<anon>:14       Foo::init();
                ^~~~~~~~~
note: in expansion of closure expansion
<anon>:13:20: 15:6 note: expansion site
<anon>:12:10: 12:14 note: `init` moved here because it has type `Bar`, which is non-copyable
<anon>:12     drop(init);

That doesn't make sense.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-resolveArea: Name/path resolution done by `rustc_resolve` specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions