Skip to content

Commit 08972a6

Browse files
authored
Merge pull request #2802 from hi-rustin/rustin-patch-clippy-needless-borrow
Make clippy happy
2 parents 31a98d3 + 21ac6a3 commit 08972a6

25 files changed

+106
-110
lines changed

download/tests/read-proxy-env.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn socks_proxy_request() {
6363
}
6464
});
6565

66-
let env_proxy = |url: &Url| for_url(&url).to_url();
66+
let env_proxy = |url: &Url| for_url(url).to_url();
6767
let url = Url::parse("http://192.168.0.1/").unwrap();
6868

6969
let client = Client::builder()

src/cli/common.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::fs;
44
use std::io::{BufRead, ErrorKind, Write};
55
use std::path::Path;
66
use std::sync::Arc;
7-
use std::{cmp, env, iter};
7+
use std::{cmp, env};
88

99
use anyhow::{anyhow, Context, Result};
1010
use git_testament::{git_testament, render_testament};
@@ -229,7 +229,7 @@ fn show_channel_updates(cfg: &Cfg, toolchains: Vec<(String, Result<UpdateStatus>
229229

230230
for (name, banner, width, color, version, previous_version) in data {
231231
let padding = max_width - width;
232-
let padding: String = iter::repeat(' ').take(padding).collect();
232+
let padding: String = " ".repeat(padding);
233233
let _ = write!(t, " {}", padding);
234234
let _ = t.attr(term2::Attr::Bold);
235235
if let Some(color) = color {
@@ -356,7 +356,7 @@ where
356356

357357
pub(crate) fn list_targets(toolchain: &Toolchain<'_>) -> Result<utils::ExitCode> {
358358
let mut t = term2::stdout();
359-
let distributable = DistributableToolchain::new_for_components(&toolchain)?;
359+
let distributable = DistributableToolchain::new_for_components(toolchain)?;
360360
let components = distributable.list_components()?;
361361
for component in components {
362362
if component.component.short_name_in_manifest() == "rust-std" {
@@ -380,7 +380,7 @@ pub(crate) fn list_targets(toolchain: &Toolchain<'_>) -> Result<utils::ExitCode>
380380

381381
pub(crate) fn list_installed_targets(toolchain: &Toolchain<'_>) -> Result<utils::ExitCode> {
382382
let mut t = term2::stdout();
383-
let distributable = DistributableToolchain::new_for_components(&toolchain)?;
383+
let distributable = DistributableToolchain::new_for_components(toolchain)?;
384384
let components = distributable.list_components()?;
385385
for component in components {
386386
if component.component.short_name_in_manifest() == "rust-std" {
@@ -399,7 +399,7 @@ pub(crate) fn list_installed_targets(toolchain: &Toolchain<'_>) -> Result<utils:
399399

400400
pub(crate) fn list_components(toolchain: &Toolchain<'_>) -> Result<utils::ExitCode> {
401401
let mut t = term2::stdout();
402-
let distributable = DistributableToolchain::new_for_components(&toolchain)?;
402+
let distributable = DistributableToolchain::new_for_components(toolchain)?;
403403
let components = distributable.list_components()?;
404404
for component in components {
405405
let name = component.name;
@@ -417,7 +417,7 @@ pub(crate) fn list_components(toolchain: &Toolchain<'_>) -> Result<utils::ExitCo
417417

418418
pub(crate) fn list_installed_components(toolchain: &Toolchain<'_>) -> Result<utils::ExitCode> {
419419
let mut t = term2::stdout();
420-
let distributable = DistributableToolchain::new_for_components(&toolchain)?;
420+
let distributable = DistributableToolchain::new_for_components(toolchain)?;
421421
let components = distributable.list_components()?;
422422
for component in components {
423423
if component.installed {

src/cli/proxy_mode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn main(arg0: &str) -> Result<ExitCode> {
3535

3636
let cfg = set_globals(false, true)?;
3737
cfg.check_metadata_version()?;
38-
direct_proxy(&cfg, &arg0, toolchain, &cmd_args)?
38+
direct_proxy(&cfg, arg0, toolchain, &cmd_args)?
3939
};
4040

4141
process::exit(c)

src/cli/rustup_mode.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::fmt;
22
use std::io::Write;
3-
use std::iter;
43
use std::path::{Path, PathBuf};
54
use std::process::Command;
65
use std::str::FromStr;
@@ -892,7 +891,7 @@ fn check_updates(cfg: &Cfg) -> Result<utils::ExitCode> {
892891
for channel in channels {
893892
match channel {
894893
(ref name, Ok(ref toolchain)) => {
895-
let distributable = DistributableToolchain::new(&toolchain)?;
894+
let distributable = DistributableToolchain::new(toolchain)?;
896895
let current_version = distributable.show_version()?;
897896
let dist_version = distributable.show_dist_version()?;
898897
let _ = t.attr(term2::Attr::Bold);
@@ -1200,7 +1199,7 @@ fn show(cfg: &Cfg) -> Result<utils::ExitCode> {
12001199
{
12011200
t.attr(term2::Attr::Bold)?;
12021201
writeln!(t, "{}", s)?;
1203-
writeln!(t, "{}", iter::repeat("-").take(s.len()).collect::<String>())?;
1202+
writeln!(t, "{}", "-".repeat(s.len()))?;
12041203
writeln!(t)?;
12051204
t.reset()?;
12061205
Ok(())
@@ -1465,7 +1464,7 @@ fn override_remove(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
14651464
for path in paths {
14661465
if cfg
14671466
.settings_file
1468-
.with_mut(|s| Ok(s.remove_override(&Path::new(&path), cfg.notify_handler.as_ref())))?
1467+
.with_mut(|s| Ok(s.remove_override(Path::new(&path), cfg.notify_handler.as_ref())))?
14691468
{
14701469
info!("override toolchain for '{}' removed", path);
14711470
} else {
@@ -1582,7 +1581,7 @@ fn set_default_host_triple(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitC
15821581
}
15831582

15841583
fn set_profile(cfg: &mut Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
1585-
cfg.set_profile(&m.value_of("profile-name").unwrap())?;
1584+
cfg.set_profile(m.value_of("profile-name").unwrap())?;
15861585
Ok(utils::ExitCode(0))
15871586
}
15881587

@@ -1596,7 +1595,7 @@ fn set_auto_self_update(cfg: &mut Cfg, m: &ArgMatches<'_>) -> Result<utils::Exit
15961595
.ok_or(CLIError::NoExeName)?;
15971596
warn!("{} is built with the no-self-update feature: setting auto-self-update will not have any effect.",arg0);
15981597
}
1599-
cfg.set_auto_self_update(&m.value_of("auto-self-update-mode").unwrap())?;
1598+
cfg.set_auto_self_update(m.value_of("auto-self-update-mode").unwrap())?;
16001599
Ok(utils::ExitCode(0))
16011600
}
16021601

src/cli/self_update.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ fn do_pre_install_options_sanity_checks(opts: &InstallOpts<'_>) -> Result<()> {
549549
let toolchain_to_use = match &opts.default_toolchain {
550550
None => "stable",
551551
Some(s) if s == "none" => "stable",
552-
Some(s) => &s,
552+
Some(s) => s,
553553
};
554554
let partial_channel = dist::PartialToolchainDesc::from_str(toolchain_to_use)?;
555555
let resolved = partial_channel.resolve(&host_triple)?.to_string();
@@ -793,7 +793,7 @@ fn maybe_install_rust(
793793
let toolchain_str = toolchain.name().to_owned();
794794
toolchain.cfg().set_default(&toolchain_str)?;
795795
writeln!(process().stdout())?;
796-
common::show_channel_update(&toolchain.cfg(), &toolchain_str, Ok(status))?;
796+
common::show_channel_update(toolchain.cfg(), &toolchain_str, Ok(status))?;
797797
}
798798
Ok(())
799799
}

src/cli/self_update/unix.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub fn do_remove_from_path() -> Result<()> {
5858

5959
// Check more files for cleanup than normally are updated.
6060
for rc in sh.rcfiles().iter().filter(|rc| rc.is_file()) {
61-
let file = utils::read_file("rcfile", &rc)?;
61+
let file = utils::read_file("rcfile", rc)?;
6262
let file_bytes = file.into_bytes();
6363
// FIXME: This is whitespace sensitive where it should not be.
6464
if let Some(idx) = file_bytes
@@ -69,7 +69,7 @@ pub fn do_remove_from_path() -> Result<()> {
6969
let mut new_bytes = file_bytes[..idx].to_vec();
7070
new_bytes.extend(&file_bytes[idx + source_bytes.len()..]);
7171
let new_file = String::from_utf8(new_bytes).unwrap();
72-
utils::write_file("rcfile", &rc, &new_file)?;
72+
utils::write_file("rcfile", rc, &new_file)?;
7373
}
7474
}
7575
}
@@ -91,7 +91,7 @@ pub fn do_add_to_path() -> Result<()> {
9191
_ => &source_cmd,
9292
};
9393

94-
utils::append_file("rcfile", &rc, &cmd_to_write)
94+
utils::append_file("rcfile", &rc, cmd_to_write)
9595
.with_context(|| format!("could not amend shell profile: '{}'", rc.display()))?;
9696
}
9797
}

src/cli/topical_doc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn local_path(root: &Path, topic: &str) -> Result<PathBuf> {
6363
}
6464

6565
let doc = DocData {
66-
topic: &topic,
66+
topic,
6767
subtopic,
6868
root,
6969
};
@@ -135,15 +135,15 @@ pub fn local_path(root: &Path, topic: &str) -> Result<PathBuf> {
135135
Some(f) => f,
136136
None => {
137137
let parent = work_path.parent().unwrap();
138-
search_path(&doc, &parent, &keywords_top)?
138+
search_path(&doc, parent, &keywords_top)?
139139
}
140140
},
141141
_ => match index_html(&doc, &work_path) {
142142
Some(f) => f,
143143
None => {
144144
// len > 2, guaranteed to have a parent, safe to unwrap
145145
let parent = work_path.parent().unwrap();
146-
search_path(&doc, &parent, &keywords_mod)?
146+
search_path(&doc, parent, &keywords_mod)?
147147
}
148148
},
149149
};

src/config.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ impl PgpPublicKey {
173173
pub fn key(&self) -> &SignedPublicKey {
174174
match self {
175175
Self::Builtin => &*BUILTIN_PGP_KEY,
176-
Self::FromEnvironment(_, k) => &k,
177-
Self::FromConfiguration(_, k) => &k,
176+
Self::FromEnvironment(_, k) => k,
177+
Self::FromConfiguration(_, k) => k,
178178
}
179179
}
180180

@@ -678,7 +678,7 @@ impl Cfg {
678678
if !all_toolchains.iter().any(|s| s == toolchain_name) {
679679
// The given name is not resolvable as a toolchain, so
680680
// instead check it's plausible for installation later
681-
dist::validate_channel_name(&toolchain_name)?;
681+
dist::validate_channel_name(toolchain_name)?;
682682
}
683683
}
684684

@@ -992,7 +992,7 @@ impl Cfg {
992992
.with(|s| {
993993
Ok(s.default_host_triple
994994
.as_ref()
995-
.map(|s| dist::TargetTriple::new(&s)))
995+
.map(|s| dist::TargetTriple::new(s)))
996996
})?
997997
.unwrap_or_else(dist::TargetTriple::from_host_or_build))
998998
}

src/diskio/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl Deref for FileBuffer {
108108

109109
fn deref(&self) -> &Self::Target {
110110
match self {
111-
FileBuffer::Immediate(ref vec) => &vec,
111+
FileBuffer::Immediate(ref vec) => vec,
112112
FileBuffer::Threaded(PoolReference::Owned(owned, _)) => owned,
113113
FileBuffer::Threaded(PoolReference::Mut(mutable, _)) => mutable,
114114
}

src/dist/component/transaction.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<'a> Transaction<'a> {
9999
&self.prefix,
100100
component,
101101
relpath,
102-
&self.temp_cfg,
102+
self.temp_cfg,
103103
self.notify_handler(),
104104
)?;
105105
self.change(item);
@@ -114,7 +114,7 @@ impl<'a> Transaction<'a> {
114114
&self.prefix,
115115
component,
116116
relpath,
117-
&self.temp_cfg,
117+
self.temp_cfg,
118118
self.notify_handler(),
119119
)?;
120120
self.change(item);
@@ -142,7 +142,7 @@ impl<'a> Transaction<'a> {
142142
/// This is used for arbitrarily manipulating a file.
143143
pub fn modify_file(&mut self, relpath: PathBuf) -> Result<()> {
144144
assert!(relpath.is_relative());
145-
let item = ChangedItem::modify_file(&self.prefix, relpath, &self.temp_cfg)?;
145+
let item = ChangedItem::modify_file(&self.prefix, relpath, self.temp_cfg)?;
146146
self.change(item);
147147
Ok(())
148148
}
@@ -217,7 +217,7 @@ impl<'a> ChangedItem<'a> {
217217
AddedFile(path) => utils::remove_file("component", &prefix.abs_path(path))?,
218218
AddedDir(path) => utils::remove_dir("component", &prefix.abs_path(path), notify)?,
219219
RemovedFile(path, tmp) | ModifiedFile(path, Some(tmp)) => {
220-
utils::rename_file("component", &tmp, &prefix.abs_path(path), notify)?
220+
utils::rename_file("component", tmp, &prefix.abs_path(path), notify)?
221221
}
222222
RemovedDir(path, tmp) => {
223223
utils::rename_dir("component", &tmp.join("bk"), &prefix.abs_path(path), notify)?

src/dist/dist.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn components_missing_msg(cs: &[Component], manifest: &ManifestV2, toolchain: &s
8787

8888
#[derive(Debug, ThisError)]
8989
enum DistError {
90-
#[error("{}", components_missing_msg(&.0, &.1, &.2))]
90+
#[error("{}", components_missing_msg(.0, .1, .2))]
9191
ToolchainComponentsMissing(Vec<Component>, ManifestV2, String),
9292
#[error("no release found for '{0}'")]
9393
MissingReleaseForToolchain(String),
@@ -491,7 +491,7 @@ impl ToolchainDesc {
491491

492492
// A little convenience for just parsing a channel name or archived channel name
493493
pub fn validate_channel_name(name: &str) -> Result<()> {
494-
let toolchain = PartialToolchainDesc::from_str(&name)?;
494+
let toolchain = PartialToolchainDesc::from_str(name)?;
495495
if toolchain.has_triple() {
496496
Err(anyhow!(format!("target triple in channel name '{}'", name)))
497497
} else {
@@ -949,9 +949,9 @@ fn try_update_from_dist_<'a>(
949949
let result = manifestation.update_v1(
950950
&manifest,
951951
update_hash,
952-
&download.temp_cfg,
952+
download.temp_cfg,
953953
&download.notify_handler,
954-
&download.pgp_keys,
954+
download.pgp_keys,
955955
);
956956
// inspect, determine what context to add, then process afterwards.
957957
let mut download_not_exists = false;

src/dist/download.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<'a> DownloadCfg<'a> {
4343
pub fn download(&self, url: &Url, hash: &str) -> Result<File> {
4444
utils::ensure_dir_exists(
4545
"Download Directory",
46-
&self.download_dir,
46+
self.download_dir,
4747
&self.notify_handler,
4848
)?;
4949
let target_file = self.download_dir.join(Path::new(hash));
@@ -74,7 +74,7 @@ impl<'a> DownloadCfg<'a> {
7474
let mut hasher = Sha256::new();
7575

7676
if let Err(e) = utils::download_file_with_resume(
77-
&url,
77+
url,
7878
&partial_file_path,
7979
Some(&mut hasher),
8080
true,
@@ -158,14 +158,14 @@ impl<'a> DownloadCfg<'a> {
158158
.download_signature(url)
159159
.with_context(|| format!("failed to download signature file {}", url))?;
160160

161-
let file_path: &Path = &file;
161+
let file_path: &Path = file;
162162
let content = std::fs::File::open(file_path).with_context(|| RustupError::ReadingFile {
163163
name: "channel data",
164164
path: PathBuf::from(file_path),
165165
})?;
166166

167167
let sig_result =
168-
crate::dist::signatures::verify_signature(content, &signature, &self.pgp_keys)?;
168+
crate::dist::signatures::verify_signature(content, &signature, self.pgp_keys)?;
169169
if let Some(keyidx) = sig_result {
170170
let key = &self.pgp_keys[keyidx];
171171
Ok(key)
@@ -229,7 +229,7 @@ impl<'a> DownloadCfg<'a> {
229229

230230
// No signatures for tarballs for now.
231231
if !url_str.ends_with(".tar.gz") && !url_str.ends_with(".tar.xz") {
232-
match self.check_signature(&url_str, &file) {
232+
match self.check_signature(url_str, &file) {
233233
Ok(key) => (self.notify_handler)(Notification::SignatureValid(url_str, key)),
234234
Err(_) => (self.notify_handler)(Notification::SignatureInvalid(url_str)),
235235
}
@@ -244,7 +244,7 @@ fn file_hash(path: &Path, notify_handler: &dyn Fn(Notification<'_>)) -> Result<S
244244
let notification_converter = |notification: crate::utils::Notification<'_>| {
245245
notify_handler(notification.into());
246246
};
247-
let mut downloaded = utils::FileReaderWithProgress::new_file(&path, &notification_converter)?;
247+
let mut downloaded = utils::FileReaderWithProgress::new_file(path, &notification_converter)?;
248248
use std::io::Read;
249249
let mut buf = vec![0; 32768];
250250
while let Ok(n) = downloaded.read(&mut buf) {

src/dist/manifest.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl Manifest {
166166

167167
for (k, v) in pkg_table {
168168
if let toml::Value::Table(t) = v {
169-
result.insert(k, Package::from_toml(t, &path)?);
169+
result.insert(k, Package::from_toml(t, path)?);
170170
}
171171
}
172172

@@ -372,13 +372,13 @@ impl Package {
372372

373373
if let Some(toml::Value::Table(t)) = target_table.remove("*") {
374374
Ok(PackageTargets::Wildcard(TargetedPackage::from_toml(
375-
t, &path,
375+
t, path,
376376
)?))
377377
} else {
378378
let mut result = HashMap::new();
379379
for (k, v) in target_table {
380380
if let toml::Value::Table(t) = v {
381-
result.insert(TargetTriple::new(&k), TargetedPackage::from_toml(t, &path)?);
381+
result.insert(TargetTriple::new(&k), TargetedPackage::from_toml(t, path)?);
382382
}
383383
}
384384
Ok(PackageTargets::Targeted(result))

0 commit comments

Comments
 (0)