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

Tracking issue for changes to name resolution (RFC 1560) #35120

Closed
nikomatsakis opened this issue Jul 29, 2016 · 15 comments
Closed

Tracking issue for changes to name resolution (RFC 1560) #35120

nikomatsakis opened this issue Jul 29, 2016 · 15 comments
Labels
B-RFC-implemented Blocker: Approved by a merged RFC and implemented. B-unstable Blocker: Implemented in the nightly compiler and unstable. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@nikomatsakis
Copy link
Contributor

Tracking issue for rust-lang/rfcs#1560.

@nikomatsakis nikomatsakis added B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. T-lang Relevant to the language team, which will review and decide on the PR/issue. B-unstable Blocker: Implemented in the nightly compiler and unstable. labels Jul 29, 2016
bors added a commit that referenced this issue Aug 5, 2016
… r=nrc

resolve: diagnostics improvement and groundwork for RFC 1560

Fixes #35115, fixes #35135, and lays groundwork for #32213 (cc #35120).
r? @nrc
@nrc nrc added B-RFC-implemented Blocker: Approved by a merged RFC and implemented. and removed B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. labels Aug 29, 2016
bors added a commit that referenced this issue Sep 2, 2016
Implement RFC 1560 behind `#![feature(item_like_imports)]`

This implements rust-lang/rfcs#1560 (cc #35120) behind the `item_like_imports` feature gate.

The [RFC text](https://github.com/rust-lang/rfcs/blob/master/text/1560-name-resolution.md#changes-to-name-resolution-rules) describes the changes to name resolution enabled by `#![feature(item_like_imports)` in detail. To summarize,
 - Items and named imports shadow glob imports.
 - Multiple globs can import the same name if the name is unused or the imports are shadowed.
 - Multiple globs can import the same name if the imports are of the same item (following re-exports).
  - The visibility of such a name is the maximum visibility of the imports.
  - Equivalently, adding a glob import will never reduce the visibility of a name, nor will removing one increase it.
 - Non-prelude private imports can be used wherever we currently allow private items to be used.
  - Prelude-imported names are unaffected, i.e. they continue to be usable only in lexical scopes.
 - Globs import all visible names, not just public names.
  - Equivalently, glob importing from an ancestor module imports all of the ancestor's names, and glob importing from other modules is unchanged.

r? @nrc
@nrc
Copy link
Member

nrc commented Oct 11, 2016

Nominating for stabilisation in the next cycle

@nrc
Copy link
Member

nrc commented Oct 11, 2016

There are potential breaking changes around importing more names in globs, e.g., in super::*, because we now import all accessible names, not just the public ones. We should do a Crater run before stabilisation. This is hard to do a warning cycle for. We should advertise the change during stabilisation. I feel like the benefits are so obvious and the breaking change so technical that it should be an easy sell.

@jseyfried
Copy link
Contributor

jseyfried commented Oct 11, 2016

More specifically, without #[feature(pub_restricted)] there is breakage if and only if

  • a glob import of an ancestor module (e.g. use super::*) imports a non-pub name,
  • the name is also imported by another glob import (making it ambiguous), and
  • the name is used (triggering an ambiguity error).

If the name is not used to resolve other imports, then it is simple to emit a warning instead of a hard ambiguity error. I believe this is likely to avoid a large fraction of any breakage in practice.

To avoid the remaining breakage, we would probably need to try re-resolving the crate without item_like_imports whenever there are ambiguity errors. This is doable, but it is fairly invasive and interacts badly with macro modularization.

@nikomatsakis
Copy link
Contributor Author

Can we get started on crater runs now? If we can't do a warning cycle, we should be aggressive about submitting PRs to affected crates to repair problems. (Also, we should investigate whether we can give good errors that link users to an issue explaining what changed and how to fix, even if they are still getting an error.)

@nrc
Copy link
Member

nrc commented Oct 12, 2016

Sure, I was thinking it was pretty early in the cycle and more breakage could appear later, but I guess there is no harm in doing multiple crate runs.

@jseyfried would you be able to make a PR to un-feature-gate for a Crater run please?

@jseyfried
Copy link
Contributor

jseyfried commented Oct 12, 2016

@nikomatsakis

If we can't do a warning cycle

A partial warning cycle is fairly simple and a full warning cycle is possible (see #35120 (comment)).

we should investigate whether we can give good errors that link users to an issue explaining what changed and how to fix

The errors we give today already include a suggestion for a fix, e.g. this gist. I could make the suggestion more detailed/concrete or improve the error in other ways -- let me know if you have ideas.

@aturon
Copy link
Member

aturon commented Oct 13, 2016

@nrc, we're moving these days to using @rfcbot for FCP proposals -- I'll flag it.

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Oct 13, 2016

Team member @aturon has proposed to merge this. The next step is review by the rest of the tagged teams:

No concerns currently listed.

Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot
Copy link

rfcbot commented Nov 11, 2016

🔔 This is now entering its final comment period, as per the review above. 🔔

psst @aturon, I wasn't able to add the final-comment-period label, please do so.

@jseyfried jseyfried added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Nov 11, 2016
@rfcbot
Copy link

rfcbot commented Nov 21, 2016

The final comment period is now complete.

@bstrie
Copy link
Contributor

bstrie commented Dec 25, 2016

I see that the FCP is complete, but this issue is still open. What's the status? Are we keeping this open pending a deprecation period?

@jseyfried
Copy link
Contributor

RFC 1560 was stabilized in #37127 (currently in beta).

@shepmaster
Copy link
Member

shepmaster commented Dec 28, 2016

This code currently fails in stable, but compiles in beta and nightly. I do not think it should:

struct Outer;

mod foo {
    use super::Outer;
    
    mod test {
        use super::*;
        
        struct Dummy(Outer);
    }
}

fn main() {}

Since use super::Outer; does not re-export Outer from foo (it should require pub to do so), I don't believe that foo::test::super::* should include Outer.

I've skimmed through the changes to name resolution rules section, but don't see what this would match up with. Anyone care to point me in the right direction?

@petrochenkov
Copy link
Contributor

@shepmaster

I've skimmed through the changes to name resolution rules section, but don't see what this would match up with.

https://github.com/rust-lang/rfcs/blob/master/text/1560-name-resolution.md#non-public-imports + https://github.com/rust-lang/rfcs/blob/master/text/1560-name-resolution.md#glob-imports-of-accessible-but-not-public-names

@shepmaster
Copy link
Member

@petrochenkov Thank you. "non-public imports" appears to be the piece I was missing; I was aware of the glob change. I guess I missed it when skimming because it uses a sibling module, not the nested module that my brain was primed for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-RFC-implemented Blocker: Approved by a merged RFC and implemented. B-unstable Blocker: Implemented in the nightly compiler and unstable. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

8 participants