-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
RFC: Exports on individual items (pub and priv) #1893
Comments
I'm in favour of this. Scrolling back and forth to the export list at the top of the file to keep things consistent is painful and error-prone. Also, this might nicely generalize glob exports -- |
+1 from me. I would also like it if things were private by default in all cases, just for simplicity. (As opposed to "if there are no pub declarations, then everything is pub") |
Also, I think we should use the same convention for classes. |
@marijnh It does generalize export globs, yes. That's more or less how I've modified the resolve pass to treat export globs anyways. Merged the glob-specifying AST nodes and just treats an export glob as "an import of the same kind that happens to re-export its target". I'm not completely in favour of this, but partly. It's similar to how I did things at first; I changed to the current system for these reasons:
I realize these are in direct tension with the desire to avoid flipping up-and-down between definitions and export lists though. So I'm just .. curious if there's some way to relieve that tension. Some languages "solve" this by using sectioning directives within definition scopes. That is, the way C++ members are organized into any number of As an aside, I think if we make this change we should bundle it with two other changes:
|
Having all the exported symbols live in one place is nice, but the problem is that only the identifiers, not the signatures, live there. So in practice one ends up scrolling down to find the definition anyway. I think I'm ok with crate-local visibility being the default.
|
Yeah. What you say wrt. signatures is true. I find the export-lists only moderately helpful as a synopsis. They're no function prototypes. I'm certainly willing to experiment with this and see how it looks. (Resolve is due for a reorganization anyways, I think. But maybe that is orthogonal to this.) |
How does this work with enum variants? Are they also crate-visible by default and require |
Maybe have them default to the visibility of their declaring enum, with explicit overriding permitted? We'd need the keyword for crate-visible in that case, as you say (I realize this is slightly widening the scope of this RFC), but perhaps |
At meeting, had consensus to implement this (pub, priv, crate) access-control on items, and turn export into import + access control. |
See also https://gist.github.com/2481106 |
punting to 0.4 |
This is working on incoming, except for cross-crate methods. Needs a snapshot to get rid of the old syntax. |
Closing; any remaining issues should be followups. |
Instead of
export
lists, we could have exports on individual items.So, instead of:
We would have:
And instead of:
We would have:
(Here I changed
export
topub
to better match classes and to avoid exceeding the 5-character limit, but I'm ok either way.)This change would help avoid the pain of managing export lists and should make libraries easier to write. Often people look at the definitions of items and want to know then and there whether the item is public or not.
The text was updated successfully, but these errors were encountered: