Skip to content

Resolve: allow non-imported items to shadow glob imports#31377

Closed
jseyfried wants to merge 1 commit into
rust-lang:masterfrom
jseyfried:allow_shadowing
Closed

Resolve: allow non-imported items to shadow glob imports#31377
jseyfried wants to merge 1 commit into
rust-lang:masterfrom
jseyfried:allow_shadowing

Conversation

@jseyfried

Copy link
Copy Markdown
Contributor

This PR lets non-imported items shadow glob imported items (fixes #31337).
More precisely, a glob imported item will be shadowed (in all of the namespaces it defines) if any namespace it defines is already defined by a non-imported item.

Previously, it was possible to shadow only one namespace of a glob-imported re-export that defined both namespaces, so this is a [breaking-chage]. For example,

mod foo {
    mod bar { pub struct Bar; }
    pub use self::bar::Bar;
}

pub use foo::*; // This imports the item `foo::bar::Bar`.

// The following used to only shadow `Bar` in the value namespace,
// leaving `foo::bar::Bar` only partially accessible.
// Now, it shadows `Bar` in both namespaces.
pub fn Bar() {}

fn f() -> Bar { foo::Bar } // This breaks

The breakage can be fixed by importing the shadowed item again as a fresh name or by renaming the item that shadows it.
r? @nrc

@nrc

nrc commented Feb 3, 2016

Copy link
Copy Markdown
Member

I think we want an RFC before accepting this, right? (As discussed in #31337)

@bors

bors commented Feb 3, 2016

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #31338) made this pull request unmergeable. Please resolve the merge conflicts.

Comment thread src/librustc_resolve/lib.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment describing the purpose of this flag?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@petrochenkov

Copy link
Copy Markdown
Contributor

Are "glob vs glob" conflicts still result in errors? (In this implementation, I mean, not in the potential RFC.)

@jseyfried

Copy link
Copy Markdown
Contributor Author

@petrochenkov yes -- glob vs glob conflicts are still errors, as are glob import vs single import conflicts.

@jseyfried jseyfried force-pushed the allow_shadowing branch 4 times, most recently from 2d62a8c to 819f8e2 Compare February 4, 2016 22:51
@bors

bors commented Feb 11, 2016

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #31461) made this pull request unmergeable. Please resolve the merge conflicts.

@nrc nrc added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 11, 2016
@jseyfried

Copy link
Copy Markdown
Contributor Author

rebased

@nikomatsakis

Copy link
Copy Markdown
Contributor

We discussed this in the recent @rust-lang/lang meeting. Our conclusion was that the correct semantics is not entirely clear here. @nrc is planning on introducing an RFC describing the name resolution system soon -- one that will also incorporate changes to hygiene and macro expansion -- and plans to raise this issue in that RFC. So we figured it'd be best to wait on making an official decision until we have time to discuss the alternatives in that forum.

@bors

bors commented Feb 15, 2016

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #31648) made this pull request unmergeable. Please resolve the merge conflicts.

@jseyfried

Copy link
Copy Markdown
Contributor Author

Closing because of the decision in #31337 and because I no longer like the "linked namespaces" shadowing sematics I implemented here (see this comment).

@jseyfried jseyfried closed this Feb 18, 2016
@jseyfried jseyfried deleted the allow_shadowing branch February 18, 2016 00:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Items shadow glob-imported reexports

5 participants