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 upNon-inline module is allowed inside other items #29765
Comments
huonw
added
A-parser
I-nominated
T-lang
labels
Nov 11, 2015
This comment has been minimized.
This comment has been minimized.
|
This seems weird to me. I think the intention is that the out-of-line syntax ( |
This comment has been minimized.
This comment has been minimized.
|
I'd vote for allowing non-inline modules only at the top-level, to retain a clear mapping to the file system. |
This comment has been minimized.
This comment has been minimized.
|
(Or nested inside modules.) |
This comment has been minimized.
This comment has been minimized.
|
triage: P-medium Backwards incompatible, but ... kind of a curiousity. |
rust-highfive
added
P-medium
and removed
I-nominated
labels
Nov 12, 2015
nikomatsakis
added
the
I-wrong
label
Nov 12, 2015
This comment has been minimized.
This comment has been minimized.
|
Found one more mod aliasing scenario. It involves several files, and is semi officially allowed by the reference. The layout
The files //main.rs
mod foo;
mod bar;
fn main() {}
//foo.rs
mod inner { mod copy; }
//bar.rs
mod inner { mod copy; }The copy module will be aliased. The problem is that although |
matklad
added a commit
to intellij-rust/intellij-rust
that referenced
this issue
Nov 14, 2015
matklad
added a commit
to intellij-rust/intellij-rust
that referenced
this issue
Nov 15, 2015
matklad
added a commit
to intellij-rust/intellij-rust
that referenced
this issue
Nov 16, 2015
This comment has been minimized.
This comment has been minimized.
|
Upon reflecting more about this, I think that there are two questions here.
The questions are independent because you can use I would prefer if the answer to the second question is not. I'm contributing to the Rust plugin for IntelliJ IDEA, and one of the tasks there is mapping files to modules (for example, to go to the parent module). I would much prefer just to highlight module aliasing as an error, rather then to deal with non one-to-one mapping between files and modules. As a side note, if a user does want aliasing for some reason, she can always use symbolic link for the same effect. |
This comment has been minimized.
This comment has been minimized.
|
I tend to believe it is fine to have aliasing if you write the Your example however is disconcerting, and suggests that perhaps the code has a slightly different model in mind than I do in my head. :) That is, I strongly expect |
This comment has been minimized.
This comment has been minimized.
It is forbidden because |
This comment has been minimized.
This comment has been minimized.
|
Just in case here is a repository with the example: https://github.com/matklad/nested-mod
I don't see a reason to allow user to shoot himself in the leg. What if you accidentelly have identical My main concern though is that non injective file to module mapping may complicate the implementation of some rust tools. Here is another hypothetical example of this. Suppose you implement incremental compilation for rustc. You will need a mapping from files to modules. If mod aliasing is alowed, then you will need a multimapping. So you end up with more complex code which is used only in a tiny fraction of projects and because of this probably contains some bugs. |
This comment has been minimized.
This comment has been minimized.
Ah, I see. So it seems to me that the problem is that
A compromise might be Yet Another Lint Warning. ;) I agree with you about preventing people from shooting themselves in the leg, but I guess I think people don't use |
This comment has been minimized.
This comment has been minimized.
I totally agree that this curiosity is insignificant for users. But I still worry more about the implementation side of the issue, and a lint warning does not help here. |
huonw commentedNov 11, 2015
These are all legal, and somewhat strange, since they're not really following the file-system analogy that modules are typically explained with. I expect this behaviour is just whatever happens to fall out of the current implementation strategy, so let's make a more explicit decision one way or another.
As one might expect, each of these is a distinct instance of
foo(which can be verified by placinglog_syntax(hello)infoo.rs: the compiler will greet you 3 times).Noticed in https://users.rust-lang.org/t/are-module-declarations-allowed-inside-functions/3583 .