diff --git a/src/book/book.rs b/src/book/book.rs index c98c03c2..f4870f1f 100644 --- a/src/book/book.rs +++ b/src/book/book.rs @@ -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)?; } diff --git a/src/book/mod.rs b/src/book/mod.rs index 41ae50d9..040e7265 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -37,10 +37,10 @@ pub struct MDBook { pub config: Config, /// A representation of the book's contents in memory. pub book: Book, - renderers: Vec>, + renderers: Vec>, /// List of pre-processors to be run on the book - preprocessors: Vec>, + preprocessors: Vec>, } 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> { - let mut renderers: Vec> = Vec::new(); +fn determine_renderers(config: &Config) -> Vec> { + let mut renderers: Vec> = 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> { renderers } -fn default_preprocessors() -> Vec> { +fn default_preprocessors() -> Vec> { 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>> { +fn determine_preprocessors(config: &Config) -> Result>> { let mut preprocessors = Vec::new(); if config.build.use_default_preprocessors { @@ -432,7 +432,11 @@ fn interpret_custom_renderer(key: &str, table: &Value) -> Box { /// /// 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()); diff --git a/src/book/summary.rs b/src/book/summary.rs index d236d8a1..e61a3459 100644 --- a/src/book/summary.rs +++ b/src/book/summary.rs @@ -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) -> String { +fn stringify_events(events: Vec>) -> String { events .into_iter() .filter_map(|t| match t { @@ -487,7 +487,7 @@ fn stringify_events(events: Vec) -> String { pub struct SectionNumber(pub Vec); 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 { diff --git a/src/lib.rs b/src/lib.rs index 7e350650..60f63e30 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -81,6 +81,7 @@ //! [`Config`]: config/struct.Config.html #![deny(missing_docs)] +#![deny(rust_2018_idioms)] #[macro_use] extern crate error_chain; diff --git a/src/preprocess/links.rs b/src/preprocess/links.rs index d852f706..f5a86905 100644 --- a/src/preprocess/links.rs +++ b/src/preprocess/links.rs @@ -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! { diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 74358fb0..b77edc02 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -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##"]+)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)]?class="([^"]+)".*?>(.*?))"##).unwrap(); regex - .replace_all(html, |caps: &Captures| { + .replace_all(html, |caps: &Captures<'_>| { let text = &caps[1]; let classes = &caps[2]; let code = &caps[3]; diff --git a/src/renderer/html_handlebars/helpers/navigation.rs b/src/renderer/html_handlebars/helpers/navigation.rs index e62ae2f6..dd39400b 100644 --- a/src/renderer/html_handlebars/helpers/navigation.rs +++ b/src/renderer/html_handlebars/helpers/navigation.rs @@ -47,7 +47,7 @@ impl Target { fn find_chapter( ctx: &Context, - rc: &mut RenderContext, + rc: &mut RenderContext<'_>, target: Target, ) -> Result, 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)"); diff --git a/src/renderer/html_handlebars/helpers/theme.rs b/src/renderer/html_handlebars/helpers/theme.rs index 44a4f85f..a42c2f91 100644 --- a/src/renderer/html_handlebars/helpers/theme.rs +++ b/src/renderer/html_handlebars/helpers/theme.rs @@ -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)"); diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 7c7aeb51..8b113676 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -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();