Skip to content

Commit 487c3bf

Browse files
committed
---
yaml --- r: 145366 b: refs/heads/try2 c: eb55348 h: refs/heads/master v: v3
1 parent b251e6a commit 487c3bf

File tree

5 files changed

+64
-31
lines changed

5 files changed

+64
-31
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 90e1e8fc4078c05b22b6a4d2716f50db6ec860f7
8+
refs/heads/try2: eb55348a7cb1d99563c9135b8c83bcc20f6346bf
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/doc/tutorial.md

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,7 +2420,8 @@ However, in practice you usually want to split you code up into multiple source
24202420
In order to do that, Rust allows you to move the body of any module into it's own source file, which works like this:
24212421

24222422
If you declare a module without its body, like `mod foo;`, the compiler will look for the
2423-
files `foo.rs` and `foo/mod.rs`. If it finds either, it uses the content of that file as the body of the module.
2423+
files `foo.rs` and `foo/mod.rs` inside some directory (usually the same as of the source file containing
2424+
the `mod foo;`). If it finds either, it uses the content of that file as the body of the module.
24242425
If it finds both, that's a compile error.
24252426

24262427
So, if we want to move the content of `mod farm` into it's own file, it would look like this:
@@ -2446,7 +2447,7 @@ pub mod barn {
24462447
# fn main() { }
24472448
~~~~
24482449

2449-
So, in short `mod foo;` is just syntactic sugar for `mod foo { /* include content of foo.rs or foo/mod.rs here */ }`.
2450+
In short, `mod foo;` is just syntactic sugar for `mod foo { /* content of <...>/foo.rs or <...>/foo/mod.rs */ }`.
24502451

24512452
This also means that having two or more identical `mod foo;` somewhere
24522453
in your crate hierarchy is generally a bad idea,
@@ -2455,14 +2456,14 @@ Both will result in duplicate and mutually incompatible definitions.
24552456

24562457
The directory the compiler looks in for those two files is determined by starting with
24572458
the same directory as the source file that contains the `mod foo;` declaration, and concatenating to that a
2458-
path equivalent to the relative path of all nested `mod { ... }` declarations the `mod foo;` is contained in, if any.
2459+
path equivalent to the relative path of all nested `mod { ... }` declarations the `mod foo;`
2460+
is contained in, if any.
24592461

24602462
For example, given a file with this module body:
24612463

24622464
~~~ {.ignore}
24632465
// src/main.rs
24642466
mod plants;
2465-
mod fungi;
24662467
mod animals {
24672468
mod fish;
24682469
mod mammals {
@@ -2477,25 +2478,61 @@ The compiler would then try all these files:
24772478
src/plants.rs
24782479
src/plants/mod.rs
24792480
2480-
src/fungi.rs
2481-
src/fungi/mod.rs
2482-
24832481
src/animals/fish.rs
24842482
src/animals/fish/mod.rs
24852483
24862484
src/animals/mammals/humans.rs
24872485
src/animals/mammals/humans/mod.rs
24882486
~~~
24892487

2490-
These rules per default result in any directory structure mirroring
2491-
the crates's module hierarchy, and allow you to have both small modules that only need
2492-
to consist of one source file, and big modules that group the source files of submodules together.
2488+
Keep in mind that identical module hierachies can still lead to different path lookups
2489+
depending on how and where you've moved a module body to its own file.
2490+
For example, if we move the `animals` module above into its own file...
2491+
2492+
~~~ {.ignore}
2493+
// src/main.rs
2494+
mod plants;
2495+
mod animals;
2496+
~~~
2497+
~~~ {.ignore}
2498+
// src/animals.rs or src/animals/mod.rs
2499+
mod fish;
2500+
mod mammals {
2501+
mod humans;
2502+
}
2503+
~~~
2504+
...then the source files of `mod animals`'s submodules can
2505+
either be placed right next to that of its parents, or in a subdirectory if `animals` source file is:
2506+
2507+
~~~ {.notrust}
2508+
src/plants.rs
2509+
src/plants/mod.rs
2510+
2511+
src/animals.rs - if file sits next to that of parent module's:
2512+
src/fish.rs
2513+
src/fish/mod.rs
2514+
2515+
src/mammals/humans.rs
2516+
src/mammals/humans/mod.rs
2517+
2518+
src/animals/mod.rs - if file is in it's own subdirectory:
2519+
src/animals/fish.rs
2520+
src/animals/fish/mod.rs
2521+
2522+
src/animals/mammals/humans.rs
2523+
src/animals/mammals/humans/mod.rs
2524+
2525+
~~~
2526+
2527+
These rules allow you to have both small modules that only need
2528+
to consist of one source file each and can be conveniently placed right next to each other,
2529+
and big complicated modules that group the source files of submodules in subdirectories.
24932530

2494-
If you need to circumvent those defaults, you can also overwrite the path a `mod foo;` would take:
2531+
If you need to circumvent the defaults, you can also overwrite the path a `mod foo;` would take:
24952532

24962533
~~~ {.ignore}
2497-
#[path="../../area51/classified.rs"]
2498-
mod alien;
2534+
#[path="../../area51/alien.rs"]
2535+
mod classified;
24992536
~~~
25002537

25012538
## Importing names into the local scope

branches/try2/mk/tools.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ RUSTPKG_INPUTS := $(wildcard $(S)src/librustpkg/*.rs)
2121

2222
# Rustdoc, the documentation tool
2323
RUSTDOC_LIB := $(S)src/librustdoc/rustdoc.rs
24-
RUSTDOC_INPUTS := $(wildcard $(S)src/librustdoc/*.rs)
24+
RUSTDOC_INPUTS := $(wildcard $(addprefix $(S)src/librustdoc/, \
25+
*.rs */*.rs */*/*.rs))
2526

2627
# Rusti, the JIT REPL
2728
RUSTI_LIB := $(S)src/librusti/rusti.rs

branches/try2/src/librustdoc/html/layout.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn render<T: fmt::Default, S: fmt::Default>(
3636
3737
<link href='http://fonts.googleapis.com/css?family=Oswald:700|Inconsolata:400'
3838
rel='stylesheet' type='text/css'>
39-
<link rel=\"stylesheet\" type=\"text/css\" href=\"{root_path}main.css\">
39+
<link rel=\"stylesheet\" type=\"text/css\" href=\"{root_path}{crate}/main.css\">
4040
4141
{favicon, select, none{} other{
4242
<link rel=\"icon\" href=\"#\" sizes=\"16x16\"
@@ -52,7 +52,7 @@ pub fn render<T: fmt::Default, S: fmt::Default>(
5252
5353
<section class=\"sidebar\">
5454
{logo, select, none{} other{
55-
<a href='{root_path}index.html'><img src='#' alt=''/></a>
55+
<a href='{root_path}{crate}/index.html'><img src='#' alt=''/></a>
5656
}}
5757
5858
{sidebar}
@@ -73,9 +73,9 @@ pub fn render<T: fmt::Default, S: fmt::Default>(
7373
<script>
7474
var rootPath = \"{root_path}\";
7575
</script>
76-
<script src=\"{root_path}jquery.js\"></script>
76+
<script src=\"{root_path}{crate}/jquery.js\"></script>
7777
<script src=\"{root_path}{crate}/search-index.js\"></script>
78-
<script src=\"{root_path}main.js\"></script>
78+
<script src=\"{root_path}{crate}/main.js\"></script>
7979
8080
<div id=\"help\" class=\"hidden\">
8181
<div class=\"shortcuts\">

branches/try2/src/librustdoc/html/render.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,15 @@ pub fn run(mut crate: clean::Crate, dst: Path) {
128128
crate = cache.fold_crate(crate);
129129

130130
// Add all the static files
131-
write(cx.dst.push("jquery.js"), include_str!("static/jquery-2.0.3.min.js"));
132-
write(cx.dst.push("main.js"), include_str!("static/main.js"));
133-
write(cx.dst.push("main.css"), include_str!("static/main.css"));
134-
write(cx.dst.push("normalize.css"), include_str!("static/normalize.css"));
135-
write(cx.dst.push("index.html"), format!("
136-
<DOCTYPE html><html><head>
137-
<meta http-equiv='refresh'
138-
content=\"0; url={}/index.html\">
139-
</head><body></body></html>
140-
", crate.name));
131+
let dst = cx.dst.push(crate.name);
132+
mkdir(&dst);
133+
write(dst.push("jquery.js"), include_str!("static/jquery-2.0.3.min.js"));
134+
write(dst.push("main.js"), include_str!("static/main.js"));
135+
write(dst.push("main.css"), include_str!("static/main.css"));
136+
write(dst.push("normalize.css"), include_str!("static/normalize.css"));
141137

142138
{
143-
mkdir(&cx.dst.push(crate.name));
144-
let dst = cx.dst.push(crate.name).push("search-index.js");
139+
let dst = dst.push("search-index.js");
145140
let mut w = BufferedWriter::new(dst.open_writer(io::CreateOrTruncate));
146141
let w = &mut w as &mut io::Writer;
147142
write!(w, "var searchIndex = [");

0 commit comments

Comments
 (0)