Skip to content

Commit bd27b76

Browse files
committed
auto merge of #20802 : huonw/rust/book-css, r=steveklabnik
There is likely to be new users with the alpha release, and there are a lot of documents on the internet (StackOverflow, reddit, blogs) that refer to these guides, so emitting a more helpful error than "404" is nice. Hence, I've temporarily reinstated stub documents for each of the old guides, referring to as relevant a part of the book as possible. Also, rustbook was silently ignoring some errors, which lead to an inconsistency with directory creation/file writing. This meant the CSS file was not being written if no `doc` directory existed in the users build dir (e.g. the buildbots). This should mean that the CSS will appear automatically in later builds.
2 parents 2e2372c + afe260f commit bd27b76

18 files changed

+76
-24
lines changed

Diff for: mk/docs.mk

+7-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ DOCS := index intro tutorial complement-bugreport \
2929
complement-lang-faq complement-design-faq complement-project-faq \
3030
rustdoc reference
3131

32+
# Legacy guides, preserved for a while to reduce the number of 404s
33+
DOCS += guide-crates guide-error-handling guide-ffi guide-macros guide \
34+
guide-ownership guide-plugins guide-pointers guide-strings guide-tasks \
35+
guide-testing
36+
37+
3238
PDF_DOCS := reference
3339

3440
RUSTDOC_DEPS_reference := doc/full-toc.inc
@@ -277,6 +283,6 @@ compiler-docs: $(COMPILER_DOC_TARGETS)
277283

278284
trpl: doc/book/index.html
279285

280-
doc/book/index.html: $(RUSTBOOK_EXE) $(wildcard $(S)/src/doc/trpl/*.md)
286+
doc/book/index.html: $(RUSTBOOK_EXE) $(wildcard $(S)/src/doc/trpl/*.md) | doc/
281287
$(Q)rm -rf doc/book
282288
$(Q)$(RUSTBOOK) build $(S)src/doc/trpl doc/book

Diff for: src/doc/guide-crates.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
% The (old) Rust Crates and Modules Guide
2+
3+
This content has moved into the
4+
[the Rust Programming Language book](book/crates-and-modules.html).

Diff for: src/doc/guide-error-handling.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
% Error Handling in Rust
2+
3+
This content has moved into the
4+
[the Rust Programming Language book](book/error-handling.html).

Diff for: src/doc/guide-ffi.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
% The (old) Rust Foreign Function Interface Guide
2+
3+
This content has moved into the
4+
[the Rust Programming Language book](book/ffi.html).

Diff for: src/doc/guide-macros.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
% The (old) Rust Macros Guide
2+
3+
This content has moved into the
4+
[the Rust Programming Language book](book/macros.html).

Diff for: src/doc/guide-ownership.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
% The (old) Rust Ownership Guide
2+
3+
This content has moved into the
4+
[the Rust Programming Language book](book/ownership.html).

Diff for: src/doc/guide-plugins.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
% The (old) Rust Compiler Plugins Guide
2+
3+
This content has moved into the
4+
[the Rust Programming Language book](book/plugins.html).

Diff for: src/doc/guide-pointers.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
% The (old) Rust Pointer Guide
2+
3+
This content has moved into the
4+
[the Rust Programming Language book](book/pointers.html).

Diff for: src/doc/guide-strings.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
% The (old) Guide to Rust Strings
2+
3+
This content has moved into the
4+
[the Rust Programming Language book](book/strings.html).

Diff for: src/doc/guide-tasks.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
% The (old) Rust Threads and Communication Guide
2+
3+
This content has moved into the
4+
[the Rust Programming Language book](book/tasks.html).

Diff for: src/doc/guide-testing.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
% The (old) Rust Testing Guide
2+
3+
This content has moved into the
4+
[the Rust Programming Language book](book/testing.html).

Diff for: src/doc/guide-unsafe.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
% Writing Safe Low-level and Unsafe Code in Rust
2+
3+
This content has moved into the
4+
[the Rust Programming Language book](book/unsafe.html).

Diff for: src/doc/guide.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
% The (old) Rust Guide
2+
3+
This content has moved into the
4+
[the Rust Programming Language book](book/README.html).

Diff for: src/rustbook/book.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ pub fn parse_summary<R: Reader>(input: R, src: &Path) -> Result<Book, Vec<String
124124
let path_from_root = match src.join(given_path.unwrap()).path_relative_from(src) {
125125
Some(p) => p,
126126
None => {
127-
errors.push(format!("Paths in SUMMARY.md must be relative, \
127+
errors.push(format!("paths in SUMMARY.md must be relative, \
128128
but path '{}' for section '{}' is not.",
129129
given_path.unwrap(), title));
130130
Path::new("")
@@ -148,8 +148,9 @@ pub fn parse_summary<R: Reader>(input: R, src: &Path) -> Result<Book, Vec<String
148148
}).sum() / 4 + 1;
149149

150150
if level > stack.len() + 1 {
151-
// FIXME: better error message
152-
errors.push(format!("Section '{}' is indented too many levels.", item.title));
151+
errors.push(format!("section '{}' is indented too deeply; \
152+
found {}, expected {} or less",
153+
item.title, level, stack.len() + 1));
153154
} else if level <= stack.len() {
154155
collapse(&mut stack, &mut top_items, level);
155156
}

Diff for: src/rustbook/build.rs

+9-18
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ fn write_toc(book: &Book, path_to_root: &Path, out: &mut Writer) -> IoResult<()>
7373
}
7474

7575
fn render(book: &Book, tgt: &Path) -> CliResult<()> {
76-
let tmp = TempDir::new("rust-book")
77-
.ok()
78-
// FIXME: lift to Result instead
79-
.expect("could not create temporary directory");
76+
let tmp = try!(TempDir::new("rust-book"));
8077

8178
for (section, item) in book.iter() {
8279
println!("{} {}", section, item.title);
@@ -163,30 +160,24 @@ impl Subcommand for Build {
163160
tgt = Path::new(os::args()[3].clone());
164161
}
165162

166-
let _ = fs::mkdir(&tgt, io::USER_DIR); // FIXME: handle errors
163+
try!(fs::mkdir(&tgt, io::USER_DIR));
167164

168-
// FIXME: handle errors
169-
let _ = File::create(&tgt.join("rust-book.css")).write_str(css::STYLE);
165+
try!(File::create(&tgt.join("rust-book.css")).write_str(css::STYLE));
170166

171-
let summary = File::open(&src.join("SUMMARY.md"));
167+
let summary = try!(File::open(&src.join("SUMMARY.md")));
172168
match book::parse_summary(summary, &src) {
173169
Ok(book) => {
174170
// execute rustdoc on the whole book
175-
try!(render(&book, &tgt).map_err(|err| {
176-
term.err(&format!("error: {}", err.description())[]);
177-
err.detail().map(|detail| {
178-
term.err(&format!("detail: {}", detail)[]);
179-
});
180-
err
181-
}))
171+
render(&book, &tgt)
182172
}
183173
Err(errors) => {
174+
let n = errors.len();
184175
for err in errors.into_iter() {
185-
term.err(&err[]);
176+
term.err(&format!("error: {}", err)[]);
186177
}
178+
179+
Err(box format!("{} errors occurred", n) as Box<Error>)
187180
}
188181
}
189-
190-
Ok(()) // lol
191182
}
192183
}

Diff for: src/rustbook/css.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// The rust-book CSS in string form.
1212

1313
pub static STYLE: &'static str = r#"
14-
@import url("//static.rust-lang.org/doc/master/rust.css");
14+
@import url("../rust.css");
1515
1616
body {
1717
max-width:none;

Diff for: src/rustbook/error.rs

+1
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,5 @@ impl Error for IoError {
7979
}
8080
}
8181

82+
8283
//fn iter_map_err<T, U, E, I: Iterator<Result<T,E>>>(iter: I,

Diff for: src/rustbook/main.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ fn main() {
5454
Ok(_) => {
5555
match subcmd.execute(&mut term) {
5656
Ok(_) => (),
57-
Err(_) => os::set_exit_status(-1),
57+
Err(err) => {
58+
term.err(&format!("error: {}", err.description())[]);
59+
err.detail().map(|detail| {
60+
term.err(&format!("detail: {}", detail)[]);
61+
});
62+
}
5863
}
5964
}
6065
Err(err) => {

0 commit comments

Comments
 (0)