Skip to content

Incorrect resolution with module paths and closure analysis #29522

Closed
@aturon

Description

@aturon

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| {});
        });
    });
}

Metadata

Metadata

Assignees

Labels

A-lifetimesArea: Lifetimes / regionsA-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