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

Resolve: refactor away the field Module::external_module_children #31317

Merged
merged 1 commit into from
Feb 1, 2016

Conversation

jseyfried
Copy link
Contributor

This PR refactors away Module's external_module_children and instead puts extern crate declarations in children like other items, simplifying duplicate checking and name resolution.

This PR also allows values to share a name with extern crates, which are only defined in the type namespace. Other than that, it is a pure refactoring.

r? @nrc

@jseyfried
Copy link
Contributor Author

Finally, this PR lays the groundwork for a fix of #26775.

cc @nikomatsakis @petrochenkov

span,
E0260,
"the name `{}` conflicts with an external crate \
that has been imported into this module",
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, if a non-crate is defined first and a crate is defined second, the error message will be incorrect.

I think both theelse cases above would be better moved from here and handled by resolve_struct_error and ResolutionError::DuplicateDefinition.
The error messages will have to be tweaked though, something along the lines:
"definition of {kind} {name} conflicts with existing definition of {kind} {name}" where {kind} is a precise item kind (including "external crate") and not just "type or module"/"value".
multispans can be used to report spans of the both conflicting items at the same time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I'm planning on cleaning up the duplicate errors in a separate PR so that it can be reviewed and discussed independently of this refactoring (unless you would like do that instead).
Thanks for the pointer to multispans -- this looks like a good use case for them.

@petrochenkov
Copy link
Contributor

reviewed, lgtm
the comment about error messages is more an improvement suggestion, than a blocker

@@ -8,7 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn std() {} //~ ERROR the name `std` conflicts with an external crate
fn std() {}
Copy link
Member

Choose a reason for hiding this comment

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

Why does fn std no longer conflict? Seems like it should to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fn std no longer conflicts since it defines std in the value namespace but the extern crate defines std in the type namespace.

Right now, fn std not does conflict with mod std { ... } for the same reason and I see no reason to treat extern crate std differently.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, seems fine, thanks for the explanation

@nrc
Copy link
Member

nrc commented Feb 1, 2016

@bors: r+

@bors
Copy link
Contributor

bors commented Feb 1, 2016

📌 Commit e768fa7 has been approved by nrc

@bors
Copy link
Contributor

bors commented Feb 1, 2016

⌛ Testing commit e768fa7 with merge 28bed3f...

bors added a commit that referenced this pull request Feb 1, 2016
This PR refactors away `Module`'s `external_module_children` and instead puts `extern crate` declarations in `children` like other items, simplifying duplicate checking and name resolution.

This PR also allows values to share a name with extern crates, which are only defined in the type namespace. Other than that, it is a pure refactoring.

r? @nrc
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

Successfully merging this pull request may close these issues.

4 participants