Skip to content

Use statements do not shadow previous items #4094

Closed
@brson

Description

@brson

This is allowed but doesn't do what you might expect.

mod foo {
    pub fn bar() -> int { 10 }
}

mod baz {
    pub fn bar() -> int { 20 }
}

use foo = baz;

fn main() {
    // This will fail - calling into mod foo, not mod baz
    assert foo::bar() == 20;
}

It used to be that 'use' statements only came before items and the items shadowed the use statements. Now they may appear alongside items, but the items still shadow the use statements, regardless of order.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binaries

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions