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
}

0 commit comments

Comments
 (0)