Deny 2018 edition idioms globally (#911)

This commit is contained in:
lzutao 2019-05-07 03:50:34 +07:00 committed by Dylan DPC
parent ab7802a9a9
commit 581187098c
9 changed files with 40 additions and 35 deletions

View File

@ -82,7 +82,7 @@ impl Book {
}
/// Get a depth-first iterator over the items in the book.
pub fn iter(&self) -> BookItems {
pub fn iter(&self) -> BookItems<'_> {
BookItems {
items: self.sections.iter().collect(),
}
@ -286,7 +286,7 @@ impl<'a> Iterator for BookItems<'a> {
}
impl Display for Chapter {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
if let Some(ref section_number) = self.number {
write!(f, "{} ", section_number)?;
}

View File

@ -37,10 +37,10 @@ pub struct MDBook {
pub config: Config,
/// A representation of the book's contents in memory.
pub book: Book,
renderers: Vec<Box<Renderer>>,
renderers: Vec<Box<dyn Renderer>>,
/// List of pre-processors to be run on the book
preprocessors: Vec<Box<Preprocessor>>,
preprocessors: Vec<Box<dyn Preprocessor>>,
}
impl MDBook {
@ -146,7 +146,7 @@ impl MDBook {
/// // etc.
/// # }
/// ```
pub fn iter(&self) -> BookItems {
pub fn iter(&self) -> BookItems<'_> {
self.book.iter()
}
@ -183,7 +183,7 @@ impl MDBook {
}
/// Run the entire build process for a particular `Renderer`.
fn execute_build_process(&self, renderer: &Renderer) -> Result<()> {
fn execute_build_process(&self, renderer: &dyn Renderer) -> Result<()> {
let mut preprocessed_book = self.book.clone();
let preprocess_ctx = PreprocessorContext::new(
self.root.clone(),
@ -217,7 +217,7 @@ impl MDBook {
Ok(())
}
fn render(&self, preprocessed_book: &Book, renderer: &Renderer) -> Result<()> {
fn render(&self, preprocessed_book: &Book, renderer: &dyn Renderer) -> Result<()> {
let name = renderer.name();
let build_dir = self.build_dir_for(name);
@ -344,8 +344,8 @@ impl MDBook {
}
/// Look at the `Config` and try to figure out what renderers to use.
fn determine_renderers(config: &Config) -> Vec<Box<Renderer>> {
let mut renderers: Vec<Box<Renderer>> = Vec::new();
fn determine_renderers(config: &Config) -> Vec<Box<dyn Renderer>> {
let mut renderers: Vec<Box<dyn Renderer>> = Vec::new();
if let Some(output_table) = config.get("output").and_then(Value::as_table) {
for (key, table) in output_table.iter() {
@ -367,20 +367,20 @@ fn determine_renderers(config: &Config) -> Vec<Box<Renderer>> {
renderers
}
fn default_preprocessors() -> Vec<Box<Preprocessor>> {
fn default_preprocessors() -> Vec<Box<dyn Preprocessor>> {
vec![
Box::new(LinkPreprocessor::new()),
Box::new(IndexPreprocessor::new()),
]
}
fn is_default_preprocessor(pre: &Preprocessor) -> bool {
fn is_default_preprocessor(pre: &dyn Preprocessor) -> bool {
let name = pre.name();
name == LinkPreprocessor::NAME || name == IndexPreprocessor::NAME
}
/// Look at the `MDBook` and try to figure out what preprocessors to run.
fn determine_preprocessors(config: &Config) -> Result<Vec<Box<Preprocessor>>> {
fn determine_preprocessors(config: &Config) -> Result<Vec<Box<dyn Preprocessor>>> {
let mut preprocessors = Vec::new();
if config.build.use_default_preprocessors {
@ -432,7 +432,11 @@ fn interpret_custom_renderer(key: &str, table: &Value) -> Box<CmdRenderer> {
///
/// The `build.use-default-preprocessors` config option can be used to ensure
/// default preprocessors always run if they support the renderer.
fn preprocessor_should_run(preprocessor: &Preprocessor, renderer: &Renderer, cfg: &Config) -> bool {
fn preprocessor_should_run(
preprocessor: &dyn Preprocessor,
renderer: &dyn Renderer,
cfg: &Config,
) -> bool {
// default preprocessors should be run by default (if supported)
if cfg.build.use_default_preprocessors && is_default_preprocessor(preprocessor) {
return preprocessor.supports_renderer(renderer.name());

View File

@ -195,7 +195,7 @@ macro_rules! collect_events {
}
impl<'a> SummaryParser<'a> {
fn new(text: &str) -> SummaryParser {
fn new(text: &str) -> SummaryParser<'_> {
let pulldown_parser = pulldown_cmark::Parser::new(text);
SummaryParser {
@ -471,7 +471,7 @@ fn get_last_link(links: &mut [SummaryItem]) -> Result<(usize, &mut Link)> {
/// Removes the styling from a list of Markdown events and returns just the
/// plain text.
fn stringify_events(events: Vec<Event>) -> String {
fn stringify_events(events: Vec<Event<'_>>) -> String {
events
.into_iter()
.filter_map(|t| match t {
@ -487,7 +487,7 @@ fn stringify_events(events: Vec<Event>) -> String {
pub struct SectionNumber(pub Vec<u32>);
impl Display for SectionNumber {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
if self.0.is_empty() {
write!(f, "0")
} else {

View File

@ -81,6 +81,7 @@
//! [`Config`]: config/struct.Config.html
#![deny(missing_docs)]
#![deny(rust_2018_idioms)]
#[macro_use]
extern crate error_chain;

View File

@ -294,7 +294,7 @@ impl<'a> Iterator for LinkIter<'a> {
}
}
fn find_links(contents: &str) -> LinkIter {
fn find_links(contents: &str) -> LinkIter<'_> {
// lazily compute following regex
// r"\\\{\{#.*\}\}|\{\{#([a-zA-Z0-9]+)\s*([a-zA-Z0-9_.\-:/\\\s]+)\}\}")?;
lazy_static! {

View File

@ -26,7 +26,7 @@ impl HtmlHandlebars {
fn render_item(
&self,
item: &BookItem,
mut ctx: RenderItemContext,
mut ctx: RenderItemContext<'_>,
print_content: &mut String,
) -> Result<()> {
// FIXME: This should be made DRY-er and rely less on mutable state
@ -505,7 +505,7 @@ fn build_header_links(html: &str) -> String {
let mut id_counter = HashMap::new();
regex
.replace_all(html, |caps: &Captures| {
.replace_all(html, |caps: &Captures<'_>| {
let level = caps[1]
.parse()
.expect("Regex should ensure we only ever get numbers here");
@ -552,7 +552,7 @@ fn wrap_header_with_link(
fn fix_code_blocks(html: &str) -> String {
let regex = Regex::new(r##"<code([^>]+)class="([^"]+)"([^>]*)>"##).unwrap();
regex
.replace_all(html, |caps: &Captures| {
.replace_all(html, |caps: &Captures<'_>| {
let before = &caps[1];
let classes = &caps[2].replace(",", " ");
let after = &caps[3];
@ -570,7 +570,7 @@ fn fix_code_blocks(html: &str) -> String {
fn add_playpen_pre(html: &str, playpen_config: &Playpen) -> String {
let regex = Regex::new(r##"((?s)<code[^>]?class="([^"]+)".*?>(.*?)</code>)"##).unwrap();
regex
.replace_all(html, |caps: &Captures| {
.replace_all(html, |caps: &Captures<'_>| {
let text = &caps[1];
let classes = &caps[2];
let code = &caps[3];

View File

@ -47,7 +47,7 @@ impl Target {
fn find_chapter(
ctx: &Context,
rc: &mut RenderContext,
rc: &mut RenderContext<'_>,
target: Target,
) -> Result<Option<StringMap>, RenderError> {
debug!("Get data from context");
@ -86,11 +86,11 @@ fn find_chapter(
}
fn render(
_h: &Helper,
_h: &Helper<'_, '_>,
r: &Handlebars,
ctx: &Context,
rc: &mut RenderContext,
out: &mut Output,
rc: &mut RenderContext<'_>,
out: &mut dyn Output,
chapter: &StringMap,
) -> Result<(), RenderError> {
trace!("Creating BTreeMap to inject in context");
@ -137,11 +137,11 @@ fn render(
}
pub fn previous(
_h: &Helper,
_h: &Helper<'_, '_>,
r: &Handlebars,
ctx: &Context,
rc: &mut RenderContext,
out: &mut Output,
rc: &mut RenderContext<'_>,
out: &mut dyn Output,
) -> Result<(), RenderError> {
trace!("previous (handlebars helper)");
@ -153,11 +153,11 @@ pub fn previous(
}
pub fn next(
_h: &Helper,
_h: &Helper<'_, '_>,
r: &Handlebars,
ctx: &Context,
rc: &mut RenderContext,
out: &mut Output,
rc: &mut RenderContext<'_>,
out: &mut dyn Output,
) -> Result<(), RenderError> {
trace!("next (handlebars helper)");

View File

@ -1,11 +1,11 @@
use handlebars::{Context, Handlebars, Helper, Output, RenderContext, RenderError};
pub fn theme_option(
h: &Helper,
h: &Helper<'_, '_>,
_r: &Handlebars,
ctx: &Context,
rc: &mut RenderContext,
out: &mut Output,
rc: &mut RenderContext<'_>,
out: &mut dyn Output,
) -> Result<(), RenderError> {
trace!("theme_option (handlebars helper)");

View File

@ -157,7 +157,7 @@ impl EventQuoteConverter {
}
}
fn clean_codeblock_headers(event: Event) -> Event {
fn clean_codeblock_headers(event: Event<'_>) -> Event<'_> {
match event {
Event::Start(Tag::CodeBlock(ref info)) => {
let info: String = info.chars().filter(|ch| !ch.is_whitespace()).collect();