Skip to content

Use statements do not shadow previous items #4094

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
brson opened this issue Dec 2, 2012 · 4 comments
Closed

Use statements do not shadow previous items #4094

brson opened this issue Dec 2, 2012 · 4 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries
Milestone

Comments

@brson
Copy link
Contributor

brson commented Dec 2, 2012

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.

@pcwalton
Copy link
Contributor

Proposal: make use statements only work before items. Bringing this up in next meeting.

@brson
Copy link
Contributor Author

brson commented Mar 23, 2013

agreed, but for all view items. that was the original behavior and I never knew why it was changed

@brson
Copy link
Contributor Author

brson commented Mar 23, 2013

oh I guess what I wrote was a little redundant. didn't realize this was my issue

@thestinger
Copy link
Contributor

use statements now have to precede items, closing

RalfJung pushed a commit to RalfJung/rust that referenced this issue Dec 21, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries
Projects
None yet
Development

No branches or pull requests

3 participants