diff --git a/examples/nop-preprocessor.rs b/examples/nop-preprocessor.rs index 398d7fc784..ee561e95c7 100644 --- a/examples/nop-preprocessor.rs +++ b/examples/nop-preprocessor.rs @@ -26,7 +26,7 @@ fn main() { if let Some(sub_args) = matches.subcommand_matches("supports") { handle_supports(&preprocessor, sub_args); } else if let Err(e) = handle_preprocessing(&preprocessor) { - eprintln!("{}", e); + eprintln!("{e}"); process::exit(1); } } diff --git a/guide/src/for_developers/mdbook-wordcount/src/main.rs b/guide/src/for_developers/mdbook-wordcount/src/main.rs index 607338dd88..c8b2f7e90c 100644 --- a/guide/src/for_developers/mdbook-wordcount/src/main.rs +++ b/guide/src/for_developers/mdbook-wordcount/src/main.rs @@ -26,8 +26,8 @@ fn main() { } let num_words = count_words(ch); - println!("{}: {}", ch.name, num_words); - writeln!(f, "{}: {}", ch.name, num_words).unwrap(); + println!("{}: {num_words}", ch.name); + writeln!(f, "{}: {num_words}", ch.name).unwrap(); if cfg.deny_odds && num_words % 2 == 1 { eprintln!("{} has an odd number of words!", ch.name); diff --git a/guide/src/for_developers/preprocessors.md b/guide/src/for_developers/preprocessors.md index 1ac462561a..10971d7092 100644 --- a/guide/src/for_developers/preprocessors.md +++ b/guide/src/for_developers/preprocessors.md @@ -89,7 +89,7 @@ fn remove_emphasis( }); cmark(events, &mut buf, None).map(|_| buf).map_err(|err| { - Error::from(format!("Markdown serialization failed: {}", err)) + Error::from(format!("Markdown serialization failed: {err}")) }) } ``` diff --git a/src/book/book.rs b/src/book/book.rs index b46843df54..ba24847971 100644 --- a/src/book/book.rs +++ b/src/book/book.rs @@ -18,11 +18,11 @@ pub fn load_book>(src_dir: P, cfg: &BuildConfig) -> Result let mut summary_content = String::new(); File::open(&summary_md) - .with_context(|| format!("Couldn't open SUMMARY.md in {:?} directory", src_dir))? + .with_context(|| format!("Couldn't open SUMMARY.md in {src_dir:?} directory"))? .read_to_string(&mut summary_content)?; let summary = parse_summary(&summary_content) - .with_context(|| format!("Summary parsing failed for file={:?}", summary_md))?; + .with_context(|| format!("Summary parsing failed for file={summary_md:?}"))?; if cfg.create_missing { create_missing(src_dir, &summary).with_context(|| "Unable to create missing chapters")?; @@ -277,7 +277,7 @@ fn load_chapter>( } let stripped = location - .strip_prefix(&src_dir) + .strip_prefix(src_dir) .expect("Chapters are always inside a book"); Chapter::new(&link.name, content, stripped, parent_names.clone()) @@ -317,7 +317,7 @@ impl<'a> Iterator for BookItems<'a> { fn next(&mut self) -> Option { let item = self.items.pop_front(); - if let Some(&BookItem::Chapter(ref ch)) = item { + if let Some(BookItem::Chapter(ch)) = item { // if we wanted a breadth-first iterator we'd `extend()` here for sub_item in ch.sub_items.iter().rev() { self.items.push_front(sub_item); @@ -331,7 +331,7 @@ impl<'a> Iterator for BookItems<'a> { impl Display for Chapter { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { if let Some(ref section_number) = self.number { - write!(f, "{} ", section_number)?; + write!(f, "{section_number} ")?; } write!(f, "{}", self.name) diff --git a/src/book/init.rs b/src/book/init.rs index b3d6dd397a..b3a2415f26 100644 --- a/src/book/init.rs +++ b/src/book/init.rs @@ -86,7 +86,7 @@ impl BookBuilder { match MDBook::load(&self.root) { Ok(book) => Ok(book), Err(e) => { - error!("{}", e); + error!("{e}"); panic!( "The BookBuilder should always create a valid book. If you are seeing this it \ @@ -194,14 +194,13 @@ impl BookBuilder { let summary = src_dir.join("SUMMARY.md"); if !summary.exists() { trace!("No summary found creating stub summary and chapter_1.md."); - let mut f = File::create(&summary).with_context(|| "Unable to create SUMMARY.md")?; + let mut f = File::create(summary).with_context(|| "Unable to create SUMMARY.md")?; writeln!(f, "# Summary")?; writeln!(f)?; writeln!(f, "- [Chapter 1](./chapter_1.md)")?; let chapter_1 = src_dir.join("chapter_1.md"); - let mut f = - File::create(&chapter_1).with_context(|| "Unable to create chapter_1.md")?; + let mut f = File::create(chapter_1).with_context(|| "Unable to create chapter_1.md")?; writeln!(f, "# Chapter 1")?; } else { trace!("Existing summary found, no need to create stub files."); @@ -214,10 +213,10 @@ impl BookBuilder { fs::create_dir_all(&self.root)?; let src = self.root.join(&self.config.book.src); - fs::create_dir_all(&src)?; + fs::create_dir_all(src)?; let build = self.root.join(&self.config.build.build_dir); - fs::create_dir_all(&build)?; + fs::create_dir_all(build)?; Ok(()) } diff --git a/src/book/mod.rs b/src/book/mod.rs index 75bbcc7144..8da610ffb2 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -86,8 +86,8 @@ impl MDBook { } if log_enabled!(log::Level::Trace) { - for line in format!("Config: {:#?}", config).lines() { - trace!("{}", line); + for line in format!("Config: {config:#?}").lines() { + trace!("{line}"); } } @@ -99,7 +99,7 @@ impl MDBook { let root = book_root.into(); let src_dir = root.join(&config.book.src); - let book = book::load_book(&src_dir, &config.build)?; + let book = book::load_book(src_dir, &config.build)?; let renderers = determine_renderers(&config); let preprocessors = determine_preprocessors(&config)?; @@ -122,7 +122,7 @@ impl MDBook { let root = book_root.into(); let src_dir = root.join(&config.book.src); - let book = book::load_book_from_disk(&summary, &src_dir)?; + let book = book::load_book_from_disk(&summary, src_dir)?; let renderers = determine_renderers(&config); let preprocessors = determine_preprocessors(&config)?; @@ -292,7 +292,7 @@ impl MDBook { info!("Testing chapter '{}': {:?}", ch.name, chapter_path); // write preprocessed file to tempdir - let path = temp_dir.path().join(&chapter_path); + let path = temp_dir.path().join(chapter_path); let mut tmpf = utils::fs::create_file(&path)?; tmpf.write_all(ch.content.as_bytes())?; @@ -302,18 +302,18 @@ impl MDBook { if let Some(edition) = self.config.rust.edition { match edition { RustEdition::E2015 => { - cmd.args(&["--edition", "2015"]); + cmd.args(["--edition", "2015"]); } RustEdition::E2018 => { - cmd.args(&["--edition", "2018"]); + cmd.args(["--edition", "2018"]); } RustEdition::E2021 => { - cmd.args(&["--edition", "2021"]); + cmd.args(["--edition", "2021"]); } } } - debug!("running {:?}", cmd); + debug!("running {cmd:?}"); let output = cmd.output()?; if !output.status.success() { @@ -332,7 +332,7 @@ impl MDBook { } if let Some(chapter) = chapter { if !chapter_found { - bail!("Chapter not found: {}", chapter); + bail!("Chapter not found: {chapter}"); } } Ok(()) @@ -441,15 +441,13 @@ fn determine_preprocessors(config: &Config) -> Result> if let Some(before) = table.get("before") { let before = before.as_array().ok_or_else(|| { Error::msg(format!( - "Expected preprocessor.{}.before to be an array", - name + "Expected preprocessor.{name}.before to be an array", )) })?; for after in before { let after = after.as_str().ok_or_else(|| { Error::msg(format!( - "Expected preprocessor.{}.before to contain strings", - name + "Expected preprocessor.{name}.before to contain strings", )) })?; @@ -457,8 +455,7 @@ fn determine_preprocessors(config: &Config) -> Result> // Only warn so that preprocessors can be toggled on and off (e.g. for // troubleshooting) without having to worry about order too much. warn!( - "preprocessor.{}.after contains \"{}\", which was not found", - name, after + "preprocessor.{name}.after contains \"{after}\", which was not found", ); } else { preprocessor_names.add_dependency(name, after); @@ -468,24 +465,19 @@ fn determine_preprocessors(config: &Config) -> Result> if let Some(after) = table.get("after") { let after = after.as_array().ok_or_else(|| { - Error::msg(format!( - "Expected preprocessor.{}.after to be an array", - name - )) + Error::msg(format!("Expected preprocessor.{name}.after to be an array")) })?; for before in after { let before = before.as_str().ok_or_else(|| { Error::msg(format!( - "Expected preprocessor.{}.after to contain strings", - name + "Expected preprocessor.{name}.after to contain strings", )) })?; if !exists(before) { // See equivalent warning above for rationale warn!( - "preprocessor.{}.before contains \"{}\", which was not found", - name, before + "preprocessor.{name}.before contains \"{before}\", which was not found", ); } else { preprocessor_names.add_dependency(before, name); @@ -539,7 +531,7 @@ fn get_custom_preprocessor_cmd(key: &str, table: &Value) -> String { .get("command") .and_then(Value::as_str) .map(ToString::to_string) - .unwrap_or_else(|| format!("mdbook-{}", key)) + .unwrap_or_else(|| format!("mdbook-{key}")) } fn interpret_custom_renderer(key: &str, table: &Value) -> Box { @@ -550,7 +542,7 @@ fn interpret_custom_renderer(key: &str, table: &Value) -> Box { .and_then(Value::as_str) .map(ToString::to_string); - let command = table_dot_command.unwrap_or_else(|| format!("mdbook-{}", key)); + let command = table_dot_command.unwrap_or_else(|| format!("mdbook-{key}")); Box::new(CmdRenderer::new(key.to_string(), command)) } @@ -744,7 +736,7 @@ mod tests { for preprocessor in &preprocessors { eprintln!(" {}", preprocessor.name()); } - panic!("{} should come before {}", before, after); + panic!("{before} should come before {after}"); } }; diff --git a/src/book/summary.rs b/src/book/summary.rs index b2784ce5f6..7dac89125f 100644 --- a/src/book/summary.rs +++ b/src/book/summary.rs @@ -190,7 +190,7 @@ macro_rules! collect_events { loop { let event = $stream.next().map(|(ev, _range)| ev); - trace!("Next event: {:?}", event); + trace!("Next event: {event:?}"); match event { Some($delimiter) => break, @@ -394,7 +394,7 @@ impl<'a> SummaryParser<'a> { items.extend(bunch_of_items); } Some(Event::Start(other_tag)) => { - trace!("Skipping contents of {:?}", other_tag); + trace!("Skipping contents of {other_tag:?}"); // Skip over the contents of this tag while let Some(event) = self.next_event() { @@ -426,7 +426,7 @@ impl<'a> SummaryParser<'a> { /// Push an event back to the tail of the stream. fn back(&mut self, ev: Event<'a>) { assert!(self.back.is_none()); - trace!("Back: {:?}", ev); + trace!("Back: {ev:?}"); self.back = Some(ev); } @@ -438,13 +438,13 @@ impl<'a> SummaryParser<'a> { }) }); - trace!("Next event: {:?}", next); + trace!("Next event: {next:?}"); next } fn parse_nested_numbered(&mut self, parent: &SectionNumber) -> Result> { - debug!("Parsing numbered chapters at level {}", parent); + debug!("Parsing numbered chapters at level {parent}"); let mut items = Vec::new(); loop { @@ -492,8 +492,7 @@ impl<'a> SummaryParser<'a> { let mut number = parent.clone(); number.0.push(num_existing_items as u32 + 1); trace!( - "Found chapter: {} {} ({})", - number, + "Found chapter: {number} {} ({})", link.name, link.location .as_ref() @@ -506,7 +505,7 @@ impl<'a> SummaryParser<'a> { return Ok(SummaryItem::Link(link)); } other => { - warn!("Expected a start of a link, actually got {:?}", other); + warn!("Expected a start of a link, actually got {other:?}"); bail!(self.parse_error( "The link items for nested chapters must only contain a hyperlink" )); @@ -517,12 +516,7 @@ impl<'a> SummaryParser<'a> { fn parse_error(&self, msg: D) -> Error { let (line, col) = self.current_location(); - anyhow::anyhow!( - "failed to parse SUMMARY.md line {}, column {}: {}", - line, - col, - msg - ) + anyhow::anyhow!("failed to parse SUMMARY.md line {line}, column {col}: {msg}") } /// Try to parse the title line. @@ -598,7 +592,7 @@ impl Display for SectionNumber { write!(f, "0") } else { for item in &self.0 { - write!(f, "{}.", item)?; + write!(f, "{item}.")?; } Ok(()) } @@ -745,7 +739,7 @@ mod tests { let href = match parser.stream.next() { Some((Event::Start(Tag::Link(_type, href, _title)), _range)) => href.to_string(), - other => panic!("Unreachable, {:?}", other), + other => panic!("Unreachable, {other:?}"), }; let got = parser.parse_link(href); diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 14a9fec6e2..e40e5c0c72 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -16,7 +16,7 @@ pub fn make_subcommand() -> Command { // Build command implementation pub fn execute(args: &ArgMatches) -> Result<()> { let book_dir = get_book_dir(args); - let mut book = MDBook::load(&book_dir)?; + let mut book = MDBook::load(book_dir)?; if let Some(dest_dir) = args.get_one::("dest-dir") { book.config.build.build_dir = dest_dir.into(); diff --git a/src/cmd/clean.rs b/src/cmd/clean.rs index 3ec605fea4..48b4147ca9 100644 --- a/src/cmd/clean.rs +++ b/src/cmd/clean.rs @@ -16,7 +16,7 @@ pub fn make_subcommand() -> Command { // Clean command implementation pub fn execute(args: &ArgMatches) -> mdbook::errors::Result<()> { let book_dir = get_book_dir(args); - let book = MDBook::load(&book_dir)?; + let book = MDBook::load(book_dir)?; let dir_to_remove = match args.get_one::("dest-dir") { Some(dest_dir) => dest_dir.into(), diff --git a/src/cmd/init.rs b/src/cmd/init.rs index d8ce93d162..9988c2cb71 100644 --- a/src/cmd/init.rs +++ b/src/cmd/init.rs @@ -70,7 +70,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> { }; if let Some(author) = get_author_name() { - debug!("Obtained user name from gitconfig: {:?}", author); + debug!("Obtained user name from gitconfig: {author:?}"); config.book.authors.push(author); builder.with_config(config); } @@ -84,7 +84,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> { /// Obtains author name from git config file by running the `git config` command. fn get_author_name() -> Option { let output = Command::new("git") - .args(&["config", "--get", "user.name"]) + .args(["config", "--get", "user.name"]) .output() .ok()?; @@ -114,5 +114,5 @@ fn confirm() -> bool { io::stdout().flush().unwrap(); let mut s = String::new(); io::stdin().read_line(&mut s).ok(); - matches!(&*s.trim(), "Y" | "y" | "yes" | "Yes") + matches!(s.trim(), "Y" | "y" | "yes" | "Yes") } diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs index 88898567ea..0521f95253 100644 --- a/src/cmd/serve.rs +++ b/src/cmd/serve.rs @@ -48,13 +48,13 @@ pub fn make_subcommand() -> Command { // Serve command implementation pub fn execute(args: &ArgMatches) -> Result<()> { let book_dir = get_book_dir(args); - let mut book = MDBook::load(&book_dir)?; + let mut book = MDBook::load(book_dir)?; let port = args.get_one::("port").unwrap(); let hostname = args.get_one::("hostname").unwrap(); let open_browser = args.get_flag("open"); - let address = format!("{}:{}", hostname, port); + let address = format!("{hostname}:{port}"); let update_config = |book: &mut MDBook| { book.config @@ -89,8 +89,8 @@ pub fn execute(args: &ArgMatches) -> Result<()> { serve(build_dir, sockaddr, reload_tx, &file_404); }); - let serving_url = format!("http://{}", address); - info!("Serving on: {}", serving_url); + let serving_url = format!("http://{address}"); + info!("Serving on: {serving_url}"); if open_browser { open(serving_url); @@ -98,11 +98,11 @@ pub fn execute(args: &ArgMatches) -> Result<()> { #[cfg(feature = "watch")] watch::trigger_on_change(&book, move |paths, book_dir| { - info!("Files changed: {:?}", paths); + info!("Files changed: {paths:?}"); info!("Building book..."); // FIXME: This area is really ugly because we need to re-set livereload :( - let result = MDBook::load(&book_dir).and_then(|mut b| { + let result = MDBook::load(book_dir).and_then(|mut b| { update_config(&mut b); b.build() }); @@ -156,7 +156,7 @@ async fn serve( std::panic::set_hook(Box::new(move |panic_info| { // exit if serve panics - error!("Unable to serve: {}", panic_info); + error!("Unable to serve: {panic_info}"); std::process::exit(1); })); diff --git a/src/cmd/test.rs b/src/cmd/test.rs index 3efe130b11..69f99f4095 100644 --- a/src/cmd/test.rs +++ b/src/cmd/test.rs @@ -44,7 +44,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> { let chapter: Option<&str> = args.get_one::("chapter").map(|s| s.as_str()); let book_dir = get_book_dir(args); - let mut book = MDBook::load(&book_dir)?; + let mut book = MDBook::load(book_dir)?; if let Some(dest_dir) = args.get_one::("dest-dir") { book.config.build.build_dir = dest_dir.to_path_buf(); diff --git a/src/cmd/watch.rs b/src/cmd/watch.rs index bbc6bde712..d1f176edf2 100644 --- a/src/cmd/watch.rs +++ b/src/cmd/watch.rs @@ -20,7 +20,7 @@ pub fn make_subcommand() -> Command { // Watch command implementation pub fn execute(args: &ArgMatches) -> Result<()> { let book_dir = get_book_dir(args); - let mut book = MDBook::load(&book_dir)?; + let mut book = MDBook::load(book_dir)?; let update_config = |book: &mut MDBook| { if let Some(dest_dir) = args.get_one::("dest-dir") { @@ -41,7 +41,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> { trigger_on_change(&book, |paths, book_dir| { info!("Files changed: {:?}\nBuilding book...\n", paths); - let result = MDBook::load(&book_dir).and_then(|mut b| { + let result = MDBook::load(book_dir).and_then(|mut b| { update_config(&mut b); b.build() }); @@ -91,10 +91,7 @@ fn filter_ignored_files(exclusion_checker: gitignore::File, paths: &[PathBuf]) - .filter(|path| match exclusion_checker.is_excluded(path) { Ok(exclude) => !exclude, Err(error) => { - warn!( - "Unable to determine if {:?} is excluded: {:?}. Including it.", - &path, error - ); + warn!("Unable to determine if {path:?} is excluded: {error:?}. Including it."); true } }) @@ -116,7 +113,7 @@ where { Ok(d) => d, Err(e) => { - error!("Error while trying to watch the files:\n\n\t{:?}", e); + error!("Error while trying to watch the files:\n\n\t{e:?}"); std::process::exit(1) } }; @@ -124,7 +121,7 @@ where // Add the source directory to the watcher if let Err(e) = watcher.watch(&book.source_dir(), Recursive) { - error!("Error while watching {:?}:\n {:?}", book.source_dir(), e); + error!("Error while watching {:?}:\n {e:?}", book.source_dir()); std::process::exit(1); }; @@ -136,10 +133,7 @@ where for dir in &book.config.build.extra_watch_dirs { let path = dir.canonicalize().unwrap(); if let Err(e) = watcher.watch(&path, Recursive) { - error!( - "Error while watching extra directory {:?}:\n {:?}", - path, e - ); + error!("Error while watching extra directory {path:?}:\n {e:?}"); std::process::exit(1); } } diff --git a/src/config.rs b/src/config.rs index 0c367d8481..c906486797 100644 --- a/src/config.rs +++ b/src/config.rs @@ -137,7 +137,7 @@ impl Config { env::vars().filter_map(|(key, value)| parse_env(&key).map(|index| (index, value))); for (key, value) in overrides { - trace!("{} => {}", key, value); + trace!("{key} => {value}"); let parsed_value = serde_json::from_str(&value) .unwrap_or_else(|_| serde_json::Value::String(value.to_string())); @@ -145,7 +145,7 @@ impl Config { if let serde_json::Value::Object(ref map) = parsed_value { // To `set` each `key`, we wrap them as `prefix.key` for (k, v) in map { - let full_key = format!("{}.{}", key, k); + let full_key = format!("{key}.{k}"); self.set(&full_key, v).expect("unreachable"); } return; @@ -197,7 +197,7 @@ impl Config { let name = name.as_ref(); match self.get_deserialized_opt(name)? { Some(value) => Ok(value), - None => bail!("Key not found, {:?}", name), + None => bail!("Key not found, {name:?}"), } } @@ -703,7 +703,7 @@ trait Updateable<'de>: Serialize + Deserialize<'de> { let mut raw = Value::try_from(&self).expect("unreachable"); if let Ok(value) = Value::try_from(value) { - let _ = raw.insert(key, value); + raw.insert(key, value); } else { return; } diff --git a/src/main.rs b/src/main.rs index 3e576c5b53..01e2fc1539 100644 --- a/src/main.rs +++ b/src/main.rs @@ -136,7 +136,7 @@ fn get_book_dir(args: &ArgMatches) -> PathBuf { fn open>(path: P) { info!("Opening web browser"); if let Err(e) = opener::open(path) { - error!("Error opening web browser: {}", e); + error!("Error opening web browser: {e}"); } } diff --git a/src/preprocess/cmd.rs b/src/preprocess/cmd.rs index 149dabda56..51ecb26b5e 100644 --- a/src/preprocess/cmd.rs +++ b/src/preprocess/cmd.rs @@ -53,7 +53,7 @@ impl CmdPreprocessor { if let Err(e) = self.write_input(stdin, book, ctx) { // Looks like the backend hung up before we could finish // sending it the render context. Log the error and keep going - warn!("Error writing the RenderContext to the backend, {}", e); + warn!("Error writing the RenderContext to the backend, {e}"); } } @@ -117,7 +117,7 @@ impl Preprocessor for CmdPreprocessor { ) })?; - trace!("{} exited with output: {:?}", self.cmd, output); + trace!("{} exited with output: {output:?}", self.cmd); ensure!( output.status.success(), format!( @@ -136,18 +136,16 @@ impl Preprocessor for CmdPreprocessor { fn supports_renderer(&self, renderer: &str) -> bool { debug!( - "Checking if the \"{}\" preprocessor supports \"{}\"", + "Checking if the \"{}\" preprocessor supports \"{renderer}\"", self.name(), - renderer ); let mut cmd = match self.command() { Ok(c) => c, Err(e) => { warn!( - "Unable to create the command for the \"{}\" preprocessor, {}", + "Unable to create the command for the \"{}\" preprocessor, {e}", self.name(), - e ); return false; } diff --git a/src/preprocess/index.rs b/src/preprocess/index.rs index 004b7eda6e..73d35c8ba2 100644 --- a/src/preprocess/index.rs +++ b/src/preprocess/index.rs @@ -54,8 +54,7 @@ fn warn_readme_name_conflict>(readme_path: P, index_path: P) { .parent() .unwrap_or_else(|| index_path.as_ref()); warn!( - "It seems that there are both {:?} and index.md under \"{}\".", - file_name, + "It seems that there are both {file_name:?} and index.md under \"{}\".", parent_dir.display() ); warn!( diff --git a/src/preprocess/links.rs b/src/preprocess/links.rs index c2c81f5221..364b2ed9a0 100644 --- a/src/preprocess/links.rs +++ b/src/preprocess/links.rs @@ -93,7 +93,7 @@ where for link in find_links(s) { replaced.push_str(&s[previous_end_index..link.start_index]); - match link.render_with_path(&path, chapter_title) { + match link.render_with_path(path, chapter_title) { Ok(new_content) => { if depth < MAX_LINK_NESTED_DEPTH { if let Some(rel_path) = link.link_type.relative_path(path) { @@ -116,9 +116,9 @@ where previous_end_index = link.end_index; } Err(e) => { - error!("Error updating \"{}\", {}", link.link_text, e); + error!("Error updating \"{}\", {e}", link.link_text); for cause in e.chain().skip(1) { - warn!("Caused By: {}", cause); + warn!("Caused By: {cause}"); } // This should make sure we include the raw `{{# ... }}` snippet @@ -327,7 +327,7 @@ impl<'a> Link<'a> { let base = base.as_ref(); match self.link_type { // omit the escape char - LinkType::Escaped => Ok((&self.link_text[1..]).to_owned()), + LinkType::Escaped => Ok(self.link_text[1..].to_owned()), LinkType::Include(ref pat, ref range_or_anchor) => { let target = base.join(pat); @@ -378,12 +378,7 @@ impl<'a> Link<'a> { if !contents.ends_with('\n') { contents.push('\n'); } - Ok(format!( - "```{}{}\n{}```\n", - ftype, - attrs.join(","), - contents - )) + Ok(format!("```{ftype}{}\n{contents}```\n", attrs.join(","))) } LinkType::Title(title) => { *chapter_title = title.to_owned(); @@ -493,7 +488,7 @@ mod tests { let s = "Some random text with {{#playground file.rs}} and {{#playground test.rs }}..."; let res = find_links(s).collect::>(); - println!("\nOUTPUT: {:?}\n", res); + println!("\nOUTPUT: {res:?}\n"); assert_eq!( res, @@ -519,7 +514,7 @@ mod tests { let s = "Some random text with {{#playground foo-bar\\baz/_c++.rs}}..."; let res = find_links(s).collect::>(); - println!("\nOUTPUT: {:?}\n", res); + println!("\nOUTPUT: {res:?}\n"); assert_eq!( res, @@ -536,7 +531,7 @@ mod tests { fn test_find_links_with_range() { let s = "Some random text with {{#include file.rs:10:20}}..."; let res = find_links(s).collect::>(); - println!("\nOUTPUT: {:?}\n", res); + println!("\nOUTPUT: {res:?}\n"); assert_eq!( res, vec![Link { @@ -555,7 +550,7 @@ mod tests { fn test_find_links_with_line_number() { let s = "Some random text with {{#include file.rs:10}}..."; let res = find_links(s).collect::>(); - println!("\nOUTPUT: {:?}\n", res); + println!("\nOUTPUT: {res:?}\n"); assert_eq!( res, vec![Link { @@ -574,7 +569,7 @@ mod tests { fn test_find_links_with_from_range() { let s = "Some random text with {{#include file.rs:10:}}..."; let res = find_links(s).collect::>(); - println!("\nOUTPUT: {:?}\n", res); + println!("\nOUTPUT: {res:?}\n"); assert_eq!( res, vec![Link { @@ -593,7 +588,7 @@ mod tests { fn test_find_links_with_to_range() { let s = "Some random text with {{#include file.rs::20}}..."; let res = find_links(s).collect::>(); - println!("\nOUTPUT: {:?}\n", res); + println!("\nOUTPUT: {res:?}\n"); assert_eq!( res, vec![Link { @@ -612,7 +607,7 @@ mod tests { fn test_find_links_with_full_range() { let s = "Some random text with {{#include file.rs::}}..."; let res = find_links(s).collect::>(); - println!("\nOUTPUT: {:?}\n", res); + println!("\nOUTPUT: {res:?}\n"); assert_eq!( res, vec![Link { @@ -631,7 +626,7 @@ mod tests { fn test_find_links_with_no_range_specified() { let s = "Some random text with {{#include file.rs}}..."; let res = find_links(s).collect::>(); - println!("\nOUTPUT: {:?}\n", res); + println!("\nOUTPUT: {res:?}\n"); assert_eq!( res, vec![Link { @@ -650,7 +645,7 @@ mod tests { fn test_find_links_with_anchor() { let s = "Some random text with {{#include file.rs:anchor}}..."; let res = find_links(s).collect::>(); - println!("\nOUTPUT: {:?}\n", res); + println!("\nOUTPUT: {res:?}\n"); assert_eq!( res, vec![Link { @@ -670,7 +665,7 @@ mod tests { let s = "Some random text with escaped playground \\{{#playground file.rs editable}} ..."; let res = find_links(s).collect::>(); - println!("\nOUTPUT: {:?}\n", res); + println!("\nOUTPUT: {res:?}\n"); assert_eq!( res, @@ -690,7 +685,7 @@ mod tests { more\n text {{#playground my.rs editable no_run should_panic}} ..."; let res = find_links(s).collect::>(); - println!("\nOUTPUT: {:?}\n", res); + println!("\nOUTPUT: {res:?}\n"); assert_eq!( res, vec![ @@ -721,7 +716,7 @@ mod tests { no_run should_panic}} ..."; let res = find_links(s).collect::>(); - println!("\nOUTPUT: {:?}\n", res); + println!("\nOUTPUT: {res:?}\n"); assert_eq!(res.len(), 3); assert_eq!( res[0], diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index e170e2fcda..c32ea80666 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -99,7 +99,7 @@ impl HtmlHandlebars { ctx.data.insert("title".to_owned(), json!(title)); ctx.data.insert( "path_to_root".to_owned(), - json!(utils::fs::path_to_root(&path)), + json!(utils::fs::path_to_root(path)), ); if let Some(ref section) = ch.number { ctx.data @@ -123,7 +123,7 @@ impl HtmlHandlebars { let rendered_index = ctx.handlebars.render("index", &ctx.data)?; let rendered_index = self.post_process(rendered_index, &ctx.html_config.playground, ctx.edition); - debug!("Creating index.html from {}", ctx_path); + debug!("Creating index.html from {ctx_path}"); utils::fs::write_file(&ctx.destination, "index.html", rendered_index.as_bytes())?; } @@ -142,13 +142,13 @@ impl HtmlHandlebars { let content_404 = if let Some(ref filename) = html_config.input_404 { let path = src_dir.join(filename); std::fs::read_to_string(&path) - .with_context(|| format!("unable to open 404 input file {:?}", path))? + .with_context(|| format!("unable to open 404 input file {path:?}"))? } else { // 404 input not explicitly configured try the default file 404.md let default_404_location = src_dir.join("404.md"); if default_404_location.exists() { std::fs::read_to_string(&default_404_location).with_context(|| { - format!("unable to open 404 input file {:?}", default_404_location) + format!("unable to open 404 input file {default_404_location:?}") })? } else { "# Document not found (404)\n\nThis URL is invalid, sorry. Please use the \ @@ -219,7 +219,7 @@ impl HtmlHandlebars { )?; if let Some(cname) = &html_config.cname { - write_file(destination, "CNAME", format!("{}\n", cname).as_bytes())?; + write_file(destination, "CNAME", format!("{cname}\n").as_bytes())?; } write_file(destination, "book.js", &theme.js)?; @@ -298,7 +298,7 @@ impl HtmlHandlebars { the `theme/fonts/` directory." ); } - write_file(destination, "fonts/fonts.css", &fonts_css)?; + write_file(destination, "fonts/fonts.css", fonts_css)?; } } if !html_config.copy_fonts && theme.fonts_css.is_none() { @@ -419,7 +419,7 @@ impl HtmlHandlebars { log::debug!("Emitting redirects"); for (original, new) in redirects { - log::debug!("Redirecting \"{}\" → \"{}\"", original, new); + log::debug!(r#"Redirecting "{original}" → "{new}""#); // Note: all paths are relative to the build directory, so the // leading slash in an absolute path means nothing (and would mess // up `root.join(original)`). @@ -440,9 +440,8 @@ impl HtmlHandlebars { if original.exists() { // sanity check to avoid accidentally overwriting a real file. let msg = format!( - "Not redirecting \"{}\" to \"{}\" because it already exists. Are you sure it needs to be redirected?", + "Not redirecting \"{}\" to \"{destination}\" because it already exists. Are you sure it needs to be redirected?", original.display(), - destination, ); return Err(Error::msg(msg)); } @@ -553,7 +552,7 @@ impl Renderer for HtmlHandlebars { // Print version let mut print_content = String::new(); - fs::create_dir_all(&destination) + fs::create_dir_all(destination) .with_context(|| "Unexpected error when constructing destination path")?; let mut is_index = true; @@ -820,12 +819,7 @@ fn insert_link_into_header( ) -> String { let id = utils::unique_id_from_content(content, id_counter); - format!( - r##"{text}"##, - level = level, - id = id, - text = content - ) + format!(r##"{content}"##) } // The rust book uses annotations for rustdoc to test code snippets, @@ -846,12 +840,7 @@ fn fix_code_blocks(html: &str) -> String { let classes = &caps[2].replace(',', " "); let after = &caps[3]; - format!( - r#""#, - before = before, - classes = classes, - after = after - ) + format!(r#""#) }) .into_owned() } @@ -894,9 +883,7 @@ fn add_playground_pre( // wrap the contents in an external pre block format!( - "
{}
", - classes, - edition_class, + "
{}
", { let content: Cow<'_, str> = if playground_config.editable && classes.contains("editable") @@ -908,14 +895,14 @@ fn add_playground_pre( // we need to inject our own main let (attrs, code) = partition_source(code); - format!("# #![allow(unused)]\n{}#fn main() {{\n{}#}}", attrs, code) + format!("# #![allow(unused)]\n{attrs}#fn main() {{\n{code}#}}") .into() }; hide_lines(&content) } ) } else { - format!("{}", classes, hide_lines(code)) + format!("{}", hide_lines(code)) } } else { // not language-rust, so no-op diff --git a/src/renderer/html_handlebars/helpers/navigation.rs b/src/renderer/html_handlebars/helpers/navigation.rs index b184c4410a..968a670162 100644 --- a/src/renderer/html_handlebars/helpers/navigation.rs +++ b/src/renderer/html_handlebars/helpers/navigation.rs @@ -127,7 +127,7 @@ fn render( context.insert( "path_to_root".to_owned(), - json!(utils::fs::path_to_root(&base_path)), + json!(utils::fs::path_to_root(base_path)), ); chapter diff --git a/src/renderer/html_handlebars/search.rs b/src/renderer/html_handlebars/search.rs index a9e2f5ca61..4324d223a3 100644 --- a/src/renderer/html_handlebars/search.rs +++ b/src/renderer/html_handlebars/search.rs @@ -50,7 +50,7 @@ pub fn create_files(search_config: &Search, destination: &Path, book: &Book) -> utils::fs::write_file( destination, "searchindex.js", - format!("Object.assign(window.search, {});", index).as_bytes(), + format!("Object.assign(window.search, {index});").as_bytes(), )?; utils::fs::write_file(destination, "searcher.js", searcher::JS)?; utils::fs::write_file(destination, "mark.min.js", searcher::MARK_JS)?; @@ -70,7 +70,7 @@ fn add_doc( items: &[&str], ) { let url = if let Some(ref id) = *section_id { - Cow::Owned(format!("{}#{}", anchor_base, id)) + Cow::Owned(format!("{anchor_base}#{id}")) } else { Cow::Borrowed(anchor_base) }; @@ -179,7 +179,7 @@ fn render_item( Event::FootnoteReference(name) => { let len = footnote_numbers.len() + 1; let number = footnote_numbers.entry(name).or_insert(len); - body.push_str(&format!(" [{}] ", number)); + body.push_str(&format!(" [{number}] ")); } Event::TaskListMarker(_checked) => {} } diff --git a/src/renderer/markdown_renderer.rs b/src/renderer/markdown_renderer.rs index 13bd05cc38..1848c63dcc 100644 --- a/src/renderer/markdown_renderer.rs +++ b/src/renderer/markdown_renderer.rs @@ -36,15 +36,15 @@ impl Renderer for MarkdownRenderer { if let BookItem::Chapter(ref ch) = *item { if !ch.is_draft_chapter() { utils::fs::write_file( - &ctx.destination, - &ch.path.as_ref().expect("Checked path exists before"), + destination, + ch.path.as_ref().expect("Checked path exists before"), ch.content.as_bytes(), )?; } } } - fs::create_dir_all(&destination) + fs::create_dir_all(destination) .with_context(|| "Unexpected error when constructing destination path")?; Ok(()) diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 1c97f8f221..14fd82ab6e 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -244,7 +244,7 @@ impl Renderer for CmdRenderer { if let Err(e) = serde_json::to_writer(&mut stdin, &ctx) { // Looks like the backend hung up before we could finish // sending it the render context. Log the error and keep going - warn!("Error writing the RenderContext to the backend, {}", e); + warn!("Error writing the RenderContext to the backend, {e}"); } // explicitly close the `stdin` file handle @@ -254,7 +254,7 @@ impl Renderer for CmdRenderer { .wait() .with_context(|| "Error waiting for the backend to complete")?; - trace!("{} exited with output: {:?}", self.cmd, status); + trace!("{} exited with output: {status:?}", self.cmd); if !status.success() { error!("Renderer exited with non-zero return code."); diff --git a/src/theme/mod.rs b/src/theme/mod.rs index 6e6b509d12..819db66f4e 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -112,7 +112,7 @@ impl Theme { return false; } if let Err(e) = load_file_contents(filename, dest) { - warn!("Couldn't load custom file, {}: {}", filename.display(), e); + warn!("Couldn't load custom file, {}: {e}", filename.display()); false } else { true diff --git a/src/utils/fs.rs b/src/utils/fs.rs index 0d6f383746..b8a9ba01bb 100644 --- a/src/utils/fs.rs +++ b/src/utils/fs.rs @@ -49,7 +49,7 @@ pub fn path_to_root>(path: P) -> String { match c { Component::Normal(_) => s.push_str("../"), _ => { - debug!("Other path component... {:?}", c); + debug!("Other path component... {c:?}"); } } s @@ -64,7 +64,7 @@ pub fn create_file(path: &Path) -> Result { // Construct path if let Some(p) = path.parent() { - trace!("Parent directory is: {:?}", p); + trace!("Parent directory is: {p:?}"); fs::create_dir_all(p)?; } @@ -74,14 +74,12 @@ pub fn create_file(path: &Path) -> Result { /// Removes all the content of a directory but not the directory itself pub fn remove_dir_content(dir: &Path) -> Result<()> { - for item in fs::read_dir(dir)? { - if let Ok(item) = item { - let item = item.path(); - if item.is_dir() { - fs::remove_dir_all(item)?; - } else { - fs::remove_file(item)?; - } + for item in fs::read_dir(dir)?.flatten() { + let item = item.path(); + if item.is_dir() { + fs::remove_dir_all(item)?; + } else { + fs::remove_file(item)?; } } Ok(()) @@ -207,69 +205,66 @@ mod tests { fn copy_files_except_ext_test() { let tmp = match tempfile::TempDir::new() { Ok(t) => t, - Err(e) => panic!("Could not create a temp dir: {}", e), + Err(e) => panic!("Could not create a temp dir: {e}"), }; // Create a couple of files - if let Err(err) = fs::File::create(&tmp.path().join("file.txt")) { - panic!("Could not create file.txt: {}", err); + if let Err(err) = fs::File::create(tmp.path().join("file.txt")) { + panic!("Could not create file.txt: {err}"); } - if let Err(err) = fs::File::create(&tmp.path().join("file.md")) { - panic!("Could not create file.md: {}", err); + if let Err(err) = fs::File::create(tmp.path().join("file.md")) { + panic!("Could not create file.md: {err}"); } - if let Err(err) = fs::File::create(&tmp.path().join("file.png")) { - panic!("Could not create file.png: {}", err); + if let Err(err) = fs::File::create(tmp.path().join("file.png")) { + panic!("Could not create file.png: {err}"); } - if let Err(err) = fs::create_dir(&tmp.path().join("sub_dir")) { - panic!("Could not create sub_dir: {}", err); + if let Err(err) = fs::create_dir(tmp.path().join("sub_dir")) { + panic!("Could not create sub_dir: {err}"); } - if let Err(err) = fs::File::create(&tmp.path().join("sub_dir/file.png")) { - panic!("Could not create sub_dir/file.png: {}", err); + if let Err(err) = fs::File::create(tmp.path().join("sub_dir/file.png")) { + panic!("Could not create sub_dir/file.png: {err}"); } - if let Err(err) = fs::create_dir(&tmp.path().join("sub_dir_exists")) { - panic!("Could not create sub_dir_exists: {}", err); + if let Err(err) = fs::create_dir(tmp.path().join("sub_dir_exists")) { + panic!("Could not create sub_dir_exists: {err}"); } - if let Err(err) = fs::File::create(&tmp.path().join("sub_dir_exists/file.txt")) { - panic!("Could not create sub_dir_exists/file.txt: {}", err); + if let Err(err) = fs::File::create(tmp.path().join("sub_dir_exists/file.txt")) { + panic!("Could not create sub_dir_exists/file.txt: {err}"); } - if let Err(err) = symlink( - &tmp.path().join("file.png"), - &tmp.path().join("symlink.png"), - ) { - panic!("Could not symlink file.png: {}", err); + if let Err(err) = symlink(tmp.path().join("file.png"), tmp.path().join("symlink.png")) { + panic!("Could not symlink file.png: {err}"); } // Create output dir - if let Err(err) = fs::create_dir(&tmp.path().join("output")) { - panic!("Could not create output: {}", err); + if let Err(err) = fs::create_dir(tmp.path().join("output")) { + panic!("Could not create output: {err}"); } - if let Err(err) = fs::create_dir(&tmp.path().join("output/sub_dir_exists")) { - panic!("Could not create output/sub_dir_exists: {}", err); + if let Err(err) = fs::create_dir(tmp.path().join("output/sub_dir_exists")) { + panic!("Could not create output/sub_dir_exists: {err}"); } if let Err(e) = copy_files_except_ext(tmp.path(), &tmp.path().join("output"), true, None, &["md"]) { - panic!("Error while executing the function:\n{:?}", e); + panic!("Error while executing the function:\n{e:?}"); } // Check if the correct files where created - if !(&tmp.path().join("output/file.txt")).exists() { + if !tmp.path().join("output/file.txt").exists() { panic!("output/file.txt should exist") } - if (&tmp.path().join("output/file.md")).exists() { + if tmp.path().join("output/file.md").exists() { panic!("output/file.md should not exist") } - if !(&tmp.path().join("output/file.png")).exists() { + if !tmp.path().join("output/file.png").exists() { panic!("output/file.png should exist") } - if !(&tmp.path().join("output/sub_dir/file.png")).exists() { + if !tmp.path().join("output/sub_dir/file.png").exists() { panic!("output/sub_dir/file.png should exist") } - if !(&tmp.path().join("output/sub_dir_exists/file.txt")).exists() { + if !tmp.path().join("output/sub_dir_exists/file.txt").exists() { panic!("output/sub_dir/file.png should exist") } - if !(&tmp.path().join("output/symlink.png")).exists() { + if !tmp.path().join("output/symlink.png").exists() { panic!("output/symlink.png should exist") } } diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 9f67deda70..b3eba03f93 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -77,7 +77,7 @@ pub fn unique_id_from_content(content: &str, id_counter: &mut HashMap id, - id_count => format!("{}-{}", id, id_count), + id_count => format!("{id}-{id_count}"), }; *id_count += 1; unique_id @@ -105,7 +105,7 @@ fn adjust_links<'a>(event: Event<'a>, path: Option<&Path>) -> Event<'a> { if base.ends_with(".md") { base.replace_range(base.len() - 3.., ".html"); } - return format!("{}{}", base, dest).into(); + return format!("{base}{dest}").into(); } else { return dest; } @@ -121,7 +121,7 @@ fn adjust_links<'a>(event: Event<'a>, path: Option<&Path>) -> Event<'a> { .to_str() .expect("utf-8 paths only"); if !base.is_empty() { - write!(fixed_link, "{}/", base).unwrap(); + write!(fixed_link, "{base}/").unwrap(); } } @@ -154,7 +154,7 @@ fn adjust_links<'a>(event: Event<'a>, path: Option<&Path>) -> Event<'a> { HTML_LINK .replace_all(&html, |caps: ®ex::Captures<'_>| { let fixed = fix(caps[2].into(), path); - format!("{}{}\"", &caps[1], fixed) + format!("{}{fixed}\"", &caps[1]) }) .into_owned() .into() @@ -236,10 +236,10 @@ fn clean_codeblock_headers(event: Event<'_>) -> Event<'_> { /// Prints a "backtrace" of some `Error`. pub fn log_backtrace(e: &Error) { - error!("Error: {}", e); + error!("Error: {e}"); for cause in e.chain().skip(1) { - error!("\tCaused By: {}", cause); + error!("\tCaused By: {cause}"); } } diff --git a/tests/alternative_backends.rs b/tests/alternative_backends.rs index cc7bfc7d9c..3956a8e4eb 100644 --- a/tests/alternative_backends.rs +++ b/tests/alternative_backends.rs @@ -90,7 +90,7 @@ fn relative_command_path() { .set("output.html", toml::value::Table::new()) .unwrap(); config.set("output.myrenderer.command", cmd_path).unwrap(); - let md = MDBook::init(&temp.path()) + let md = MDBook::init(temp.path()) .with_config(config) .build() .unwrap(); @@ -119,13 +119,11 @@ fn dummy_book_with_backend( let mut config = Config::default(); config - .set(format!("output.{}.command", name), command) + .set(format!("output.{name}.command"), command) .unwrap(); if backend_is_optional { - config - .set(format!("output.{}.optional", name), true) - .unwrap(); + config.set(format!("output.{name}.optional"), true).unwrap(); } let md = MDBook::init(temp.path()) diff --git a/tests/dummy_book/mod.rs b/tests/dummy_book/mod.rs index d9d9a068de..6bd268224e 100644 --- a/tests/dummy_book/mod.rs +++ b/tests/dummy_book/mod.rs @@ -84,10 +84,8 @@ pub fn assert_contains_strings>(filename: P, strings: &[&str]) { for s in strings { assert!( content.contains(s), - "Searching for {:?} in {}\n\n{}", - s, + "Searching for {s:?} in {}\n\n{content}", filename.display(), - content ); } } @@ -99,10 +97,8 @@ pub fn assert_doesnt_contain_strings>(filename: P, strings: &[&st for s in strings { assert!( !content.contains(s), - "Found {:?} in {}\n\n{}", - s, + "Found {s:?} in {}\n\n{content}", filename.display(), - content ); } } @@ -112,12 +108,12 @@ fn recursive_copy, B: AsRef>(from: A, to: B) -> Result<()> let from = from.as_ref(); let to = to.as_ref(); - for entry in WalkDir::new(&from) { + for entry in WalkDir::new(from) { let entry = entry.with_context(|| "Unable to inspect directory entry")?; let original_location = entry.path(); let relative = original_location - .strip_prefix(&from) + .strip_prefix(from) .expect("`original_location` is inside the `from` directory"); let new_location = to.join(relative); @@ -126,7 +122,7 @@ fn recursive_copy, B: AsRef>(from: A, to: B) -> Result<()> fs::create_dir_all(parent).with_context(|| "Couldn't create directory")?; } - fs::copy(&original_location, &new_location) + fs::copy(original_location, new_location) .with_context(|| "Unable to copy file contents")?; } } diff --git a/tests/init.rs b/tests/init.rs index 2b6ad507ce..4729b99528 100644 --- a/tests/init.rs +++ b/tests/init.rs @@ -23,7 +23,7 @@ fn base_mdbook_init_should_create_default_content() { for file in &created_files { let target = temp.path().join(file); println!("{}", target.display()); - assert!(target.exists(), "{} doesn't exist", file); + assert!(target.exists(), "{file} doesn't exist"); } let contents = fs::read_to_string(temp.path().join("book.toml")).unwrap(); @@ -59,7 +59,7 @@ fn run_mdbook_init_should_create_content_from_summary() { for file in &created_files { let target = src_dir.join(file); println!("{}", target.display()); - assert!(target.exists(), "{} doesn't exist", file); + assert!(target.exists(), "{file} doesn't exist"); } } @@ -73,8 +73,7 @@ fn run_mdbook_init_with_custom_book_and_src_locations() { for file in &created_files { assert!( !temp.path().join(file).exists(), - "{} shouldn't exist yet!", - file + "{file} shouldn't exist yet!", ); } @@ -88,8 +87,7 @@ fn run_mdbook_init_with_custom_book_and_src_locations() { let target = temp.path().join(file); assert!( target.exists(), - "{} should have been created by `mdbook init`", - file + "{file} should have been created by `mdbook init`", ); } diff --git a/tests/parse_existing_summary_files.rs b/tests/parse_existing_summary_files.rs index 418ec31fee..de7df81d7e 100644 --- a/tests/parse_existing_summary_files.rs +++ b/tests/parse_existing_summary_files.rs @@ -30,7 +30,7 @@ macro_rules! summary_md_test { if let Err(e) = book::parse_summary(&content) { eprintln!("Error parsing {}", filename.display()); eprintln!(); - eprintln!("{:?}", e); + eprintln!("{e:?}"); panic!(); } } diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index a279c4f8e3..795e08da73 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -275,7 +275,7 @@ fn root_index_html() -> Result { .with_context(|| "Book building failed")?; let index_page = temp.path().join("book").join("index.html"); - let html = fs::read_to_string(&index_page).with_context(|| "Unable to read index.html")?; + let html = fs::read_to_string(index_page).with_context(|| "Unable to read index.html")?; Ok(Document::from(html.as_str())) } @@ -412,7 +412,7 @@ fn recursive_includes_are_capped() { let content = &["Around the world, around the world Around the world, around the world Around the world, around the world"]; - assert_contains_strings(&recursive, content); + assert_contains_strings(recursive, content); } #[test] @@ -462,7 +462,7 @@ fn by_default_mdbook_use_index_preprocessor_to_convert_readme_to_index() { let second_index = temp.path().join("book").join("second").join("index.html"); let unexpected_strings = vec!["Second README"]; - assert_doesnt_contain_strings(&second_index, &unexpected_strings); + assert_doesnt_contain_strings(second_index, &unexpected_strings); } #[test] @@ -628,10 +628,8 @@ fn edit_url_has_configured_src_dir_edit_url() { } fn remove_absolute_components(path: &Path) -> impl Iterator + '_ { - path.components().skip_while(|c| match c { - Component::Prefix(_) | Component::RootDir => true, - _ => false, - }) + path.components() + .skip_while(|c| matches!(c, Component::Prefix(_) | Component::RootDir)) } /// Checks formatting of summary names with inline elements. @@ -803,7 +801,7 @@ mod search { let src = read_book_index(temp.path()); let dest = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/searchindex_fixture.json"); - let dest = File::create(&dest).unwrap(); + let dest = File::create(dest).unwrap(); serde_json::to_writer_pretty(dest, &src).unwrap(); src