Skip to content

Commit 3c54a4d

Browse files
authored
Merge pull request #2083 from ehuss/fix-clippy
Apply some clippy fixes
2 parents cf9de82 + c3155e2 commit 3c54a4d

File tree

18 files changed

+56
-64
lines changed

18 files changed

+56
-64
lines changed

src/book/book.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ fn create_missing(src_dir: &Path, summary: &Summary) -> Result<()> {
3939
.chain(summary.suffix_chapters.iter())
4040
.collect();
4141

42-
while !items.is_empty() {
43-
let next = items.pop().expect("already checked");
44-
42+
while let Some(next) = items.pop() {
4543
if let SummaryItem::Link(ref link) = *next {
4644
if let Some(ref location) = link.location {
4745
let filename = src_dir.join(location);
@@ -277,7 +275,7 @@ fn load_chapter<P: AsRef<Path>>(
277275
}
278276

279277
let stripped = location
280-
.strip_prefix(&src_dir)
278+
.strip_prefix(src_dir)
281279
.expect("Chapters are always inside a book");
282280

283281
Chapter::new(&link.name, content, stripped, parent_names.clone())
@@ -317,7 +315,7 @@ impl<'a> Iterator for BookItems<'a> {
317315
fn next(&mut self) -> Option<Self::Item> {
318316
let item = self.items.pop_front();
319317

320-
if let Some(&BookItem::Chapter(ref ch)) = item {
318+
if let Some(BookItem::Chapter(ch)) = item {
321319
// if we wanted a breadth-first iterator we'd `extend()` here
322320
for sub_item in ch.sub_items.iter().rev() {
323321
self.items.push_front(sub_item);

src/book/init.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ impl BookBuilder {
198198
writeln!(f, "- [Chapter 1](./chapter_1.md)")?;
199199

200200
let chapter_1 = src_dir.join("chapter_1.md");
201-
let mut f =
202-
File::create(&chapter_1).with_context(|| "Unable to create chapter_1.md")?;
201+
let mut f = File::create(chapter_1).with_context(|| "Unable to create chapter_1.md")?;
203202
writeln!(f, "# Chapter 1")?;
204203
} else {
205204
trace!("Existing summary found, no need to create stub files.");
@@ -212,10 +211,10 @@ impl BookBuilder {
212211
fs::create_dir_all(&self.root)?;
213212

214213
let src = self.root.join(&self.config.book.src);
215-
fs::create_dir_all(&src)?;
214+
fs::create_dir_all(src)?;
216215

217216
let build = self.root.join(&self.config.build.build_dir);
218-
fs::create_dir_all(&build)?;
217+
fs::create_dir_all(build)?;
219218

220219
Ok(())
221220
}

src/book/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl MDBook {
9999
let root = book_root.into();
100100

101101
let src_dir = root.join(&config.book.src);
102-
let book = book::load_book(&src_dir, &config.build)?;
102+
let book = book::load_book(src_dir, &config.build)?;
103103

104104
let renderers = determine_renderers(&config);
105105
let preprocessors = determine_preprocessors(&config)?;
@@ -122,7 +122,7 @@ impl MDBook {
122122
let root = book_root.into();
123123

124124
let src_dir = root.join(&config.book.src);
125-
let book = book::load_book_from_disk(&summary, &src_dir)?;
125+
let book = book::load_book_from_disk(&summary, src_dir)?;
126126

127127
let renderers = determine_renderers(&config);
128128
let preprocessors = determine_preprocessors(&config)?;
@@ -309,7 +309,7 @@ impl MDBook {
309309
info!("Testing chapter '{}': {:?}", ch.name, chapter_path);
310310

311311
// write preprocessed file to tempdir
312-
let path = temp_dir.path().join(&chapter_path);
312+
let path = temp_dir.path().join(chapter_path);
313313
let mut tmpf = utils::fs::create_file(&path)?;
314314
tmpf.write_all(ch.content.as_bytes())?;
315315

@@ -319,13 +319,13 @@ impl MDBook {
319319
if let Some(edition) = self.config.rust.edition {
320320
match edition {
321321
RustEdition::E2015 => {
322-
cmd.args(&["--edition", "2015"]);
322+
cmd.args(["--edition", "2015"]);
323323
}
324324
RustEdition::E2018 => {
325-
cmd.args(&["--edition", "2018"]);
325+
cmd.args(["--edition", "2018"]);
326326
}
327327
RustEdition::E2021 => {
328-
cmd.args(&["--edition", "2021"]);
328+
cmd.args(["--edition", "2021"]);
329329
}
330330
}
331331
}

src/cmd/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn make_subcommand() -> Command {
1616
// Build command implementation
1717
pub fn execute(args: &ArgMatches) -> Result<()> {
1818
let book_dir = get_book_dir(args);
19-
let mut book = MDBook::load(&book_dir)?;
19+
let mut book = MDBook::load(book_dir)?;
2020

2121
if let Some(dest_dir) = args.get_one::<PathBuf>("dest-dir") {
2222
book.config.build.build_dir = dest_dir.into();

src/cmd/clean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn make_subcommand() -> Command {
1616
// Clean command implementation
1717
pub fn execute(args: &ArgMatches) -> mdbook::errors::Result<()> {
1818
let book_dir = get_book_dir(args);
19-
let book = MDBook::load(&book_dir)?;
19+
let book = MDBook::load(book_dir)?;
2020

2121
let dir_to_remove = match args.get_one::<PathBuf>("dest-dir") {
2222
Some(dest_dir) => dest_dir.into(),

src/cmd/init.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
8686
/// Obtains author name from git config file by running the `git config` command.
8787
fn get_author_name() -> Option<String> {
8888
let output = Command::new("git")
89-
.args(&["config", "--get", "user.name"])
89+
.args(["config", "--get", "user.name"])
9090
.output()
9191
.ok()?;
9292

@@ -116,5 +116,5 @@ fn confirm() -> bool {
116116
io::stdout().flush().unwrap();
117117
let mut s = String::new();
118118
io::stdin().read_line(&mut s).ok();
119-
matches!(&*s.trim(), "Y" | "y" | "yes" | "Yes")
119+
matches!(s.trim(), "Y" | "y" | "yes" | "Yes")
120120
}

src/cmd/serve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub fn make_subcommand() -> Command {
4848
// Serve command implementation
4949
pub fn execute(args: &ArgMatches) -> Result<()> {
5050
let book_dir = get_book_dir(args);
51-
let mut book = MDBook::load(&book_dir)?;
51+
let mut book = MDBook::load(book_dir)?;
5252

5353
let port = args.get_one::<String>("port").unwrap();
5454
let hostname = args.get_one::<String>("hostname").unwrap();
@@ -102,7 +102,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
102102
info!("Building book...");
103103

104104
// FIXME: This area is really ugly because we need to re-set livereload :(
105-
let result = MDBook::load(&book_dir).and_then(|mut b| {
105+
let result = MDBook::load(book_dir).and_then(|mut b| {
106106
update_config(&mut b);
107107
b.build()
108108
});

src/cmd/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
4444
let chapter: Option<&str> = args.get_one::<String>("chapter").map(|s| s.as_str());
4545

4646
let book_dir = get_book_dir(args);
47-
let mut book = MDBook::load(&book_dir)?;
47+
let mut book = MDBook::load(book_dir)?;
4848

4949
if let Some(dest_dir) = args.get_one::<PathBuf>("dest-dir") {
5050
book.config.build.build_dir = dest_dir.to_path_buf();

src/cmd/watch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn make_subcommand() -> Command {
2121
// Watch command implementation
2222
pub fn execute(args: &ArgMatches) -> Result<()> {
2323
let book_dir = get_book_dir(args);
24-
let mut book = MDBook::load(&book_dir)?;
24+
let mut book = MDBook::load(book_dir)?;
2525

2626
let update_config = |book: &mut MDBook| {
2727
if let Some(dest_dir) = args.get_one::<PathBuf>("dest-dir") {
@@ -42,7 +42,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
4242

4343
trigger_on_change(&book, |paths, book_dir| {
4444
info!("Files changed: {:?}\nBuilding book...\n", paths);
45-
let result = MDBook::load(&book_dir).and_then(|mut b| {
45+
let result = MDBook::load(book_dir).and_then(|mut b| {
4646
update_config(&mut b);
4747
b.build()
4848
});

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ trait Updateable<'de>: Serialize + Deserialize<'de> {
703703
let mut raw = Value::try_from(&self).expect("unreachable");
704704

705705
if let Ok(value) = Value::try_from(value) {
706-
let _ = raw.insert(key, value);
706+
raw.insert(key, value);
707707
} else {
708708
return;
709709
}

src/preprocess/links.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ where
9393
for link in find_links(s) {
9494
replaced.push_str(&s[previous_end_index..link.start_index]);
9595

96-
match link.render_with_path(&path, chapter_title) {
96+
match link.render_with_path(path, chapter_title) {
9797
Ok(new_content) => {
9898
if depth < MAX_LINK_NESTED_DEPTH {
9999
if let Some(rel_path) = link.link_type.relative_path(path) {
@@ -327,7 +327,7 @@ impl<'a> Link<'a> {
327327
let base = base.as_ref();
328328
match self.link_type {
329329
// omit the escape char
330-
LinkType::Escaped => Ok((&self.link_text[1..]).to_owned()),
330+
LinkType::Escaped => Ok(self.link_text[1..].to_owned()),
331331
LinkType::Include(ref pat, ref range_or_anchor) => {
332332
let target = base.join(pat);
333333

src/renderer/html_handlebars/hbs_renderer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl HtmlHandlebars {
9999
ctx.data.insert("title".to_owned(), json!(title));
100100
ctx.data.insert(
101101
"path_to_root".to_owned(),
102-
json!(utils::fs::path_to_root(&path)),
102+
json!(utils::fs::path_to_root(path)),
103103
);
104104
if let Some(ref section) = ch.number {
105105
ctx.data
@@ -292,7 +292,7 @@ impl HtmlHandlebars {
292292
}
293293
if let Some(fonts_css) = &theme.fonts_css {
294294
if !fonts_css.is_empty() {
295-
write_file(destination, "fonts/fonts.css", &fonts_css)?;
295+
write_file(destination, "fonts/fonts.css", fonts_css)?;
296296
}
297297
}
298298
if !html_config.copy_fonts && theme.fonts_css.is_none() {
@@ -547,7 +547,7 @@ impl Renderer for HtmlHandlebars {
547547
// Print version
548548
let mut print_content = String::new();
549549

550-
fs::create_dir_all(&destination)
550+
fs::create_dir_all(destination)
551551
.with_context(|| "Unexpected error when constructing destination path")?;
552552

553553
let mut is_index = true;

src/renderer/html_handlebars/helpers/navigation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ fn render(
127127

128128
context.insert(
129129
"path_to_root".to_owned(),
130-
json!(utils::fs::path_to_root(&base_path)),
130+
json!(utils::fs::path_to_root(base_path)),
131131
);
132132

133133
chapter

src/renderer/markdown_renderer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ impl Renderer for MarkdownRenderer {
3737
if !ch.is_draft_chapter() {
3838
utils::fs::write_file(
3939
&ctx.destination,
40-
&ch.path.as_ref().expect("Checked path exists before"),
40+
ch.path.as_ref().expect("Checked path exists before"),
4141
ch.content.as_bytes(),
4242
)?;
4343
}
4444
}
4545
}
4646

47-
fs::create_dir_all(&destination)
47+
fs::create_dir_all(destination)
4848
.with_context(|| "Unexpected error when constructing destination path")?;
4949

5050
Ok(())

src/utils/fs.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -210,39 +210,36 @@ mod tests {
210210
};
211211

212212
// Create a couple of files
213-
if let Err(err) = fs::File::create(&tmp.path().join("file.txt")) {
213+
if let Err(err) = fs::File::create(tmp.path().join("file.txt")) {
214214
panic!("Could not create file.txt: {}", err);
215215
}
216-
if let Err(err) = fs::File::create(&tmp.path().join("file.md")) {
216+
if let Err(err) = fs::File::create(tmp.path().join("file.md")) {
217217
panic!("Could not create file.md: {}", err);
218218
}
219-
if let Err(err) = fs::File::create(&tmp.path().join("file.png")) {
219+
if let Err(err) = fs::File::create(tmp.path().join("file.png")) {
220220
panic!("Could not create file.png: {}", err);
221221
}
222-
if let Err(err) = fs::create_dir(&tmp.path().join("sub_dir")) {
222+
if let Err(err) = fs::create_dir(tmp.path().join("sub_dir")) {
223223
panic!("Could not create sub_dir: {}", err);
224224
}
225-
if let Err(err) = fs::File::create(&tmp.path().join("sub_dir/file.png")) {
225+
if let Err(err) = fs::File::create(tmp.path().join("sub_dir/file.png")) {
226226
panic!("Could not create sub_dir/file.png: {}", err);
227227
}
228-
if let Err(err) = fs::create_dir(&tmp.path().join("sub_dir_exists")) {
228+
if let Err(err) = fs::create_dir(tmp.path().join("sub_dir_exists")) {
229229
panic!("Could not create sub_dir_exists: {}", err);
230230
}
231-
if let Err(err) = fs::File::create(&tmp.path().join("sub_dir_exists/file.txt")) {
231+
if let Err(err) = fs::File::create(tmp.path().join("sub_dir_exists/file.txt")) {
232232
panic!("Could not create sub_dir_exists/file.txt: {}", err);
233233
}
234-
if let Err(err) = symlink(
235-
&tmp.path().join("file.png"),
236-
&tmp.path().join("symlink.png"),
237-
) {
234+
if let Err(err) = symlink(tmp.path().join("file.png"), tmp.path().join("symlink.png")) {
238235
panic!("Could not symlink file.png: {}", err);
239236
}
240237

241238
// Create output dir
242-
if let Err(err) = fs::create_dir(&tmp.path().join("output")) {
239+
if let Err(err) = fs::create_dir(tmp.path().join("output")) {
243240
panic!("Could not create output: {}", err);
244241
}
245-
if let Err(err) = fs::create_dir(&tmp.path().join("output/sub_dir_exists")) {
242+
if let Err(err) = fs::create_dir(tmp.path().join("output/sub_dir_exists")) {
246243
panic!("Could not create output/sub_dir_exists: {}", err);
247244
}
248245

@@ -253,22 +250,22 @@ mod tests {
253250
}
254251

255252
// Check if the correct files where created
256-
if !(&tmp.path().join("output/file.txt")).exists() {
253+
if !tmp.path().join("output/file.txt").exists() {
257254
panic!("output/file.txt should exist")
258255
}
259-
if (&tmp.path().join("output/file.md")).exists() {
256+
if tmp.path().join("output/file.md").exists() {
260257
panic!("output/file.md should not exist")
261258
}
262-
if !(&tmp.path().join("output/file.png")).exists() {
259+
if !tmp.path().join("output/file.png").exists() {
263260
panic!("output/file.png should exist")
264261
}
265-
if !(&tmp.path().join("output/sub_dir/file.png")).exists() {
262+
if !tmp.path().join("output/sub_dir/file.png").exists() {
266263
panic!("output/sub_dir/file.png should exist")
267264
}
268-
if !(&tmp.path().join("output/sub_dir_exists/file.txt")).exists() {
265+
if !tmp.path().join("output/sub_dir_exists/file.txt").exists() {
269266
panic!("output/sub_dir/file.png should exist")
270267
}
271-
if !(&tmp.path().join("output/symlink.png")).exists() {
268+
if !tmp.path().join("output/symlink.png").exists() {
272269
panic!("output/symlink.png should exist")
273270
}
274271
}

tests/alternative_backends.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ fn relative_command_path() {
9090
.set("output.html", toml::value::Table::new())
9191
.unwrap();
9292
config.set("output.myrenderer.command", cmd_path).unwrap();
93-
let md = MDBook::init(&temp.path())
93+
let md = MDBook::init(temp.path())
9494
.with_config(config)
9595
.build()
9696
.unwrap();

tests/dummy_book/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ fn recursive_copy<A: AsRef<Path>, B: AsRef<Path>>(from: A, to: B) -> Result<()>
112112
let from = from.as_ref();
113113
let to = to.as_ref();
114114

115-
for entry in WalkDir::new(&from) {
115+
for entry in WalkDir::new(from) {
116116
let entry = entry.with_context(|| "Unable to inspect directory entry")?;
117117

118118
let original_location = entry.path();
119119
let relative = original_location
120-
.strip_prefix(&from)
120+
.strip_prefix(from)
121121
.expect("`original_location` is inside the `from` directory");
122122
let new_location = to.join(relative);
123123

@@ -126,7 +126,7 @@ fn recursive_copy<A: AsRef<Path>, B: AsRef<Path>>(from: A, to: B) -> Result<()>
126126
fs::create_dir_all(parent).with_context(|| "Couldn't create directory")?;
127127
}
128128

129-
fs::copy(&original_location, &new_location)
129+
fs::copy(original_location, &new_location)
130130
.with_context(|| "Unable to copy file contents")?;
131131
}
132132
}

0 commit comments

Comments
 (0)