Merge pull request #1214 from ehuss/fix-clippy

Fix some clippy warnings.
This commit is contained in:
Eric Huss 2020-05-10 08:39:19 -07:00 committed by GitHub
commit 8ee950e3de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 46 additions and 65 deletions

View File

@ -5,6 +5,7 @@
//!
//! [1]: ../index.html
#[allow(clippy::module_inception)]
mod book;
mod init;
mod summary;
@ -126,8 +127,6 @@ impl MDBook {
/// ```no_run
/// # use mdbook::MDBook;
/// # use mdbook::book::BookItem;
/// # #[allow(unused_variables)]
/// # fn main() {
/// # let book = MDBook::load("mybook").unwrap();
/// for item in book.iter() {
/// match *item {
@ -143,7 +142,6 @@ impl MDBook {
/// // 2. Chapter 2
/// //
/// // etc.
/// # }
/// ```
pub fn iter(&self) -> BookItems<'_> {
self.book.iter()
@ -405,7 +403,7 @@ fn interpret_custom_preprocessor(key: &str, table: &Value) -> Box<CmdPreprocesso
.map(ToString::to_string)
.unwrap_or_else(|| format!("mdbook-{}", key));
Box::new(CmdPreprocessor::new(key.to_string(), command.to_string()))
Box::new(CmdPreprocessor::new(key.to_string(), command))
}
fn interpret_custom_renderer(key: &str, table: &Value) -> Box<CmdRenderer> {
@ -418,7 +416,7 @@ fn interpret_custom_renderer(key: &str, table: &Value) -> Box<CmdRenderer> {
let command = table_dot_command.unwrap_or_else(|| format!("mdbook-{}", key));
Box::new(CmdRenderer::new(key.to_string(), command.to_string()))
Box::new(CmdRenderer::new(key.to_string(), command))
}
/// Check whether we should run a particular `Preprocessor` in combination

View File

@ -281,7 +281,7 @@ impl<'a> SummaryParser<'a> {
} else {
Ok(Link {
name,
location: PathBuf::from(href.to_string()),
location: PathBuf::from(href),
number: None,
nested_items: Vec::new(),
})

View File

@ -44,7 +44,7 @@
//! assert_eq!(got, Some(PathBuf::from("./themes")));
//! # Ok(())
//! # }
//! # fn main() { run().unwrap() }
//! # run().unwrap()
//! ```
#![deny(missing_docs)]

View File

@ -82,6 +82,7 @@
#![deny(missing_docs)]
#![deny(rust_2018_idioms)]
#![allow(clippy::comparison_chain)]
#[macro_use]
extern crate error_chain;

View File

@ -75,8 +75,7 @@ fn find_chapter(
// Skip things like "spacer"
chapter.contains_key("path")
})
.skip(1)
.next()
.nth(1)
{
Some(chapter) => return Ok(Some(chapter.clone())),
None => return Ok(None),

View File

@ -32,7 +32,7 @@ impl HelperDef for RenderToc {
.evaluate(ctx, "@root/path")?
.as_json()
.as_str()
.ok_or(RenderError::new("Type error for `path`, string expected"))?
.ok_or_else(|| RenderError::new("Type error for `path`, string expected"))?
.replace("\"", "");
let current_section = rc
@ -46,17 +46,13 @@ impl HelperDef for RenderToc {
.evaluate(ctx, "@root/fold_enable")?
.as_json()
.as_bool()
.ok_or(RenderError::new(
"Type error for `fold_enable`, bool expected",
))?;
.ok_or_else(|| RenderError::new("Type error for `fold_enable`, bool expected"))?;
let fold_level = rc
.evaluate(ctx, "@root/fold_level")?
.as_json()
.as_u64()
.ok_or(RenderError::new(
"Type error for `fold_level`, u64 expected",
))?;
.ok_or_else(|| RenderError::new("Type error for `fold_level`, u64 expected"))?;
out.write("<ol class=\"chapter\">")?;
@ -75,17 +71,14 @@ impl HelperDef for RenderToc {
("", 1)
};
let is_expanded = {
if !fold_enable {
// Disable fold. Expand all chapters.
true
} else if !section.is_empty() && current_section.starts_with(section) {
// The section is ancestor or the current section itself.
let is_expanded =
if !fold_enable || (!section.is_empty() && current_section.starts_with(section)) {
// Expand if folding is disabled, or if the section is an
// ancestor or the current section itself.
true
} else {
// Levels that are larger than this would be folded.
level - 1 < fold_level as usize
}
};
if level > current_level {

View File

@ -152,8 +152,7 @@ impl CmdRenderer {
impl CmdRenderer {
fn handle_render_command_error(&self, ctx: &RenderContext, error: io::Error) -> Result<()> {
match error.kind() {
ErrorKind::NotFound => {
if let ErrorKind::NotFound = error.kind() {
// Look for "output.{self.name}.optional".
// If it exists and is true, treat this as a warning.
// Otherwise, fail the build.
@ -179,8 +178,6 @@ impl CmdRenderer {
);
}
}
_ => {}
}
Err(error).chain_err(|| "Unable to start the backend")?
}
}

View File

@ -28,11 +28,8 @@ pub fn write_file<P: AsRef<Path>>(build_dir: &Path, filename: P, content: &[u8])
/// ```rust
/// # use std::path::Path;
/// # use mdbook::utils::fs::path_to_root;
/// #
/// # fn main() {
/// let path = Path::new("some/relative/path");
/// assert_eq!(path_to_root(path), "../../");
/// # }
/// ```
///
/// **note:** it's not very fool-proof, if you find a situation where

View File

@ -43,14 +43,12 @@ pub fn take_anchored_lines(s: &str, anchor: &str) -> String {
}
}
}
} else {
if let Some(cap) = ANCHOR_START.captures(l) {
} else if let Some(cap) = ANCHOR_START.captures(l) {
if &cap["anchor_name"] == anchor {
anchor_found = true;
}
}
}
}
retained.join("\n")
}
@ -96,8 +94,7 @@ pub fn take_rustdoc_include_anchored_lines(s: &str, anchor: &str) -> String {
}
}
}
} else {
if let Some(cap) = ANCHOR_START.captures(l) {
} else if let Some(cap) = ANCHOR_START.captures(l) {
if &cap["anchor_name"] == anchor {
within_anchored_section = true;
}
@ -107,7 +104,6 @@ pub fn take_rustdoc_include_anchored_lines(s: &str, anchor: &str) -> String {
output.push_str("\n");
}
}
}
output.pop();
output