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

Regression (?) in name resolution of items defined in functions/blocks #31845

Closed
petrochenkov opened this issue Feb 23, 2016 · 2 comments
Closed

Comments

@petrochenkov
Copy link
Contributor

This code compiles on nightly, but is rejected by stable and beta compilers.
On nightly items defined in a block are visible from all modules defined in this block.
Such "pervasive" visibility is quite unusual and I suspect it was introduced unintentionally.

fn f() {
    struct S;

    fn g() {
        let s = S; // <- beta/stable/nightly - ok
    }
    mod m {
        fn h() {
            let s = S; // <- beta/stable - error: unresolved name `S` [E0425], nightly - ok
        }

        mod n {
            fn k() {
                let s = S; // <- beta/stable - error: unresolved name `S` [E0425], nightly - ok
            }
        }
    }
}

fn main() {
}

cc @jseyfried

@jseyfried
Copy link
Contributor

This was introduced in #31105 while fixing #23880.
This bug existed earlier (in some sense) but was benign. Before #31105, only type parameters and local variables leaked, but using these "captured" locals and parameters is already a separate error.

bors added a commit that referenced this issue Feb 26, 2016
This fixes a bug (#31845) introduced in #31105 in which lexical scopes contain items from all anonymous module ancestors, even if the path to the anonymous module includes a normal module:
```rust
fn f() {
    fn g() {}
    mod foo {
        fn h() {
           g(); // This erroneously resolves on nightly
        }
    }
}
```

This is a [breaking-change] on nightly but not on stable or beta.
r? @nikomatsakis
@jseyfried
Copy link
Contributor

@petrochenkov this can be closed -- I think bors didn't close it because the magic words were only in the title.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants