-
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
Path mental model #2155
Path mental model #2155
Conversation
That would be overly verbose and only support those people who want it gone IMO. |
If the main objection to the other RFC is that it contains too many pieces, why do the same thing in an attempt to change it? Further, this is a lot of churn that a) has been brought up before and b) never got any consensus.
|
"File-system" based module system was rejected, no need to mention it again. |
While I agree with your other points, this isn't helpful. RFCs aren't set in stone, and there has always been the intention to open a new eRFC for file system-based modules discovery. |
Okay, so people seem generally opposed to However, nobody has yet commented on the central point of the RFC: that we should not remove |
The other RFC doesn't remove |
Having two ways of doing the same thing is arguably the worst of all worlds from a learnability perspective and is hardly in favor of that feature. I would honestly prefer the file-dir system than having both exist with a lint against neither. On nightly behind a feature gate is fine, but once stabilized we should at least be able to decide one over the other. |
I am positively perplexed.1 I'm fairly certain that you were never able to substitute
mod subdir;
fn main() { }
mod a;
mod b;
pub struct S;
use self::a::S; // error; should have used super::a::S
Footnotes
|
In Interestingly, early modules discussion proposed switching to Go's directory-based packages rather than Rust's file-based modules, which would have made this work everywhere. (This was rejected for making it too hard to find the definitions of items, and also for being too backwards-incompatible.) |
Well... @ExpHP was correct in their analysis. It shows how confusing This is no longer a valid pull request, so I will now close. |
(As opposed to the more usual case of |
@vitiral I believe it's easiest to understand the meaning of Here's how my example can be "desugared" into a single file:
// at this level:
// * `self` is :: (the crate root)
// * `super` is invalid
mod subdir {
// at this level:
// * `self` is ::subdir
// * `super` is :: (the crate root)
mod a {
// at this level:
// * `self` is ::subdir::a
// * `super` is ::subdir
pub struct S;
}
mod b {
// at this level:
// * `self` is ::subdir::b
// * `super` is ::subdir
use self::a::S; // error; should have used super::a::S
}
}
fn main() {} |
P.S. a common example of when mod tests {
#[derive(Copy,Clone,Debug)]
enum Color { Red, Green, Blue }
// Import the variants so that we can write `Red` instead of `Color::Red`.
// Notice that because `Color` is not defined in the crate's root module,
// and because `use` paths are absolute by default,
// we must explicitly `use self::Color::{...}` instead of `use Color::{...}`
use self::Color::{Red, Green, Blue};
#[test]
fn test() {
println!("{:?}", Red);
}
} |
@rpjohnst @ExpHP Thanks for the clarifications, those helped. @steveklabnik I'm not sure if you've heard this before, but my biggest confusion around The confusing thing about Anyway, you being the docs guru I thought you might like to see this, since |
|
This RFC proposes to unify the mental model around paths. It does this by:
foo.rs + foo/
"file-dir" module system from RFC 2126 on the grounds (primarily) that the design contains a critical flaw aroundself::
+super::
and did not have enough discussion within the mega-rfc, so it warrants its own RFCmod foo
to be changed tomod self::foo
, so that explicit paths are used everywhere after RFC 2126 is stabilized.cargo new
createcrate/
instead ofsrc/
so thatuse crate::foo::bar
has an accurate mental map ofcrate/foo/bar.rs
instead ofsrc/foo/bar.rs
Rendered