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

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

Closed
bluss opened this issue Jan 25, 2015 · 2 comments
Closed

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

bluss opened this issue Jan 25, 2015 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@bluss
Copy link
Member

bluss commented Jan 25, 2015

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)

@kmcallister kmcallister added the A-diagnostics Area: Messages for errors, warnings, and lints label Jan 25, 2015
@bluss
Copy link
Member Author

bluss commented May 25, 2015

This is now fixed (At least as of 1.0.0).

@alexcrichton alexcrichton added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label May 26, 2015
@frewsxcv
Copy link
Member

I'll create a regression test for this

frewsxcv added a commit to frewsxcv/rust that referenced this issue Jun 18, 2015
Manishearth added a commit to Manishearth/rust that referenced this issue Jun 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

No branches or pull requests

4 participants