Skip to content
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

Incorrect resolution with module paths and closure analysis #29522

Closed
aturon opened this issue Nov 2, 2015 · 5 comments · Fixed by #29547
Closed

Incorrect resolution with module paths and closure analysis #29522

aturon opened this issue Nov 2, 2015 · 5 comments · Fixed by #29547
Assignees
Labels
A-lifetimes Area: lifetime related A-resolve Area: Path resolution

Comments

@aturon
Copy link
Member

aturon commented Nov 2, 2015

The following code incorrectly fails to compile:

use std::thread::spawn;

mod foo {
    struct Scope<'a>(&'a u8);
    pub fn scope<'a, F, R>(f: F) -> R where F: FnOnce(&Scope<'a>) -> R {
        panic!()
    }
}

fn main() {
    foo::scope(|scope| {
        spawn(move || {
            foo::scope(|s| {});
        });
    });
}

with error:

src/lib.rs:13:9: 13:14 error: the type `[closure@src/lib.rs:13:15: 15:10 scope:&foo::Scope<'_>]` does not fulfill the required lifetime [E0477]
src/lib.rs:13         spawn(move || {
                      ^~~~~
note: type must outlive the static lifetime

However, if you change the name scope in the closure within main, it works fine:

fn main() {
    foo::scope(|s| {
        spawn(move || {
            foo::scope(|s| {});
        });
    });
}
@aturon aturon added I-wrong A-resolve Area: Path resolution labels Nov 2, 2015
@nikomatsakis nikomatsakis added the A-lifetimes Area: lifetime related label Nov 2, 2015
@nikomatsakis
Copy link
Contributor

This is certainly creepy, nominating. Also I marked it as A-lifetimes because I don't think this impacts name resolution per se. My first thought is it is related to some of the known indeterminancies in region inference.

@aturon
Copy link
Member Author

aturon commented Nov 2, 2015

(This happens in 1.4 stable, 1.5 beta, and the 2015-10-31 nightly)

@aturon
Copy link
Member Author

aturon commented Nov 2, 2015

@nikomatsakis Note that the particular error here may be misleading. The original report was getting an error about Sync not being satisfied.

@nikomatsakis
Copy link
Contributor

@aturon yes, I saw that, though it seems likely related

@Aatch Aatch changed the title Incorrent resolution with module paths and closure analysis Incorrect resolution with module paths and closure analysis Nov 3, 2015
@arielb1
Copy link
Contributor

arielb1 commented Nov 3, 2015

Figured this out. Apparently resolve registers scope as an upvar. Will fix.

@arielb1 arielb1 self-assigned this Nov 3, 2015
arielb1 pushed a commit to arielb1/rust that referenced this issue Nov 3, 2015
bors added a commit that referenced this issue Nov 4, 2015
`resolve_identifier` used to mark a variable as an upvar when used within a closure. However, the function is also used for the "unnecessary qualification" lint, which would mark paths whose last component had the same name as a local as upvars.

Fixes #29522 

r? @eddyb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: lifetime related A-resolve Area: Path resolution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants