Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Tobba opened this issue Jun 26, 2015 · 2 comments
Labels
A-resolve Area: Name/path resolution done by `rustc_resolve` specifically

Comments

@Tobba
Copy link
Contributor

Tobba commented Jun 26, 2015

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.

@eddyb eddyb added the A-resolve Area: Name/path resolution done by `rustc_resolve` specifically label Jun 26, 2015
@eddyb
Copy link
Member

eddyb commented Jun 26, 2015

I introduced this bug in #17259 by tracking captures as they were resolved.
At the time I was unaware of secondary resolution requests in non-error paths.
The only one that I've seen since is for a little-known lint (because it's disabled by default, and only ever used in a test which tests that the lint works):

#![warn(unused_qualifications)]
mod foo {
    pub fn bar() {}
}
use foo::bar;

fn main() {
    foo::bar(); // warning: unnecessary qualification
}

This lint works by resolving the last element of a path after resolving the full path.
If the results match, the lint is triggered. However, in this case, there is a side-effect of upvar capture because that last element happens to match a local variable outside a closure scope.

@steveklabnik
Copy link
Member

This program compiles today. Closing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-resolve Area: Name/path resolution done by `rustc_resolve` specifically
Projects
None yet
Development

No branches or pull requests

3 participants