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,18 +71,15 @@ 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 {
while level > current_level {

View file

@ -152,34 +152,31 @@ impl CmdRenderer {
impl CmdRenderer {
fn handle_render_command_error(&self, ctx: &RenderContext, error: io::Error) -> Result<()> {
match error.kind() {
ErrorKind::NotFound => {
// Look for "output.{self.name}.optional".
// If it exists and is true, treat this as a warning.
// Otherwise, fail the build.
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.
let optional_key = format!("output.{}.optional", self.name);
let optional_key = format!("output.{}.optional", self.name);
let is_optional = match ctx.config.get(&optional_key) {
Some(Value::Boolean(value)) => *value,
_ => false,
};
let is_optional = match ctx.config.get(&optional_key) {
Some(Value::Boolean(value)) => *value,
_ => false,
};
if is_optional {
warn!(
"The command `{}` for backend `{}` was not found, \
but was marked as optional.",
self.cmd, self.name
);
return Ok(());
} else {
error!(
"The command `{}` wasn't found, is the `{}` backend installed?",
self.cmd, self.name
);
}
if is_optional {
warn!(
"The command `{}` for backend `{}` was not found, \
but was marked as optional.",
self.cmd, self.name
);
return Ok(());
} else {
error!(
"The command `{}` wasn't found, is the `{}` backend installed?",
self.cmd, self.name
);
}
_ => {}
}
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,11 +43,9 @@ pub fn take_anchored_lines(s: &str, anchor: &str) -> String {
}
}
}
} else {
if let Some(cap) = ANCHOR_START.captures(l) {
if &cap["anchor_name"] == anchor {
anchor_found = true;
}
} else if let Some(cap) = ANCHOR_START.captures(l) {
if &cap["anchor_name"] == anchor {
anchor_found = true;
}
}
}
@ -96,16 +94,14 @@ pub fn take_rustdoc_include_anchored_lines(s: &str, anchor: &str) -> String {
}
}
}
} else {
if let Some(cap) = ANCHOR_START.captures(l) {
if &cap["anchor_name"] == anchor {
within_anchored_section = true;
}
} else if !ANCHOR_END.is_match(l) {
output.push_str("# ");
output.push_str(l);
output.push_str("\n");
} else if let Some(cap) = ANCHOR_START.captures(l) {
if &cap["anchor_name"] == anchor {
within_anchored_section = true;
}
} else if !ANCHOR_END.is_match(l) {
output.push_str("# ");
output.push_str(l);
output.push_str("\n");
}
}