From 01301d99517a3bac767a2d2ab9547fdc2ceb2761 Mon Sep 17 00:00:00 2001 From: Michael Bryan Date: Sat, 8 Jul 2017 17:55:00 +0800 Subject: [PATCH] Started cleaning up some of the lints and warnings --- Cargo.toml | 1 - src/lib.rs | 3 --- src/loader/book.rs | 9 ++++++++- src/loader/mod.rs | 3 ++- src/loader/summary.rs | 10 +++------- tests/loading.rs | 5 ++--- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c88c3815..1ba96365 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,6 @@ ws = { version = "0.7", optional = true} # Tests [dev-dependencies] tempdir = "0.3.4" -pretty_assertions = "0.2.1" [build-dependencies] error-chain = "0.10" diff --git a/src/lib.rs b/src/lib.rs index beec449e..9ad46c3d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -86,9 +86,6 @@ extern crate serde; #[macro_use] extern crate serde_json; -#[cfg(test)] -#[macro_use] -extern crate pretty_assertions; #[cfg(test)] extern crate tempdir; diff --git a/src/loader/book.rs b/src/loader/book.rs index f253eea4..803c4020 100644 --- a/src/loader/book.rs +++ b/src/loader/book.rs @@ -122,6 +122,13 @@ fn load_chapter>(link: &Link, src_dir: P) -> Result { } /// A depth-first iterator over the items in a book. +/// +/// # Note +/// +/// This struct shouldn't be created directly, instead prefer the +/// [`Book::iter()`] method. +/// +/// [`Book::iter()`]: struct.Book.html#method.iter pub struct BookItems<'a> { items: VecDeque<&'a BookItem>, } @@ -239,7 +246,7 @@ And here is some more text. #[test] fn load_a_book_with_a_single_chapter() { - let (link, temp) = dummy_link(); + let (link, _temp) = dummy_link(); let summary = Summary { numbered_chapters: vec![SummaryItem::Link(link)], ..Default::default() diff --git a/src/loader/mod.rs b/src/loader/mod.rs index bf3e8ae2..0209497f 100644 --- a/src/loader/mod.rs +++ b/src/loader/mod.rs @@ -18,7 +18,7 @@ #![deny(missing_docs)] -use std::path::{Path, PathBuf}; +use std::path::Path; use std::fs::File; use std::io::Read; use errors::*; @@ -27,6 +27,7 @@ mod summary; mod book; pub use self::book::{Book, BookItems, BookItem, Chapter}; +pub use self::summary::SectionNumber; use self::book::load_book_from_disk; use self::summary::parse_summary; diff --git a/src/loader/summary.rs b/src/loader/summary.rs index 88ad7d02..c2dfe03f 100644 --- a/src/loader/summary.rs +++ b/src/loader/summary.rs @@ -2,7 +2,6 @@ use std::fmt::{self, Formatter, Display}; use std::ops::{Deref, DerefMut}; use std::path::{Path, PathBuf}; use pulldown_cmark::{self, Event, Tag}; - use errors::*; @@ -248,7 +247,7 @@ impl<'a> SummaryParser<'a> { match self.state { State::Begin => self.step_start(next_event)?, State::PrefixChapters => self.step_prefix(next_event)?, - State::NumberedChapters(n) => self.step_numbered(next_event, n)?, + State::NumberedChapters(_) => self.step_numbered(next_event)?, State::SuffixChapters => self.step_suffix(next_event)?, State::End => {}, } @@ -316,7 +315,7 @@ impl<'a> SummaryParser<'a> { /// section and need to parse the suffix section. /// /// Otherwise, ignore the event. - fn step_numbered(&mut self, event: Event, nesting: u32) -> Result<()> { + fn step_numbered(&mut self, event: Event) -> Result<()> { match event { Event::Start(Tag::Item) => { let it = self.parse_item().chain_err( @@ -448,10 +447,6 @@ fn push_item_at_nesting_level(links: &mut Vec, mut item: SummaryIte links.push(item); Ok(section_number) } else { - let next_level = level - 1; - let index_for_item = links.len() + 1; - - // FIXME: This bit needs simplifying! let (index, last_link) = get_last_link(links).chain_err(|| { format!("The list of links needs to be {} levels deeper (current position {})", level, section_number) @@ -465,6 +460,7 @@ fn push_item_at_nesting_level(links: &mut Vec, mut item: SummaryIte /// Gets a pointer to the last `Link` in a list of `SummaryItem`s, and its /// index. fn get_last_link(links: &mut [SummaryItem]) -> Result<(usize, &mut Link)> { + // TODO: This should probably be integrated into `Link::push_item()` links .iter_mut() .enumerate() diff --git a/tests/loading.rs b/tests/loading.rs index 62a5361e..50ff4f10 100644 --- a/tests/loading.rs +++ b/tests/loading.rs @@ -1,10 +1,7 @@ //! Integration tests for loading a book into memory -#[macro_use] -extern crate pretty_assertions; extern crate mdbook; extern crate env_logger; -extern crate tempdir; use std::path::PathBuf; @@ -13,6 +10,8 @@ use mdbook::loader::load_book; #[test] fn load_the_example_book() { + env_logger::init().ok(); + let example_src_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")) .join("book-example") .join("src");