Skip to content

resolve: the relative order of items and statements in a block can be important #33118

Closed as not planned
@jseyfried

Description

@jseyfried

For example,

fn foo() {}

fn f1() {
    fn bar() {
        foo(); // This resolves to the item
    }
    let foo = 0;
}

fn f2() {
    let foo = 0;
    fn bar() {
        foo(); // This is an error (cannot capture dynamic environment in a fn item)
    }
}

Since items in a block are above the block's local variables in the scope hierarchy, it might make sense to resolve the items' bodies in scopes that descend directly from the scope of the block's items, bypassing the scopes of the local variables.

That being said, I think I prefer the current behavior. However, since it will mildly complicate name resolution in the future, I wanted to make sure that we actually want this behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions