-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Module system cleanup #385
Conversation
I would love to remove the various restrictions (especially the ordering restriction, which often requires uses before definitions) as proposed in this RFC. I've always considered the ordering restriction a wart. I'm ambivalent about the lint. In general, we probably will want lint(s) corresponding to our coding guidelines, but these are not completely nailed down now. And removing the ordering restriction may allow new guidelines to emerge. |
👍 I also think this will ease the way for macros to expand to both items and view items, which should allow us to avoid some of the sketchiness present in e.g. |
The lint could be made opt-in for now. |
This is great. I think there's no better reason to do this than the fact that—as you showed—these restrictions can already be worked around. We might as well clean this up. |
As a relatively new user of Rust, I can confirm that I realize that isn't how it actually works, but from a human perspective that's how it feels like it would work, to the extent that it didn't even occur to me that the ordering could have been wrong. Even after getting the error message from the compiler, I still tried about gazillion other things before finally changing their ordering on a lark (and was surprised when it worked). I don't have much to say about the other aspects of the proposal. But even just allowing |
+1, mod-after-use is very confusing to newcomers. |
+1, restrictions are confusing and seem stupid. |
Style is good but it shouldn't be enforced that way. We already have some style guides and conventions that @aturon is working on. A better case can be made, in my opinion, to fix this and use as style the "logical" or at least historical (from other languages) method of use after mod. Any abitrary rules can be chosen as the style, we may as well choose ones that seem to make sense. |
@blaenk You suggest that the current rules were made up from nothing, but in fact they were the result of import shadowing working other than people believed. |
I didn't suggest that at all. In fact, as this very RFC suggests, that reason has been invalidated by a prior RFC, perhaps better conventions can arise, as @aturon mentioned. What I meant by "any arbitrary rules can be enforced" was that, if you really wanted to continue enforcing a given style this way, there's no reason we can't switch to the more logical ordering style and enforce that, if what you ultimately care about is having only one possible style. |
@sfackler there would be no more view items, which is great if it doesn't break any hypothetical extension (@nikomatsakis seems to have plans for expansion-time resolution that work with this). |
I would like to see the ordering restrictions between mod and use statements lifted (are there also restrictions wrt other items? If so, I would like to lift those too). I would like to see more motivation for I would actually like to restrict the use of |
@nick29581: Then the main motivation for I also don't think that macros expanding to extern crate is a problem in general - its just like having a #[phase(link)]
extern crate foo; // Might link to additional libraries
foo::bar();
#[phase(plugin)]
extern crate foo;
bar!(); // Might link to additional libraries Of course, if we change |
There are a couple of use cases for #[cfg(test)]
mod test {
extern crate test;
fn bench_thing(b: &mut test::Bencher) { ... }
} If this change were implemented, another use case would be making macros like #[deriving(Decodable)]
mod Foo { .. }
// expands to
extern crate serialize as gensymed_name;
impl gensymed_name::Decodable for Foo { ... } |
We discussed this at today's meeting and we would like to accept this RFC, but without the optional lint. @Kimundi could you push a commit removing the lint from the RFC and then we'll merge. Thanks! |
Niiice. Good work everyone! On Tuesday, October 21, 2014, Nick Cameron notifications@github.com wrote:
|
Agreed, really glad to see this moving forward! |
@nick29581: Done, glad to hear it got accepted :) |
RFC #385 is currently active
…r=nrc We no longer require `use` and `extern crate` items to precede other items in modules thanks to [RFC #385](rust-lang/rfcs#385), but we still require `use` and `extern crate` items to precede statements in blocks (other items can appear anywhere in a block). I think that this is a needless distinction between imports and other items that contradicts the intent of the RFC.
Remove a few unnecessary restrictions and inconsistencies in the module system, namely:
extern crate
,use
and other items.pub extern crate
as opposed to only private ones.extern crate
in blocks/functions, and not just in modules.Rendered