Skip to content

Commit 8ad8b74

Browse files
committed
Fix lints
1 parent a6e9176 commit 8ad8b74

16 files changed

+68
-72
lines changed

src/cli/self_update.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ pub fn install(
413413

414414
fn rustc_or_cargo_exists_in_path() -> Result<()> {
415415
// Ignore rustc and cargo if present in $HOME/.cargo/bin or a few other directories
416+
#[allow(clippy::ptr_arg)]
416417
fn ignore_paths(path: &PathBuf) -> bool {
417418
!path
418419
.components()

src/cli/self_update/windows.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ fn _apply_new_path(new_path: Option<Vec<u16>>) -> Result<()> {
180180
}
181181

182182
// Tell other processes to update their environment
183+
#[allow(clippy::unnecessary_cast)]
183184
unsafe {
184185
SendMessageTimeoutA(
185186
HWND_BROADCAST,

src/cli/topical_doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn index_html(doc: &DocData<'_>, wpath: &Path) -> Option<PathBuf> {
2222
}
2323
}
2424

25-
fn dir_into_vec(dir: &PathBuf) -> Result<Vec<OsString>> {
25+
fn dir_into_vec(dir: &Path) -> Result<Vec<OsString>> {
2626
let entries = fs::read_dir(dir).chain_err(|| format!("Opening directory {:?}", dir))?;
2727
let mut v = Vec::new();
2828
for entry in entries {

src/config.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ impl<'a> OverrideCfg<'a> {
110110
|| file.toolchain.components.is_some()
111111
|| file.toolchain.profile.is_some()
112112
{
113-
return Err(ErrorKind::CannotSpecifyPathAndOptions(path.into()).into());
113+
return Err(ErrorKind::CannotSpecifyPathAndOptions(path).into());
114114
}
115115
Some(Toolchain::from_path(cfg, cfg_path, &path)?)
116116
}
117117
(Some(channel), Some(path)) => {
118-
return Err(ErrorKind::CannotSpecifyChannelAndPath(channel, path.into()).into())
118+
return Err(ErrorKind::CannotSpecifyChannelAndPath(channel, path).into())
119119
}
120120
(None, None) => None,
121121
},
@@ -172,8 +172,7 @@ impl PgpPublicKey {
172172
Ok(ret)
173173
}
174174
use pgp::types::KeyTrait;
175-
let mut ret = Vec::new();
176-
ret.push(format!("from {}", self));
175+
let mut ret = vec![format!("from {}", self)];
177176
let key = self.key();
178177
let keyid = format_hex(&key.key_id().to_vec(), "-", 4)?;
179178
let algo = key.algorithm();

src/diskio/immediate.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{
1111
time::Instant,
1212
};
1313

14-
use super::{CompletedIO, Executor, Item};
14+
use super::{CompletedIo, Executor, Item};
1515

1616
#[derive(Debug)]
1717
pub struct _IncrementalFileState {
@@ -35,7 +35,7 @@ impl ImmediateUnpacker {
3535
}
3636
}
3737

38-
fn deque(&self) -> Box<dyn Iterator<Item = CompletedIO>> {
38+
fn deque(&self) -> Box<dyn Iterator<Item = CompletedIo>> {
3939
let mut guard = self.incremental_state.lock().unwrap();
4040
// incremental file in progress
4141
if let Some(ref mut state) = *guard {
@@ -52,16 +52,12 @@ impl ImmediateUnpacker {
5252
if state.finished {
5353
*guard = None;
5454
}
55-
Box::new(Some(CompletedIO::Item(item)).into_iter())
55+
Box::new(Some(CompletedIo::Item(item)).into_iter())
5656
} else {
5757
// Case 2: pending chunks (which might be empty)
5858
let mut completed_chunks = vec![];
5959
completed_chunks.append(&mut state.completed_chunks);
60-
Box::new(
61-
completed_chunks
62-
.into_iter()
63-
.map(|size| CompletedIO::Chunk(size)),
64-
)
60+
Box::new(completed_chunks.into_iter().map(CompletedIo::Chunk))
6561
}
6662
} else {
6763
Box::new(None.into_iter())
@@ -70,7 +66,7 @@ impl ImmediateUnpacker {
7066
}
7167

7268
impl Executor for ImmediateUnpacker {
73-
fn dispatch(&self, mut item: Item) -> Box<dyn Iterator<Item = CompletedIO> + '_> {
69+
fn dispatch(&self, mut item: Item) -> Box<dyn Iterator<Item = CompletedIo> + '_> {
7470
item.result = match &mut item.kind {
7571
super::Kind::Directory => super::create_dir(&item.full_path),
7672
super::Kind::File(ref contents) => {
@@ -89,7 +85,7 @@ impl Executor for ImmediateUnpacker {
8985
.start
9086
.map(|s| Instant::now().saturating_duration_since(s));
9187
*guard = None;
92-
Box::new(Some(CompletedIO::Item(item)).into_iter())
88+
Box::new(Some(CompletedIo::Item(item)).into_iter())
9389
} else {
9490
state.item = Some(item);
9591
Box::new(None.into_iter())
@@ -103,20 +99,20 @@ impl Executor for ImmediateUnpacker {
10399
item.finish = item
104100
.start
105101
.map(|s| Instant::now().saturating_duration_since(s));
106-
Box::new(Some(CompletedIO::Item(item)).into_iter())
102+
Box::new(Some(CompletedIo::Item(item)).into_iter())
107103
}
108104

109-
fn join(&mut self) -> Box<dyn Iterator<Item = CompletedIO>> {
105+
fn join(&mut self) -> Box<dyn Iterator<Item = CompletedIo>> {
110106
self.deque()
111107
}
112108

113-
fn completed(&self) -> Box<dyn Iterator<Item = CompletedIO>> {
109+
fn completed(&self) -> Box<dyn Iterator<Item = CompletedIo>> {
114110
self.deque()
115111
}
116112

117113
fn incremental_file_state(&self) -> super::IncrementalFileState {
118114
let mut state = self.incremental_state.lock().unwrap();
119-
if let Some(_) = *state {
115+
if state.is_some() {
120116
unreachable!();
121117
} else {
122118
*state = Some(_IncrementalFileState {
@@ -188,7 +184,7 @@ impl IncrementalFileWriter {
188184
if let Some(ref mut state) = *state {
189185
if let Some(ref mut file) = (&mut self.file).as_mut() {
190186
// Length 0 vector is used for clean EOF signalling.
191-
if chunk.len() == 0 {
187+
if chunk.is_empty() {
192188
trace_scoped!("close", "name:": self.path_display);
193189
drop(std::mem::take(&mut self.file));
194190
state.finished = true;

src/diskio/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub struct Item {
139139
}
140140

141141
#[derive(Debug)]
142-
pub enum CompletedIO {
142+
pub enum CompletedIo {
143143
/// A submitted Item has completed
144144
Item(Item),
145145
/// An IncrementalFile has completed a single chunk
@@ -211,14 +211,14 @@ impl IncrementalFileState {
211211
mode: u32,
212212
) -> Result<(Box<dyn FnMut(Vec<u8>) -> bool>, IncrementalFile)> {
213213
use std::sync::mpsc::channel;
214-
match self {
215-
&IncrementalFileState::Threaded => {
214+
match *self {
215+
IncrementalFileState::Threaded => {
216216
let (tx, rx) = channel::<Vec<u8>>();
217217
let content_callback = IncrementalFile::ThreadedReceiver(rx);
218218
let chunk_submit = move |chunk: Vec<u8>| tx.send(chunk).is_ok();
219219
Ok((Box::new(chunk_submit), content_callback))
220220
}
221-
&IncrementalFileState::Immediate(ref state) => {
221+
IncrementalFileState::Immediate(ref state) => {
222222
let content_callback = IncrementalFile::ImmediateReceiver;
223223
let mut writer = immediate::IncrementalFileWriter::new(path, mode, state.clone())?;
224224
let chunk_submit = move |chunk: Vec<u8>| writer.chunk_submit(chunk);
@@ -236,24 +236,24 @@ pub trait Executor {
236236
/// During overload situations previously queued items may
237237
/// need to be completed before the item is accepted:
238238
/// consume the returned iterator.
239-
fn execute(&self, mut item: Item) -> Box<dyn Iterator<Item = CompletedIO> + '_> {
239+
fn execute(&self, mut item: Item) -> Box<dyn Iterator<Item = CompletedIo> + '_> {
240240
item.start = Some(Instant::now());
241241
self.dispatch(item)
242242
}
243243

244244
/// Actually dispatch a operation.
245245
/// This is called by the default execute() implementation and
246246
/// should not be called directly.
247-
fn dispatch(&self, item: Item) -> Box<dyn Iterator<Item = CompletedIO> + '_>;
247+
fn dispatch(&self, item: Item) -> Box<dyn Iterator<Item = CompletedIo> + '_>;
248248

249249
/// Wrap up any pending operations and iterate over them.
250250
/// All operations submitted before the join will have been
251251
/// returned either through ready/complete or join once join
252252
/// returns.
253-
fn join(&mut self) -> Box<dyn Iterator<Item = CompletedIO> + '_>;
253+
fn join(&mut self) -> Box<dyn Iterator<Item = CompletedIo> + '_>;
254254

255255
/// Iterate over completed items.
256-
fn completed(&self) -> Box<dyn Iterator<Item = CompletedIO> + '_>;
256+
fn completed(&self) -> Box<dyn Iterator<Item = CompletedIo> + '_>;
257257

258258
/// Get any state needed for incremental file processing
259259
fn incremental_file_state(&self) -> IncrementalFileState;

src/diskio/test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ fn test_incremental_file(io_threads: &str) -> Result<()> {
3535
loop {
3636
for work in io_executor.completed().collect::<Vec<_>>() {
3737
match work {
38-
super::CompletedIO::Chunk(size) => written += size,
39-
super::CompletedIO::Item(item) => unreachable!(format!("{:?}", item)),
38+
super::CompletedIo::Chunk(size) => written += size,
39+
super::CompletedIo::Item(item) => unreachable!(format!("{:?}", item)),
4040
}
4141
}
4242
if written == 20 {
@@ -48,8 +48,8 @@ fn test_incremental_file(io_threads: &str) -> Result<()> {
4848
loop {
4949
for work in io_executor.completed().collect::<Vec<_>>() {
5050
match work {
51-
super::CompletedIO::Chunk(_) => unreachable!(),
52-
super::CompletedIO::Item(_) => {
51+
super::CompletedIo::Chunk(_) => unreachable!(),
52+
super::CompletedIo::Item(_) => {
5353
file_finished = true;
5454
}
5555
}

src/diskio/threaded.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ use std::sync::atomic::{AtomicUsize, Ordering};
99
use std::sync::mpsc::{channel, Receiver, Sender};
1010
use std::sync::Arc;
1111

12-
use super::{perform, CompletedIO, Executor, Item};
12+
use super::{perform, CompletedIo, Executor, Item};
1313
use crate::utils::notifications::Notification;
1414
use crate::utils::units::Unit;
1515

1616
enum Task {
17-
Request(CompletedIO),
17+
Request(CompletedIo),
1818
// Used to synchronise in the join method.
1919
Sentinel,
2020
}
@@ -60,19 +60,19 @@ impl<'a> Threaded<'a> {
6060
let n_files = self.n_files.clone();
6161
self.pool.execute(move || {
6262
let chunk_complete_callback = |size| {
63-
tx.send(Task::Request(CompletedIO::Chunk(size)))
63+
tx.send(Task::Request(CompletedIo::Chunk(size)))
6464
.expect("receiver should be listening")
6565
};
6666
perform(&mut item, chunk_complete_callback);
6767
n_files.fetch_sub(1, Ordering::Relaxed);
68-
tx.send(Task::Request(CompletedIO::Item(item)))
68+
tx.send(Task::Request(CompletedIo::Item(item)))
6969
.expect("receiver should be listening");
7070
});
7171
}
7272
}
7373

7474
impl<'a> Executor for Threaded<'a> {
75-
fn dispatch(&self, item: Item) -> Box<dyn Iterator<Item = CompletedIO> + '_> {
75+
fn dispatch(&self, item: Item) -> Box<dyn Iterator<Item = CompletedIo> + '_> {
7676
// Yield any completed work before accepting new work - keep memory
7777
// pressure under control
7878
// - return an iterator that runs until we can submit and then submits
@@ -83,7 +83,7 @@ impl<'a> Executor for Threaded<'a> {
8383
})
8484
}
8585

86-
fn join(&mut self) -> Box<dyn Iterator<Item = CompletedIO> + '_> {
86+
fn join(&mut self) -> Box<dyn Iterator<Item = CompletedIo> + '_> {
8787
// Some explanation is in order. Even though the tar we are reading from (if
8888
// any) will have had its FileWithProgress download tracking
8989
// completed before we hit drop, that is not true if we are unwinding due to a
@@ -149,7 +149,7 @@ impl<'a> Executor for Threaded<'a> {
149149
})
150150
}
151151

152-
fn completed(&self) -> Box<dyn Iterator<Item = CompletedIO> + '_> {
152+
fn completed(&self) -> Box<dyn Iterator<Item = CompletedIo> + '_> {
153153
Box::new(JoinIterator {
154154
iter: self.rx.try_iter(),
155155
consume_sentinel: true,
@@ -174,9 +174,9 @@ struct JoinIterator<T: Iterator<Item = Task>> {
174174
}
175175

176176
impl<T: Iterator<Item = Task>> Iterator for JoinIterator<T> {
177-
type Item = CompletedIO;
177+
type Item = CompletedIo;
178178

179-
fn next(&mut self) -> Option<CompletedIO> {
179+
fn next(&mut self) -> Option<CompletedIo> {
180180
let task_o = self.iter.next();
181181
match task_o {
182182
None => None,
@@ -200,9 +200,9 @@ struct SubmitIterator<'a, 'b> {
200200
}
201201

202202
impl<'a, 'b> Iterator for SubmitIterator<'a, 'b> {
203-
type Item = CompletedIO;
203+
type Item = CompletedIo;
204204

205-
fn next(&mut self) -> Option<CompletedIO> {
205+
fn next(&mut self) -> Option<CompletedIo> {
206206
// The number here is arbitrary; just a number to stop exhausting fd's on linux
207207
// and still allow rapid decompression to generate work to dispatch
208208
// This function could perhaps be tuned: e.g. it may wait in rx.iter()

src/dist/component/package.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::path::{Path, PathBuf};
1010

1111
use tar::EntryType;
1212

13-
use crate::diskio::{get_executor, CompletedIO, Executor, Item, Kind};
13+
use crate::diskio::{get_executor, CompletedIo, Executor, Item, Kind};
1414
use crate::dist::component::components::*;
1515
use crate::dist::component::transaction::*;
1616
use crate::dist::temp;
@@ -204,14 +204,14 @@ impl MemoryBudget {
204204
}
205205
}
206206

207-
fn reclaim(&mut self, op: &CompletedIO) {
207+
fn reclaim(&mut self, op: &CompletedIo) {
208208
match &op {
209-
CompletedIO::Item(op) => match &op.kind {
209+
CompletedIo::Item(op) => match &op.kind {
210210
Kind::Directory => {}
211211
Kind::File(content) => self.used -= content.len(),
212212
Kind::IncrementalFile(_) => {}
213213
},
214-
CompletedIO::Chunk(size) => self.used -= size,
214+
CompletedIo::Chunk(size) => self.used -= size,
215215
}
216216
}
217217

@@ -234,8 +234,8 @@ impl MemoryBudget {
234234

235235
/// Handle the async result of io operations
236236
/// Replaces op.result with Ok(())
237-
fn filter_result(op: &mut CompletedIO) -> io::Result<()> {
238-
if let CompletedIO::Item(op) = op {
237+
fn filter_result(op: &mut CompletedIo) -> io::Result<()> {
238+
if let CompletedIo::Item(op) = op {
239239
let result = mem::replace(&mut op.result, Ok(()));
240240
match result {
241241
Ok(_) => Ok(()),
@@ -268,10 +268,10 @@ fn trigger_children(
268268
io_executor: &dyn Executor,
269269
directories: &mut HashMap<PathBuf, DirStatus>,
270270
budget: &mut MemoryBudget,
271-
op: CompletedIO,
271+
op: CompletedIo,
272272
) -> Result<usize> {
273273
let mut result = 0;
274-
if let CompletedIO::Item(item) = op {
274+
if let CompletedIo::Item(item) = op {
275275
if let Kind::Directory = item.kind {
276276
let mut pending = Vec::new();
277277
directories
@@ -510,12 +510,9 @@ fn unpack_without_first_dir<'a, R: Read>(
510510
filter_result(&mut item).chain_err(|| ErrorKind::ExtractingPackage)?;
511511
trigger_children(&*io_executor, &mut directories, &mut budget, item)?;
512512
}
513-
let mut incremental_file_sender =
514-
if let Some(incremental_file_sender) = incremental_file_sender {
515-
Some((incremental_file_sender, &mut entry))
516-
} else {
517-
None
518-
};
513+
514+
let mut incremental_file_sender = incremental_file_sender
515+
.map(|incremental_file_sender| (incremental_file_sender, &mut entry));
519516

520517
// monitor io queue and feed in the content of the file (if needed)
521518
while !flush_ios(

src/dist/component/transaction.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,12 @@ impl<'a> ChangedItem<'a> {
229229
}
230230
Ok(())
231231
}
232-
fn dest_abs_path(
233-
prefix: &InstallPrefix,
234-
component: &str,
235-
relpath: &PathBuf,
236-
) -> Result<PathBuf> {
232+
fn dest_abs_path(prefix: &InstallPrefix, component: &str, relpath: &Path) -> Result<PathBuf> {
237233
let abs_path = prefix.abs_path(relpath);
238234
if utils::path_exists(&abs_path) {
239235
Err(ErrorKind::ComponentConflict {
240236
name: component.to_owned(),
241-
path: relpath.clone(),
237+
path: relpath.to_path_buf(),
242238
}
243239
.into())
244240
} else {

src/dist/dist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,13 @@ impl<'a> Manifest<'a> {
407407
ext: &str,
408408
) -> Result<Option<String>> {
409409
let suffix = target_triple.to_owned() + ext;
410-
Ok(utils::match_file("manifest", &self.0, |line| {
410+
utils::match_file("manifest", &self.0, |line| {
411411
if line.starts_with(package) && line.ends_with(&suffix) {
412412
Some(format!("{}/{}", &self.1, line))
413413
} else {
414414
None
415415
}
416-
})?)
416+
})
417417
}
418418
}
419419

0 commit comments

Comments
 (0)