Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upFeature gate import shadowing #116
Conversation
This comment has been minimized.
This comment has been minimized.
|
(Update circa 15 July 2014: This comment was responding to an earlier version of the RFC which was less clear and thus seemed broader in scope. I'm leaving the comment in place so that one can understand the thread of discussion.) So, just to be clear: This would stop me from choosing certain names in a pattern binding (such as a fn parameter name) just because the same name happens to be pulled in from a use declaration (perhaps via a glob), is that right? One important case to make sure continues to work (and can work, even with this proposal in place; we just need to make sure it does work): if a macro introduces an item, it should not be restricted in the names it chooses for its hygienically injected bindings. For example, consider the following:
What I want to avoid is that the proposed rule be over-zealously interpreted as meaning that the The reason you need to make sure this case continues to work, i.e. the reason it is important that such psuedo-shadowing is allowed, is that if you disallowed such pseudo-shadowing, then macros are no longer proper abstractions, since any use of them becomes dependent upon all of their internally bound names being available. (Overall, as a Schemer, I prefer flexible shadowing rules rather than trying to restrict programmers from shadowing identifiers. But I think I do understand where people come from when they ask for things like this.) |
This comment has been minimized.
This comment has been minimized.
|
@pnkfelix I'm not sure what you mean with your first point about pattern bindings. |
This comment has been minimized.
This comment has been minimized.
|
@Kimundi I just said "pattern binding" to mean binding in general, i.e. via the declarations of a Its one thing if this RFC Is restricted to outlawing certain combinations of |
This comment has been minimized.
This comment has been minimized.
|
Ah, I see you think I'm proposing forbidding shadowing between any declaration in the same module. Thats not what I meant: I only propose forbidding shadowing of items (including view items) in the same flat scope. This would be forbidden: use foo::Bar;
struct Bar;But this would be allowed: use foo::Bar;
fn x() {
struct Bar;
}Thats what I mean with flat scope: There is the top level of the module, and then anonymous modules like function bodies that inherit all declarations from their parent, while also being able to shadow them themself, and currently So, bindings in Same situation with the macro: The |
This comment has been minimized.
This comment has been minimized.
|
Ah! That is indeed different than what I thought you were proposing. Okay. Maybe revise RFC to make that distinction explicit. |
This comment has been minimized.
This comment has been minimized.
|
+100, thank you for writing the proposal I was going to write. I'll try to recap how I understand this proposal, and how I think it should be, and I hope that these things coincide. DefinitionsScopeA scope is basically the space between braces, with inner braces starting a new scope. So:
NamespaceA separate namespace exists for each type of thing for which you can use the same identifier without conflict. Rust has separate namespaces for type-level things (types, traits), lifetimes, value-level things (variables, statics, functions, enum variants), modules, and macros. Item declarationItem declarations are basically those things which it is legal to declare outside of function bodies, so not The rules
MotivationItem declarations in a given scope are logically unordered, so it makes no sense for them to shadow each other. Allowing shadowing of declarations from outer scopes improves modularity, because it means that if additional declarations are introduced to an outer scope, the meaning of inner scopes is unaffected. |
This comment has been minimized.
This comment has been minimized.
|
Thanks for writing that up, your "rules" section is pretty much what I'm trying to propose here :) EDIT: |
This comment has been minimized.
This comment has been minimized.
|
Ah, the term "view item" was unfamiliar to me. But yes, by "item declarations" I meant both view items and definitions. |
This comment has been minimized.
This comment has been minimized.
ben0x539
commented
Jun 25, 2014
|
This proposal seems reasonable to agree on. I'd be surprised if it even negatively affects existing code and I think it has the potential to make item visibilities less surprising, and if it turns out untenable we can relent at any time post-1.0.. |
This comment has been minimized.
This comment has been minimized.
|
@Kimundi can you revise the RFC to try to incorporate some of the feedback from the discussion here? |
This comment has been minimized.
This comment has been minimized.
|
@pnkfelix Yeah, but only around starting the weekend. |
This comment has been minimized.
This comment has been minimized.
|
@pnkfelix I updated the RFC with more information, I hope its now clearer what it is about. |
This comment has been minimized.
This comment has been minimized.
|
+1, I'm all about making resolve simpler. |
This comment has been minimized.
This comment has been minimized.
|
W.r.t. unresolved questions: Overlapping imports
I think forbidding this should be explicitly part of the RFC as well. Prelude
FWIW, what Haskell does here is that:
Rust doesn't have an equivalent for Prelude and backwards compatibilityHowever, the above doesn't solve the problem that adding names to the
My recommendation: Do none of these for now. There's no urgent need. Make shadowing things imported from the |
aturon
referenced this pull request
Jul 18, 2014
Closed
rustc: error when both both defining and using a module should be more specific #15769
This comment has been minimized.
This comment has been minimized.
|
Somewhat related, I've specified a formalization (and prototype) of the name resolution rules I would eventually like to see Rust use: https://github.com/nikomatsakis/rust-name-resolution-algorithm It would be nice to make changes to resolve to make it forwards compatible with these rules. (That said, I do plan to amend those rules to take macros into account, and that has not been done.) |
This comment has been minimized.
This comment has been minimized.
|
Is there any good reason to have a feature gate at all? I think I would prefer to simply remove it. |
This comment has been minimized.
This comment has been minimized.
|
In meeting, we clarified that feature gate is just a means to do a more graceful deprecation, which makes sense. |
brson
merged commit e5f3fb1
into
rust-lang:master
Aug 12, 2014
This comment has been minimized.
This comment has been minimized.
|
Discussed at https://github.com/rust-lang/meeting-minutes/blob/master/weekly-meetings/2014-08-12.md. Accepted as RFC 50. Tracking bug: rust-lang/rust#16464 The feature gating is just going to be for the purposes of deprecation, with the intent to remove the feature completely in the future. |
Kimundi commentedJun 12, 2014
Rendered View