Skip to content

Commit 538da39

Browse files
committed
---
yaml --- r: 82544 b: refs/heads/auto c: bb7bc6c h: refs/heads/master v: v3
1 parent ae49be6 commit 538da39

File tree

5 files changed

+65
-32
lines changed

5 files changed

+65
-32
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 90e1e8fc4078c05b22b6a4d2716f50db6ec860f7
16+
refs/heads/auto: bb7bc6c584ece3c0f1fc7fe7c60d343975fa516b
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/doc/tutorial.md

Lines changed: 51 additions & 14 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
@@ -2655,7 +2692,7 @@ fn main() {
26552692

26562693
In general, `use` creates an local alias:
26572694
An alternate path and a possibly different name to access the same item,
2658-
without touching the original, and with both being interchangeable.
2695+
whiteout touching the original, and with both being interchangeable.
26592696

26602697
## Reexporting names
26612698

branches/auto/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/auto/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/auto/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)