Skip to content

Commit 2ece700

Browse files
authored
Merge pull request #1890 from lzutao/fix-clippy
Fix clippy warnings
2 parents 4514881 + 75010f3 commit 2ece700

22 files changed

+79
-75
lines changed

src/cli/download_tracker.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ impl DownloadTracker {
212212
struct Duration(f64);
213213

214214
impl fmt::Display for Duration {
215+
#[allow(clippy::many_single_char_names)]
215216
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
216217
// repurposing the alternate mode for ETA
217218
let sec = self.0;
@@ -258,13 +259,13 @@ mod tests {
258259

259260
assert_eq!(DownloadTracker::from_seconds(60), (0, 0, 1, 0));
260261

261-
assert_eq!(DownloadTracker::from_seconds(3600), (0, 1, 0, 0));
262+
assert_eq!(DownloadTracker::from_seconds(3_600), (0, 1, 0, 0));
262263

263-
assert_eq!(DownloadTracker::from_seconds(3600 * 24), (1, 0, 0, 0));
264+
assert_eq!(DownloadTracker::from_seconds(3_600 * 24), (1, 0, 0, 0));
264265

265-
assert_eq!(DownloadTracker::from_seconds(52292), (0, 14, 31, 32));
266+
assert_eq!(DownloadTracker::from_seconds(52_292), (0, 14, 31, 32));
266267

267-
assert_eq!(DownloadTracker::from_seconds(222292), (2, 13, 44, 52));
268+
assert_eq!(DownloadTracker::from_seconds(222_292), (2, 13, 44, 52));
268269
}
269270

270271
}

src/cli/errors.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(clippy::large_enum_variant)]
12
#![allow(dead_code)]
23

34
use crate::rustup_mode::CompletionCommand;

src/cli/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn run_rustup() -> Result<()> {
4848
open_trace_file!(dir)?;
4949
}
5050
let result = run_rustup_inner();
51-
if let Ok(_) = env::var("RUSTUP_TRACE_DIR") {
51+
if env::var("RUSTUP_TRACE_DIR").is_ok() {
5252
close_trace_file!();
5353
}
5454
result

src/cli/rustup_mode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ pub enum CompletionCommand {
11461146
Cargo,
11471147
}
11481148

1149-
static COMPLETIONS: &[(&'static str, CompletionCommand)] = &[
1149+
static COMPLETIONS: &[(&str, CompletionCommand)] = &[
11501150
("rustup", CompletionCommand::Rustup),
11511151
("cargo", CompletionCommand::Cargo),
11521152
];

src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl Cfg {
9595
);
9696
let dist_root = dist_root_server.clone() + "/dist";
9797

98-
let cfg = Cfg {
98+
let cfg = Self {
9999
rustup_dir,
100100
settings_file,
101101
toolchains_dir,

src/diskio/immediate.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
/// threaded code paths.
55
use super::{perform, Executor, Item};
66

7+
#[derive(Default)]
78
pub struct ImmediateUnpacker {}
89
impl ImmediateUnpacker {
9-
pub fn new<'a>() -> ImmediateUnpacker {
10-
ImmediateUnpacker {}
10+
pub fn new() -> Self {
11+
Self {}
1112
}
1213
}
1314

1415
impl Executor for ImmediateUnpacker {
15-
fn dispatch(&mut self, mut item: Item) -> Box<dyn '_ + Iterator<Item = Item>> {
16+
fn dispatch(&mut self, mut item: Item) -> Box<dyn Iterator<Item = Item> + '_> {
1617
perform(&mut item);
1718
Box::new(Some(item).into_iter())
1819
}

src/diskio/mod.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub struct Item {
8989

9090
impl Item {
9191
pub fn make_dir(full_path: PathBuf, mode: u32) -> Self {
92-
Item {
92+
Self {
9393
full_path,
9494
kind: Kind::Directory,
9595
start: 0.0,
@@ -102,7 +102,7 @@ impl Item {
102102

103103
pub fn write_file(full_path: PathBuf, content: Vec<u8>, mode: u32) -> Self {
104104
let len = content.len();
105-
Item {
105+
Self {
106106
full_path,
107107
kind: Kind::File(content),
108108
start: 0.0,
@@ -122,24 +122,24 @@ pub trait Executor {
122122
/// During overload situations previously queued items may
123123
/// need to be completed before the item is accepted:
124124
/// consume the returned iterator.
125-
fn execute(&mut self, mut item: Item) -> Box<dyn '_ + Iterator<Item = Item>> {
125+
fn execute(&mut self, mut item: Item) -> Box<dyn Iterator<Item = Item> + '_> {
126126
item.start = precise_time_s();
127127
self.dispatch(item)
128128
}
129129

130130
/// Actually dispatch a operation.
131131
/// This is called by the default execute() implementation and
132132
/// should not be called directly.
133-
fn dispatch(&mut self, item: Item) -> Box<dyn '_ + Iterator<Item = Item>>;
133+
fn dispatch(&mut self, item: Item) -> Box<dyn Iterator<Item = Item> + '_>;
134134

135135
/// Wrap up any pending operations and iterate over them.
136136
/// All operations submitted before the join will have been
137137
/// returned either through ready/complete or join once join
138138
/// returns.
139-
fn join(&mut self) -> Box<dyn '_ + Iterator<Item = Item>>;
139+
fn join(&mut self) -> Box<dyn Iterator<Item = Item> + '_>;
140140

141141
/// Iterate over completed items.
142-
fn completed(&mut self) -> Box<dyn '_ + Iterator<Item = Item>>;
142+
fn completed(&mut self) -> Box<dyn Iterator<Item = Item> + '_>;
143143
}
144144

145145
/// Trivial single threaded IO to be used from executors.
@@ -200,15 +200,13 @@ pub fn get_executor<'a>(
200200
if let Ok(thread_str) = env::var("RUSTUP_IO_THREADS") {
201201
if thread_str == "disabled" {
202202
Box::new(immediate::ImmediateUnpacker::new())
203+
} else if let Ok(thread_count) = thread_str.parse::<usize>() {
204+
Box::new(threaded::Threaded::new_with_threads(
205+
notify_handler,
206+
thread_count,
207+
))
203208
} else {
204-
if let Ok(thread_count) = thread_str.parse::<usize>() {
205-
Box::new(threaded::Threaded::new_with_threads(
206-
notify_handler,
207-
thread_count,
208-
))
209-
} else {
210-
Box::new(threaded::Threaded::new(notify_handler))
211-
}
209+
Box::new(threaded::Threaded::new(notify_handler))
212210
}
213211
} else {
214212
Box::new(threaded::Threaded::new(notify_handler))

src/diskio/threaded.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl<'a> Threaded<'a> {
8989
}
9090

9191
impl<'a> Executor for Threaded<'a> {
92-
fn dispatch(&mut self, item: Item) -> Box<dyn '_ + Iterator<Item = Item>> {
92+
fn dispatch(&mut self, item: Item) -> Box<dyn Iterator<Item = Item> + '_> {
9393
// Yield any completed work before accepting new work - keep memory
9494
// pressure under control
9595
// - return an iterator that runs until we can submit and then submits
@@ -100,7 +100,7 @@ impl<'a> Executor for Threaded<'a> {
100100
})
101101
}
102102

103-
fn join(&mut self) -> Box<dyn '_ + Iterator<Item = Item>> {
103+
fn join(&mut self) -> Box<dyn Iterator<Item = Item> + '_> {
104104
// Some explanation is in order. Even though the tar we are reading from (if
105105
// any) will have had its FileWithProgress download tracking
106106
// completed before we hit drop, that is not true if we are unwinding due to a
@@ -115,16 +115,14 @@ impl<'a> Executor for Threaded<'a> {
115115
// items, and the download tracker's progress is confounded with
116116
// actual handling of data today, we synthesis a data buffer and
117117
// pretend to have bytes to deliver.
118-
self.notify_handler
119-
.map(|handler| handler(Notification::DownloadFinished));
120-
self.notify_handler
121-
.map(|handler| handler(Notification::DownloadPushUnits("iops")));
122118
let mut prev_files = self.n_files.load(Ordering::Relaxed);
123-
self.notify_handler.map(|handler| {
119+
if let Some(handler) = self.notify_handler {
120+
handler(Notification::DownloadFinished);
121+
handler(Notification::DownloadPushUnits("iops"));
124122
handler(Notification::DownloadContentLengthReceived(
125123
prev_files as u64,
126-
))
127-
});
124+
));
125+
}
128126
if prev_files > 50 {
129127
println!("{} deferred IO operations", prev_files);
130128
}
@@ -139,14 +137,15 @@ impl<'a> Executor for Threaded<'a> {
139137
prev_files = current_files;
140138
current_files = self.n_files.load(Ordering::Relaxed);
141139
let step_count = prev_files - current_files;
142-
self.notify_handler
143-
.map(|handler| handler(Notification::DownloadDataReceived(&buf[0..step_count])));
140+
if let Some(handler) = self.notify_handler {
141+
handler(Notification::DownloadDataReceived(&buf[0..step_count]));
142+
}
144143
}
145144
self.pool.join();
146-
self.notify_handler
147-
.map(|handler| handler(Notification::DownloadFinished));
148-
self.notify_handler
149-
.map(|handler| handler(Notification::DownloadPopUnits));
145+
if let Some(handler) = self.notify_handler {
146+
handler(Notification::DownloadFinished);
147+
handler(Notification::DownloadPopUnits);
148+
}
150149
// close the feedback channel so that blocking reads on it can
151150
// complete. send is atomic, and we know the threads completed from the
152151
// pool join, so this is race-free. It is possible that try_iter is safe
@@ -167,7 +166,7 @@ impl<'a> Executor for Threaded<'a> {
167166
})
168167
}
169168

170-
fn completed(&mut self) -> Box<dyn '_ + Iterator<Item = Item>> {
169+
fn completed(&mut self) -> Box<dyn Iterator<Item = Item> + '_> {
171170
Box::new(JoinIterator {
172171
iter: self.rx.try_iter(),
173172
consume_sentinel: true,

src/dist/component/components.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct Components {
2020

2121
impl Components {
2222
pub fn open(prefix: InstallPrefix) -> Result<Self> {
23-
let c = Components { prefix };
23+
let c = Self { prefix };
2424

2525
// Validate that the metadata uses a format we know
2626
if let Some(v) = c.read_version()? {
@@ -152,7 +152,7 @@ impl ComponentPart {
152152
}
153153
pub fn decode(line: &str) -> Option<Self> {
154154
line.find(':')
155-
.map(|pos| ComponentPart(line[0..pos].to_owned(), PathBuf::from(&line[(pos + 1)..])))
155+
.map(|pos| Self(line[0..pos].to_owned(), PathBuf::from(&line[(pos + 1)..])))
156156
}
157157
}
158158

src/dist/component/package.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl DirectoryPackage {
5252
.lines()
5353
.map(std::borrow::ToOwned::to_owned)
5454
.collect();
55-
Ok(DirectoryPackage {
55+
Ok(Self {
5656
path,
5757
components,
5858
copy,
@@ -165,7 +165,7 @@ struct MemoryBudget {
165165

166166
// Probably this should live in diskio but ¯\_(ツ)_/¯
167167
impl MemoryBudget {
168-
fn new(max_file_size: usize) -> MemoryBudget {
168+
fn new(max_file_size: usize) -> Self {
169169
const DEFAULT_UNPACK_RAM: usize = 400 * 1024 * 1024;
170170
let unpack_ram = if let Ok(budget_str) = env::var("RUSTUP_UNPACK_RAM") {
171171
if let Ok(budget) = budget_str.parse::<usize>() {
@@ -179,7 +179,7 @@ impl MemoryBudget {
179179
if max_file_size > unpack_ram {
180180
panic!("RUSTUP_UNPACK_RAM must be larger than {}", max_file_size);
181181
}
182-
MemoryBudget {
182+
Self {
183183
limit: unpack_ram,
184184
used: 0,
185185
}

src/dist/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl Config {
2222
let components =
2323
Self::toml_to_components(components, &format!("{}{}.", path, "components"))?;
2424

25-
Ok(Config {
25+
Ok(Self {
2626
config_version: version,
2727
components,
2828
})
@@ -77,7 +77,7 @@ impl Config {
7777

7878
impl Default for Config {
7979
fn default() -> Self {
80-
Config {
80+
Self {
8181
config_version: DEFAULT_CONFIG_VERSION.to_owned(),
8282
components: Vec::new(),
8383
}

src/dist/dist.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ static TRIPLE_MIPS64_UNKNOWN_LINUX_GNUABI64: &str = "mips64el-unknown-linux-gnua
120120

121121
impl TargetTriple {
122122
pub fn new(name: &str) -> Self {
123-
TargetTriple(name.to_string())
123+
Self(name.to_string())
124124
}
125125

126126
pub fn from_build() -> Self {
127127
if let Some(triple) = option_env!("RUSTUP_OVERRIDE_BUILD_TRIPLE") {
128-
TargetTriple::new(triple)
128+
Self::new(triple)
129129
} else {
130-
TargetTriple::new(env!("TARGET"))
130+
Self::new(env!("TARGET"))
131131
}
132132
}
133133

@@ -207,7 +207,7 @@ impl TargetTriple {
207207
}
208208

209209
if let Ok(triple) = env::var("RUSTUP_OVERRIDE_HOST_TRIPLE") {
210-
Some(TargetTriple(triple))
210+
Some(Self(triple))
211211
} else {
212212
inner()
213213
}
@@ -221,7 +221,7 @@ impl TargetTriple {
221221
impl PartialTargetTriple {
222222
pub fn new(name: &str) -> Option<Self> {
223223
if name.is_empty() {
224-
return Some(PartialTargetTriple {
224+
return Some(Self {
225225
arch: None,
226226
os: None,
227227
env: None,
@@ -250,7 +250,7 @@ impl PartialTargetTriple {
250250
}
251251
}
252252

253-
PartialTargetTriple {
253+
Self {
254254
arch: c.get(1).map(|s| s.as_str()).and_then(fn_map),
255255
os: c.get(2).map(|s| s.as_str()).and_then(fn_map),
256256
env: c.get(3).map(|s| s.as_str()).and_then(fn_map),
@@ -288,7 +288,7 @@ impl FromStr for PartialToolchainDesc {
288288

289289
let trip = c.get(3).map(|c| c.as_str()).unwrap_or("");
290290
let trip = PartialTargetTriple::new(&trip);
291-
trip.map(|t| PartialToolchainDesc {
291+
trip.map(|t| Self {
292292
channel: c.get(1).unwrap().as_str().to_owned(),
293293
date: c.get(2).map(|s| s.as_str()).and_then(fn_map),
294294
target: t,
@@ -382,7 +382,7 @@ impl FromStr for ToolchainDesc {
382382
}
383383
}
384384

385-
ToolchainDesc {
385+
Self {
386386
channel: c.get(1).unwrap().as_str().to_owned(),
387387
date: c.get(2).map(|s| s.as_str()).and_then(fn_map),
388388
target: TargetTriple(c.get(3).unwrap().as_str().to_owned()),

0 commit comments

Comments
 (0)