Skip to content

False positive for "can't capture dynamic environment in a fn item" #21622

Closed
@bluss

Description

@bluss

Because of let new = Index::new;, a local shorthand to a static function, this code fails to compile. Moving the let new down below fn inner it will compile.

Error message:

<anon>:11:21: 11:31 error: can't capture dynamic environment in a fn item; use the || { ... } closure form instead
<anon>:11         let index = Index::new();
                              ^~~~~~~~~~
struct Index;

impl Index {
    fn new() -> Self { Index }
}

fn user() {
    let new = Index::new;

    fn inner() {
        let index = Index::new();
    }

    let index2 = new();
}

fn main() {}

Playpen link

rust version: rustc 1.0.0-nightly (4874ca36f 2015-01-23 00:18:57 +0000)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions