diff --git a/src/book/book.rs b/src/book/book.rs index b46843df..647a8042 100644 --- a/src/book/book.rs +++ b/src/book/book.rs @@ -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()) diff --git a/src/book/init.rs b/src/book/init.rs index ebcdd934..faca1d09 100644 --- a/src/book/init.rs +++ b/src/book/init.rs @@ -198,8 +198,7 @@ impl BookBuilder { 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."); @@ -212,10 +211,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 33fe93f7..a5e3e78c 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -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)?; @@ -309,7 +309,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())?; @@ -319,13 +319,13 @@ 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"]); } } } diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 14a9fec6..e40e5c0c 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 3ec605fe..48b4147c 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 3a60d975..55d90081 100644 --- a/src/cmd/init.rs +++ b/src/cmd/init.rs @@ -86,7 +86,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()?; diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs index 88898567..eeb19cb3 100644 --- a/src/cmd/serve.rs +++ b/src/cmd/serve.rs @@ -48,7 +48,7 @@ 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(); @@ -102,7 +102,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> { 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() }); diff --git a/src/cmd/test.rs b/src/cmd/test.rs index 3efe130b..69f99f40 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 4cc1b131..e9806e1c 100644 --- a/src/cmd/watch.rs +++ b/src/cmd/watch.rs @@ -21,7 +21,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") { @@ -42,7 +42,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() }); diff --git a/src/preprocess/links.rs b/src/preprocess/links.rs index c2c81f52..0af21196 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) { @@ -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); diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index a7c99225..ee27fd13 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 @@ -292,7 +292,7 @@ impl HtmlHandlebars { } if let Some(fonts_css) = &theme.fonts_css { if !fonts_css.is_empty() { - 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() { @@ -547,7 +547,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; diff --git a/src/renderer/html_handlebars/helpers/navigation.rs b/src/renderer/html_handlebars/helpers/navigation.rs index b184c441..968a6701 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/markdown_renderer.rs b/src/renderer/markdown_renderer.rs index 13bd05cc..4a5a5c2a 100644 --- a/src/renderer/markdown_renderer.rs +++ b/src/renderer/markdown_renderer.rs @@ -37,14 +37,14 @@ impl Renderer for MarkdownRenderer { if !ch.is_draft_chapter() { utils::fs::write_file( &ctx.destination, - &ch.path.as_ref().expect("Checked path exists before"), + 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/utils/fs.rs b/src/utils/fs.rs index 67f7062d..8ad5aad8 100644 --- a/src/utils/fs.rs +++ b/src/utils/fs.rs @@ -210,39 +210,36 @@ mod tests { }; // Create a couple of files - if let Err(err) = fs::File::create(&tmp.path().join("file.txt")) { + 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")) { + 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")) { + 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")) { + 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")) { + 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")) { + 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")) { + 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"), - ) { + 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")) { + 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")) { + if let Err(err) = fs::create_dir(tmp.path().join("output/sub_dir_exists")) { panic!("Could not create output/sub_dir_exists: {}", err); } @@ -253,22 +250,22 @@ mod tests { } // 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/tests/alternative_backends.rs b/tests/alternative_backends.rs index cc7bfc7d..72594e57 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(); diff --git a/tests/dummy_book/mod.rs b/tests/dummy_book/mod.rs index d9d9a068..f91ed9f0 100644 --- a/tests/dummy_book/mod.rs +++ b/tests/dummy_book/mod.rs @@ -112,12 +112,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 +126,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/rendered_output.rs b/tests/rendered_output.rs index 12999b44..886b01a4 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] @@ -803,7 +803,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