Skip to content

Commit bc91f96

Browse files
committed
chore: use match ergonomics in favor of explicit refs
1 parent 97d7c50 commit bc91f96

File tree

10 files changed

+40
-41
lines changed

10 files changed

+40
-41
lines changed

src/cli/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ where
368368

369369
before_restart()?;
370370

371-
if let Some(ref setup_path) = setup_path {
371+
if let Some(setup_path) = &setup_path {
372372
return self_update::run_update(setup_path);
373373
} else {
374374
// Try again in case we emitted "tool `{}` is already installed" last time.

src/cli/self_update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ async fn maybe_install_rust(
905905

906906
let (components, targets) = (opts.components, opts.targets);
907907
let toolchain = opts.install(&mut cfg)?;
908-
if let Some(ref desc) = toolchain {
908+
if let Some(desc) = &toolchain {
909909
let status = if Toolchain::exists(&cfg, &desc.into())? {
910910
warn!("Updating existing toolchain, profile choice will be ignored");
911911
// If we have a partial install we might not be able to read content here. We could:

src/config.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl OverrideCfg {
190190
match self {
191191
Self::PathBased(path_based_name) => path_based_name.into(),
192192
Self::Custom(custom_name) => custom_name.into(),
193-
Self::Official { ref toolchain, .. } => toolchain.into(),
193+
Self::Official { toolchain, .. } => (&toolchain).into(),
194194
}
195195
}
196196
}
@@ -558,12 +558,12 @@ impl<'a> Cfg<'a> {
558558
fn find_override_config(&self) -> Result<Option<(OverrideCfg, ActiveReason)>> {
559559
let override_config: Option<(OverrideCfg, ActiveReason)> =
560560
// First check +toolchain override from the command line
561-
if let Some(ref name) = self.toolchain_override {
561+
if let Some(name) = &self.toolchain_override {
562562
let override_config = name.resolve(&self.get_default_host_triple()?)?.into();
563563
Some((override_config, ActiveReason::CommandLine))
564564
}
565565
// Then check the RUSTUP_TOOLCHAIN environment variable
566-
else if let Some(ref name) = self.env_override {
566+
else if let Some(name) = &self.env_override {
567567
// Because path based toolchain files exist, this has to support
568568
// custom, distributable, and absolute path toolchains otherwise
569569
// rustup's export of a RUSTUP_TOOLCHAIN when running a process will
@@ -659,7 +659,7 @@ impl<'a> Cfg<'a> {
659659
let default_host_triple = get_default_host_triple(settings, self.process);
660660
// Do not permit architecture/os selection in channels as
661661
// these are host specific and toolchain files are portable.
662-
if let ResolvableToolchainName::Official(ref name) = toolchain_name
662+
if let ResolvableToolchainName::Official(name) = &toolchain_name
663663
&& name.has_triple()
664664
{
665665
// Permit fully qualified names IFF the toolchain is installed. TODO(robertc): consider
@@ -958,7 +958,7 @@ impl<'a> Cfg<'a> {
958958
let st = distributable
959959
.update_extra(&[], &[], profile, force_update, false)
960960
.await;
961-
if let Err(ref e) = st {
961+
if let Err(e) = &st {
962962
(self.notify_handler)(Notification::NonFatalError(e));
963963
}
964964
(desc, st)

src/diskio/immediate.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl ImmediateUnpacker {
3838
fn deque(&self) -> Box<dyn Iterator<Item = CompletedIo>> {
3939
let mut guard = self.incremental_state.lock().unwrap();
4040
// incremental file in progress
41-
if let Some(ref mut state) = *guard {
41+
if let Some(state) = &mut *guard {
4242
// Case 1: pending errors
4343
if state.finished {
4444
let mut item = state.item.take().unwrap();
@@ -81,7 +81,7 @@ impl Executor for ImmediateUnpacker {
8181
// If there is a pending error, return it, otherwise stash the
8282
// Item for eventual return when the file is finished.
8383
let mut guard = self.incremental_state.lock().unwrap();
84-
let Some(ref mut state) = *guard else {
84+
let Some(state) = &mut *guard else {
8585
unreachable!()
8686
};
8787
if state.err.is_some() {
@@ -187,7 +187,7 @@ impl IncrementalFileWriter {
187187
Ok(v) => v,
188188
Err(e) => {
189189
let mut state = self.state.lock().unwrap();
190-
if let Some(ref mut state) = *state {
190+
if let Some(state) = &mut *state {
191191
state.err.replace(Err(e));
192192
state.finished = true;
193193
false
@@ -200,10 +200,10 @@ impl IncrementalFileWriter {
200200

201201
fn write(&mut self, chunk: Vec<u8>) -> std::result::Result<bool, io::Error> {
202202
let mut state = self.state.lock().unwrap();
203-
let Some(ref mut state) = *state else {
203+
let Some(state) = &mut *state else {
204204
unreachable!()
205205
};
206-
let Some(ref mut file) = self.file.as_mut() else {
206+
let Some(file) = &mut self.file else {
207207
return Ok(false);
208208
};
209209
// Length 0 vector is used for clean EOF signalling.

src/diskio/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,14 @@ impl IncrementalFileState {
270270
mode: u32,
271271
) -> Result<(Box<dyn FnMut(FileBuffer) -> bool>, IncrementalFile)> {
272272
use std::sync::mpsc::channel;
273-
match *self {
273+
match self {
274274
IncrementalFileState::Threaded => {
275275
let (tx, rx) = channel::<FileBuffer>();
276276
let content_callback = IncrementalFile::ThreadedReceiver(rx);
277277
let chunk_submit = move |chunk: FileBuffer| tx.send(chunk).is_ok();
278278
Ok((Box::new(chunk_submit), content_callback))
279279
}
280-
IncrementalFileState::Immediate(ref state) => {
280+
IncrementalFileState::Immediate(state) => {
281281
let content_callback = IncrementalFile::ImmediateReceiver;
282282
let mut writer = immediate::IncrementalFileWriter::new(path, mode, state.clone())?;
283283
let chunk_submit = move |chunk: FileBuffer| writer.chunk_submit(chunk);

src/dist/manifest.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,11 @@ impl Manifest {
357357
fn validate(&self) -> Result<()> {
358358
// Every component mentioned must have an actual package to download
359359
for pkg in self.packages.values() {
360-
match pkg.targets {
361-
PackageTargets::Wildcard(ref tpkg) => {
360+
match &pkg.targets {
361+
PackageTargets::Wildcard(tpkg) => {
362362
self.validate_targeted_package(tpkg)?;
363363
}
364-
PackageTargets::Targeted(ref tpkgs) => {
364+
PackageTargets::Targeted(tpkgs) => {
365365
for tpkg in tpkgs.values() {
366366
self.validate_targeted_package(tpkg)?;
367367
}
@@ -447,9 +447,9 @@ impl Manifest {
447447

448448
impl Package {
449449
pub fn get_target(&self, target: Option<&TargetTriple>) -> Result<&TargetedPackage> {
450-
match self.targets {
451-
PackageTargets::Wildcard(ref tpkg) => Ok(tpkg),
452-
PackageTargets::Targeted(ref tpkgs) => {
450+
match &self.targets {
451+
PackageTargets::Wildcard(tpkg) => Ok(tpkg),
452+
PackageTargets::Targeted(tpkgs) => {
453453
if let Some(t) = target {
454454
tpkgs
455455
.get(t)
@@ -523,7 +523,7 @@ impl Component {
523523

524524
pub(crate) fn name(&self, manifest: &Manifest) -> String {
525525
let pkg = self.short_name(manifest);
526-
if let Some(ref t) = self.target {
526+
if let Some(t) = &self.target {
527527
format!("{pkg}-{t}")
528528
} else {
529529
pkg
@@ -538,7 +538,7 @@ impl Component {
538538
}
539539
pub(crate) fn description(&self, manifest: &Manifest) -> String {
540540
let pkg = self.short_name(manifest);
541-
if let Some(ref t) = self.target {
541+
if let Some(t) = &self.target {
542542
format!("'{pkg}' for target '{t}'")
543543
} else {
544544
format!("'{pkg}'")
@@ -549,7 +549,7 @@ impl Component {
549549
}
550550
pub(crate) fn name_in_manifest(&self) -> String {
551551
let pkg = self.short_name_in_manifest();
552-
if let Some(ref t) = self.target {
552+
if let Some(t) = &self.target {
553553
format!("{pkg}-{t}")
554554
} else {
555555
pkg.to_string()

src/dist/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -694,16 +694,16 @@ impl ToolchainDesc {
694694
}
695695
/// Either "$channel" or "channel-$date"
696696
pub fn manifest_name(&self) -> String {
697-
match self.date {
697+
match &self.date {
698698
None => self.channel.to_string(),
699-
Some(ref date) => format!("{}-{}", self.channel, date),
699+
Some(date) => format!("{}-{}", self.channel, date),
700700
}
701701
}
702702

703703
pub(crate) fn package_dir(&self, dist_root: &str) -> String {
704-
match self.date {
704+
match &self.date {
705705
None => dist_root.to_string(),
706-
Some(ref date) => format!("{dist_root}/{date}"),
706+
Some(date) => format!("{dist_root}/{date}"),
707707
}
708708
}
709709

@@ -843,16 +843,16 @@ impl fmt::Display for PartialToolchainDesc {
843843
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
844844
write!(f, "{}", &self.channel)?;
845845

846-
if let Some(ref date) = self.date {
846+
if let Some(date) = &self.date {
847847
write!(f, "-{date}")?;
848848
}
849-
if let Some(ref arch) = self.target.arch {
849+
if let Some(arch) = &self.target.arch {
850850
write!(f, "-{arch}")?;
851851
}
852-
if let Some(ref os) = self.target.os {
852+
if let Some(os) = &self.target.os {
853853
write!(f, "-{os}")?;
854854
}
855-
if let Some(ref env) = self.target.env {
855+
if let Some(env) = &self.target.env {
856856
write!(f, "-{env}")?;
857857
}
858858

@@ -864,7 +864,7 @@ impl fmt::Display for ToolchainDesc {
864864
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
865865
write!(f, "{}", &self.channel)?;
866866

867-
if let Some(ref date) = self.date {
867+
if let Some(date) = &self.date {
868868
write!(f, "-{date}")?;
869869
}
870870
write!(f, "-{}", self.target)?;

src/test/clitools.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl Config {
229229
// Ensure PATH is prefixed with the rustup-exe directory
230230
let prev_path = env::var_os("PATH");
231231
let mut new_path = self.exedir.clone().into_os_string();
232-
if let Some(ref p) = prev_path {
232+
if let Some(p) = &prev_path {
233233
new_path.push(if cfg!(windows) { ";" } else { ":" });
234234
new_path.push(p);
235235
}
@@ -697,16 +697,15 @@ impl ConstState {
697697
{
698698
// fast path: the dist already exists
699699
let lock = self.scenarios[s].read().unwrap();
700-
if let Some(ref path) = *lock {
700+
if let Some(path) = &*lock {
701701
return Ok(path.clone());
702702
}
703703
}
704704
{
705705
let mut lock = self.scenarios[s].write().unwrap();
706706
// another writer may have initialized it
707-
match *lock {
708-
Some(ref path) => Ok(path.clone()),
709-
707+
match &*lock {
708+
Some(path) => Ok(path.clone()),
710709
None => {
711710
let dist_path = self.const_dist_dir.path().join(format!("{s:?}"));
712711
s.write_to(&dist_path);

src/test/dist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ impl MockDistServer {
637637
);
638638
let tarballs = TARBALLS.lock().unwrap();
639639
let hash = if tarballs.contains_key(&key) {
640-
let (ref contents, ref hash) = tarballs[&key];
640+
let (contents, hash) = &tarballs[&key];
641641
File::create(&installer_tarball)
642642
.unwrap()
643643
.write_all(contents)

src/test/mock.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,14 @@ impl MockFile {
238238

239239
pub fn build(&self, path: &Path) {
240240
let path = path.join(&self.path);
241-
match self.contents {
242-
Contents::Dir(ref files) => {
241+
match &self.contents {
242+
Contents::Dir(files) => {
243243
for (name, contents) in files {
244244
let fname = path.join(name);
245245
contents.build(&fname);
246246
}
247247
}
248-
Contents::File(ref contents) => contents.build(&path),
248+
Contents::File(contents) => contents.build(&path),
249249
}
250250
}
251251
}

0 commit comments

Comments
 (0)